lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 9 March 2015 at 15:23, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
>> In lvm.c if the target of OP_CALL is a Lua function then it is handled
>> by the same invocation of luaV_execute(). When I compile a Lua
>> function I cannot do this so I need to recursively invoke
>> luaV_execute() on the called function. I was wondering if I should
>> directly call luaV_execute() or call luaD_call() - what would be the
>> correct approach?
>
> Probably luaD_call, but depends on your code. luaD_call handles C
> functions, controls the stack depth, and controls yields. Probably
> you want all of them.
>

Looking deeper into this I see that there is an extra step being
performed in the OP_CALL that may not be done by luaD_call():

        if (luaD_precall(L, ra, nresults)) {  /* C function? */
          if (nresults >= 0) L->top = ci->top;  /* adjust results */

If I understand correctly - this is because following a call to C
function L->top is set to the first result from the C function, but
here L->top must be reset to the top of the stack for current
function. Am I correct in my understanding?

Thanks and Regards

Dibyendu