[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: lua_newthread etc.
- From: Roberto Ierusalimschy <roberto@...>
- Date: Thu, 23 Jan 2003 11:00:20 +0000
> 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_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.