Use lua_getfield instead of helper getField
parent
9401a4389e
commit
6953eb7aa2
|
@ -338,24 +338,6 @@ void CelxLua::initMaps()
|
|||
}
|
||||
|
||||
|
||||
static void getField(lua_State* l, int index, const char* key)
|
||||
{
|
||||
// When we move to Lua 5.1, this will be replaced by:
|
||||
// lua_getfield(l, index, key);
|
||||
lua_pushstring(l, key);
|
||||
#ifdef LUA_GLOBALSINDEX
|
||||
if (index == LUA_GLOBALSINDEX) {
|
||||
lua_gettable(l, index);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (index != LUA_REGISTRYINDEX)
|
||||
lua_gettable(l, index - 1);
|
||||
else
|
||||
lua_gettable(l, index);
|
||||
}
|
||||
|
||||
|
||||
// Push a class name onto the Lua stack
|
||||
void PushClass(lua_State* l, int id)
|
||||
{
|
||||
|
@ -730,7 +712,7 @@ bool LuaState::handleKeyEvent(const char* key)
|
|||
return false;
|
||||
|
||||
// get the registered event table
|
||||
getField(costate, LUA_REGISTRYINDEX, EventHandlers);
|
||||
lua_getfield(costate, LUA_REGISTRYINDEX, EventHandlers);
|
||||
if (!lua_istable(costate, -1))
|
||||
{
|
||||
cerr << "Missing event handler table";
|
||||
|
@ -739,7 +721,7 @@ bool LuaState::handleKeyEvent(const char* key)
|
|||
}
|
||||
|
||||
bool handled = false;
|
||||
getField(costate, -1, KeyHandler);
|
||||
lua_getfield(costate, -1, KeyHandler);
|
||||
if (lua_isfunction(costate, -1))
|
||||
{
|
||||
lua_remove(costate, -2); // remove the key event table from the stack
|
||||
|
@ -777,7 +759,7 @@ bool LuaState::handleMouseButtonEvent(float x, float y, int button, bool down)
|
|||
return false;
|
||||
|
||||
// get the registered event table
|
||||
getField(costate, LUA_REGISTRYINDEX, EventHandlers);
|
||||
lua_getfield(costate, LUA_REGISTRYINDEX, EventHandlers);
|
||||
if (!lua_istable(costate, -1))
|
||||
{
|
||||
cerr << "Missing event handler table";
|
||||
|
@ -786,7 +768,7 @@ bool LuaState::handleMouseButtonEvent(float x, float y, int button, bool down)
|
|||
}
|
||||
|
||||
bool handled = false;
|
||||
getField(costate, -1, down ? MouseDownHandler : MouseUpHandler);
|
||||
lua_getfield(costate, -1, down ? MouseDownHandler : MouseUpHandler);
|
||||
if (lua_isfunction(costate, -1))
|
||||
{
|
||||
lua_remove(costate, -2); // remove the key event table from the stack
|
||||
|
@ -833,7 +815,7 @@ bool LuaState::handleTickEvent(double dt)
|
|||
return false;
|
||||
|
||||
// get the registered event table
|
||||
getField(costate, LUA_REGISTRYINDEX, EventHandlers);
|
||||
lua_getfield(costate, LUA_REGISTRYINDEX, EventHandlers);
|
||||
if (!lua_istable(costate, -1))
|
||||
{
|
||||
cerr << "Missing event handler table";
|
||||
|
@ -842,7 +824,7 @@ bool LuaState::handleTickEvent(double dt)
|
|||
}
|
||||
|
||||
bool handled = false;
|
||||
getField(costate, -1, TickHandler);
|
||||
lua_getfield(costate, -1, TickHandler);
|
||||
if (lua_isfunction(costate, -1))
|
||||
{
|
||||
lua_remove(costate, -2); // remove the key event table from the stack
|
||||
|
|
Loading…
Reference in New Issue