Skip to content

Instantly share code, notes, and snippets.

@ThePhD
Created December 9, 2013 16:04
Show Gist options
  • Save ThePhD/7874559 to your computer and use it in GitHub Desktop.
Save ThePhD/7874559 to your computer and use it in GitHub Desktop.
I hate lua
// GC table
void** freshuserdata = static_cast<void**>( lua_newuserdata( state( ), sizeof( userdata ) ) );
*freshuserdata = userdata;
lua_newtable( state( ) ); /* create metatable. */
stack::push( state( ), "__gc" ); /* push key '__gc' */
stack::push( state( ), destroyfunc, 0 ); /* push gc method. */
lua_rawset( state( ), -3 ); /* metatable['__gc'] = userdata_gc_method */
lua_setmetatable( state( ), -2 ); /* set the userdata's metatable. */
// Actual function call we want
luaL_setfuncs(state(), funcreg, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment