lua-users home
lua-l archive

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


>>>>> "Dirk" == Dirk Laurie <dirk.laurie@gmail.com> writes:

 Dirk> I have added an essay on protected calls to my collection of Lua Notes.
 Dirk> https://github.com/dlaurie/lua-notes

Your description of the LUA_MULTRET case isn't clear about the fact that
after the call, lua_gettop reflects not just the number of return values
from the call but also whatever you previously had on the current stack
below the function value.

i.e. you typically have to do things like

    nstack = lua_gettop(L);
    lua_pushcfunction(L, myfunc);
    if (lua_pcall(L, 0, LUA_MULTRET, 0) != LUA_OK) { /* deal with error */ }
    nret = lua_gettop(L) - nstack;
    
Another issue that may be worth mentioning is the idiom of using
lua_settop at the start of a function to adjust the stack (discarding
excess parameters and supplying missing ones).

-- 
Andrew.