lua-users home
lua-l archive

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


On Mon, Jul 25, 2016 at 5:04 PM, Marc Balmer <marc@msys.ch> wrote:
 
p = lua_newuserdate(L, sizeof int)
*p = 42

/* Do a Lua API call that might error (longjmp) out */

As long as the allocated user datum stays on Lua's stack, it won't be collected. So the use of p immediately after the first line in the snippet above is safe.

If what you do later pops the datum without storing it somewhere else, then, yes, it can be collected and you could end up with a dangling pointer.

Cheers,
V.