lua-users home
lua-l archive

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


Reuben Thomas wrote:
> http://luaforge.net/projects/clue/

Those would need to be protected by a lua_pcall if any call does a lua_error.

> /* Export a Lua variable `lvar' of Lua type `lty' to a C variable
>    `cvar'. */
> #define CLUE_EXPORT(L, cvar, lvar, lty)         \
>   do {                                          \
>     lua_getglobal(L, #lvar);                    \
>     cvar = lua_to ## lty(L, -1);                \
>     lua_pop(L, 1);                              \
>   } while (0)

If lty is string and cvar is a const char *, then after the lua_pop, whether cvar remains valid is undefined. Concerning lua_tostring/lua_tolstring, the reference manual says "Because Lua has garbage collection, there is no guarantee that the pointer returned by lua_tolstring will be valid after the corresponding value is removed from the stack." (though on looking at the 5.1.2 code, it looks ok).