anyone with experience with the lua c api: how does the garbage collection of strings passed from lua to c work? how do you ensure the lua gc does not free the string while c is using it?
@nasser afaik lua_pushstring makes a copy of the string and never keeps any C pointers
@nasser oh sorry you said from Lua to C. I think the pointer you get from luaL_checkstring is valid only while that stack index is unmodified
@nasser basically if you want to access that string anywhere outside of the C function being called by Lua, make a copy of it.
@nasser lua_tolstring returns a pointer to the data inside the value sitting on the Lua stack. You need to make a copy of it then, as it can be garbage collected as soon as the value is removed from the stack for whatever reason.
@moralrecordings makes sense -- the interop stack is basically a gc root