lua-users home
lua-l archive

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

On Mar 16, 2014, at 2:39 AM, Rena <> wrote:

To me, C/C++ are tools for making libraries to allow Lua to do what I want. ;-) When I use them, usually I don't use any C++ features beyond templates and classes.

I agree that working with the Lua stack can be a headache at times. It helps a lot to annotate each stack operation with a comment listing the stack contents, like:

lua_getmetatable(Lua, 1); //-1: meta
lua_getfield (Lua, -1, "method"); //-1: method, -2: meta
lua_pushvalue(Lua,  2); //-1: key, -2: method, -3: meta
lua_gettable (Lua, -2); //-1: value, -2: method, -3: meta

Yes that’s what we do .. we adopted the notation used in the Lua reference:

lua_pushnil(L); // [-0,+1]=1 Push nil
lua_pushstring(L, “xxx”); // [-0,+1]=2 Push string
… etc

It’s a bit of a pain to comment but does help keep track of stuff.