1
0

Got rid of "self" in plugins, which is deprecated anyway

Fixed bug in many On* hooks that did not pop the return values from the stack
Fixed Plugin:Call() that removed one too many items from the stack

git-svn-id: http://mc-server.googlecode.com/svn/trunk@950 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
faketruth 2012-10-11 20:49:18 +00:00
parent 3b125d47d1
commit 4eaafbd70f
3 changed files with 29 additions and 12 deletions

View File

@ -81,12 +81,6 @@ bool cLuaCommandBinder::HandleCommand( const std::string & a_Command, cPlayer* a
}
}
// For enabling 'self' in the function, it's kind of a hack I'm not sure this is the way to go
lua_pushvalue(func.LuaState, LUA_GLOBALSINDEX);
lua_pushstring(func.LuaState, "self");
tolua_pushusertype( func.LuaState, func.Plugin, "cPlugin" );
lua_rawset(func.LuaState, -3);
lua_pop(func.LuaState, 1);
LOGD("1. Stack size: %i", lua_gettop(func.LuaState) );
lua_rawgeti( func.LuaState, LUA_REGISTRYINDEX, func.Reference); // same as lua_getref()

View File

@ -808,7 +808,7 @@ static int tolua_cPlugin_Call(lua_State* tolua_S)
return 0;
}
lua_pop(targetState, nresults+1); // I have no idea what I'm doing, but it works
lua_pop(targetState, nresults); // I have no idea what I'm doing, but it works
return nresults;
}

View File

@ -184,7 +184,9 @@ bool cPlugin_NewLua::OnCollectPickup(cPlayer * a_Player, cPickup * a_Pickup)
return false;
}
return (tolua_toboolean(m_LuaState, -1, 0) > 0);
bool bRetVal = (tolua_toboolean( m_LuaState, -1, 0) > 0);
lua_pop(m_LuaState, 1);
return bRetVal;
}
@ -207,7 +209,9 @@ bool cPlugin_NewLua::OnDisconnect(cPlayer * a_Player, const AString & a_Reason)
return false;
}
return (tolua_toboolean( m_LuaState, -1, 0) > 0);
bool bRetVal = (tolua_toboolean( m_LuaState, -1, 0) > 0);
lua_pop(m_LuaState, 1);
return bRetVal;
}
@ -234,7 +238,9 @@ bool cPlugin_NewLua::OnBlockPlace(cPlayer * a_Player, int a_BlockX, int a_BlockY
return false;
}
return (tolua_toboolean( m_LuaState, -1, 0) > 0);
bool bRetVal = (tolua_toboolean( m_LuaState, -1, 0) > 0);
lua_pop(m_LuaState, 1);
return bRetVal;
}
@ -263,7 +269,9 @@ bool cPlugin_NewLua::OnBlockDig(cPlayer * a_Player, int a_BlockX, int a_BlockY,
return false;
}
return (tolua_toboolean( m_LuaState, -1, 0) > 0);
bool bRetVal = (tolua_toboolean( m_LuaState, -1, 0) > 0);
lua_pop(m_LuaState, 1);
return bRetVal;
}
@ -286,7 +294,9 @@ bool cPlugin_NewLua::OnChat(cPlayer * a_Player, const AString & a_Message)
return false;
}
return (tolua_toboolean( m_LuaState, -1, 0) > 0);
bool bRetVal = (tolua_toboolean( m_LuaState, -1, 0) > 0);
lua_pop(m_LuaState, 1);
return bRetVal;
}
@ -307,6 +317,7 @@ bool cPlugin_NewLua::OnLogin(cClientHandle * a_Client, int a_ProtocolVersion, co
return false;
bool bRetVal = (tolua_toboolean( m_LuaState, -1, 0) > 0);
lua_pop(m_LuaState, 1);
return bRetVal;
}
@ -341,6 +352,7 @@ bool cPlugin_NewLua::OnPlayerJoin( cPlayer* a_Player )
return false;
bool bRetVal = (tolua_toboolean( m_LuaState, -1, 0) > 0);
lua_pop(m_LuaState, 1);
return bRetVal;
}
@ -392,6 +404,7 @@ bool cPlugin_NewLua::OnKilled( cPawn* a_Killed, cEntity* a_Killer )
return false;
bool bRetVal = (tolua_toboolean( m_LuaState, -1, 0) > 0);
lua_pop(m_LuaState, 1);
return bRetVal;
}
@ -433,6 +446,7 @@ bool cPlugin_NewLua::OnChunkGenerating(cWorld * a_World, int a_ChunkX, int a_Chu
return false;
bool bRetVal = (tolua_toboolean( m_LuaState, -1, 0) > 0);
lua_pop(m_LuaState, 1);
return bRetVal;
}
@ -456,6 +470,7 @@ bool cPlugin_NewLua::OnPreCrafting(const cPlayer * a_Player, const cCraftingGrid
}
bool bRetVal = (tolua_toboolean( m_LuaState, -1, 0) > 0);
lua_pop(m_LuaState, 1);
return bRetVal;
}
@ -479,6 +494,7 @@ bool cPlugin_NewLua::OnCraftingNoRecipe(const cPlayer * a_Player, const cCraftin
}
bool bRetVal = (tolua_toboolean( m_LuaState, -1, 0) > 0);
lua_pop(m_LuaState, 1);
return bRetVal;
}
@ -502,6 +518,7 @@ bool cPlugin_NewLua::OnPostCrafting(const cPlayer * a_Player, const cCraftingGri
}
bool bRetVal = (tolua_toboolean( m_LuaState, -1, 0) > 0);
lua_pop(m_LuaState, 1);
return bRetVal;
}
@ -531,6 +548,7 @@ bool cPlugin_NewLua::OnBlockToPickup(
}
bool bRetVal = (tolua_toboolean( m_LuaState, -1, 0) > 0);
lua_pop(m_LuaState, 1);
return bRetVal;
}
@ -554,6 +572,7 @@ bool cPlugin_NewLua::OnWeatherChanged(cWorld * a_World)
}
bool bRetVal = (tolua_toboolean( m_LuaState, -1, 0) > 0);
lua_pop(m_LuaState, 1);
return bRetVal;
}
@ -589,6 +608,7 @@ bool cPlugin_NewLua::OnUpdatingSign(
return false;
}
bool bRetVal = (tolua_toboolean( m_LuaState, -5, 0) > 0);
if (lua_isstring(m_LuaState, -4))
{
@ -606,6 +626,7 @@ bool cPlugin_NewLua::OnUpdatingSign(
{
a_Line4 = tolua_tostring(m_LuaState, -1, "");
}
// TODO - FIXME: This probably needs to pop 5 things from the stack before returning
return bRetVal;
}
@ -642,6 +663,7 @@ bool cPlugin_NewLua::OnUpdatedSign(
}
bool bRetVal = (tolua_toboolean( m_LuaState, -1, 0) > 0);
lua_pop(m_LuaState, 1);
return bRetVal;
}
@ -666,6 +688,7 @@ bool cPlugin_NewLua::OnHandshake(cClientHandle * a_Client, const AString & a_Use
}
bool bRetVal = (tolua_toboolean( m_LuaState, -1, 0) > 0);
lua_pop(m_LuaState, 1);
return bRetVal;
}