lua-users home
lua-l archive

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


Though note that depending on how you do lifetime management, you may actually want to use a weak table mapping light userdata pointers to full userdata proxies.


You could even use a metatable on this mapping table to do the proxy construction thereby allowing one to write:

	pushMappingTable( L );	/* e.g., fetch it from the registry */
	lua_pushlightuserdata( L, p );
	lua_gettable( L, -2 );	/* Fetch or construct the proxy. */
	lua_remove( L, -2 );	/* Remove the proxy table. */

If you can store the proxy table as the environment to your C code or as an upvalue, then it becomes even simpler. For example:

	lua_pushlightuserdata( L, p );
	lua_gettable( L, LUA_ENVIRONINDEX );

Mark