Re: partially define a table in C++, and partially in script
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: partially define a table in C++, and partially in script
- From: Shea Martin <shea08@...>
- Date: 2007年2月06日 16:02:26 -0400
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
- References:
- partially define a table in C++, and partially in script, Shea Martin
- Re: partially define a table in C++, and partially in script, Rici Lake
- Re: partially define a table in C++, and partially in script, Shea Martin
- Re: partially define a table in C++, and partially in script, Doug Rogers
- Re: partially define a table in C++, and partially in script, Shea Martin