lua-users home
lua-l archive

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


> Does that mean I should call lua_newthread through lua_pcall if I am to
> prevent my application from exiting on an error? If so, what other Lua
> API functions should be treated with similar caution?

If you are worried about memory-allocation failures, then most
API functions need that caution. Most functions in Lua may need to
allocate memory, and if this fails Lua throws an error. So, yes, to
prevent your application to exit you should call them in protected mode.
You can do this with lua_pcall, or with the new (not in the manual, yet)
lua_cpcall:

LUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud);

You pass the function to be called in protected mode and a generic
userdata for it (it will be available as a userdata argument to the
function). See an example of use in lua.c.

-- Roberto