A lesson on structs, recursion, stack size and pointers.

Jarrett Billingsley kb3ctd2 at yahoo.com
Sun Jan 20 23:19:30 PST 2008


"Dan" <murpsoft at hotmail.com> wrote in message 
news:fn0pfk$kup$1 at digitalmars.com...


>
> static Value* myFunc(ref Value self, ref Value cc, arguments[] ...){}
>

Your other issues aside, have you considered using/passing some kind of 
context which would hold all these values instead?  In MiniD (which uses an 
API heavily inspired by Lua), native functions take two params -- a class 
reference to the current "thread", and a number representing the number of 
params passed to this function.  The function then asks the thread object 
for any params it needs, since they're all on the thread's stack anyway.  To 
return values, the native function pushes all the values it wants to return 
on the thread's stack and returns a number indicating how many values to 
return (functions can return any number of values).

I don't know anything about the internals of Walnut, and therefore if this 
scheme would be possible for you, but it sure is faster to pass a pointer 
and an int.  It also solves the return value allocation issue. 




More information about the Digitalmars-d-learn mailing list