lua-users home
lua-l archive

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




2009/10/30 Kenk <kenk@heroesent.com>
Hi there,

  I'm just looking for a 'best-practice' scenario here... Say I've got user data all setup and Lua's happily using it. If for whatever reason that user data becomes deleted in C code (for example, a window closing, or a routine called that deletes an element in the collection that Lua happens to have a reference to somewhere else in script).... What's the best way of setting this userdata to nil in C and then telling Lua it's no longer around? In script I'd set the variable to nil... Not sure how I'd go about that from C.

Thanks!

 
It is the same principle. Say for example you have a full userdata stored as a global in Lua then:
lua_pushstrings, ud_name);
lua_pushnil(s);
lua_settable(s, LUA_GLOBALSINDEX);