|
|
||
|
Shea Martin wrote:
void DefinePlayerEvent( lua_State* vm ){ lua_newtable( vm );lua_pushstring( vm, "log" ); lua_pushcclosure( vm, l_event_log, 0 ); lua_settable( vm, -3 ); lua_pushvalue( vm, -2 ); //get Event from global space lua_setfield( vm, -2, "__index" ); // mt.__index = Event lua_setmetatable( vm, -2 ); //attach metatable //lua_setglobal( vm, "Event" ); }
Ok, after reading chapter 28, I changed my DefinePlayerEvent() to this:
void DefinePlayerEvent( lua_State* vm )
{
luaL_newmetatable( vm, "Event.mt" );
lua_pushstring( vm, "log" );
lua_pushcclosure( vm, l_event_log, 0 );
lua_settable( vm, -3 );
lua_pushstring( vm, "__index" );
lua_pushvalue( vm, -2 );
lua_pushvalue( vm, -2 );
lua_settable( vm, -3 );
}
and it works! Thanks, I'll keep reading.
~S