Re: Best way to have table-like fields on userdata
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Best way to have table-like fields on userdata
- From: dcharno <dcharno@...>
- Date: 2006年11月28日 16:35:44 -0500
I create a table and set it as the userdata's environment for storing
fields. In the index and newindex metamethods, retrieve the field from
the environment:
Forgot the rollover for the metatable.
int myindex( lua_State *L )
{
lua_getfenv( L, 1 );
lua_pushvalue( L, 2 );
lua_rawget( L, -2 );
if (lua_isnil( L, -1 ))
{
lua_pop( L, 2 );
lua_getmetatable( L, 1 );
lua_pushvalue( L, 2 );
lua_rawget( L, -2 );
}
return 1;
}