lua-users home
lua-l archive

Re: Best way to have table-like fields on userdata

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


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;
 }

AltStyle によって変換されたページ (->オリジナル) /