Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool Plugin::CallPlayerHook(const char *hook, Player *playerObj) {
- std::list<Hook*>::iterator iter;
- try {
- for(iter = Hooks.begin(); iter != Hooks.end(); ++iter) {
- if(strcmp((*iter)->eventName, hook))
- continue;
- if(lua_gettop(Lua))
- return false;
- try {
- lua_getfield(Lua, LUA_GLOBALSINDEX, "PLUGINS");
- lua_pushnumber(Lua, this->id);
- lua_gettable(Lua, -2);
- lua_getfield(Lua, -1, (*iter)->functionName);
- } catch(...) {
- Console::PrintText("Exception with getting function for hook '%s' and plugin '%s'", hook, this->Name);
- lua_settop(Lua, 0);
- return false;
- }
- try {
- this->SetEnv();
- } catch(...) {
- Console::PrintText("Exception with SetEnv() for hook '%s' and plugin '%s'", hook, this->Name);
- lua_settop(Lua, 0);
- return false;
- }
- try {
- if (playerObj != NULL) {
- tolua_pushusertype(Lua, playerObj, "Player");
- } else {
- Console::PrintText("Player is NULL for hook '%s' and plugin '%s'", hook, this->Name);
- lua_settop(Lua, 0);
- return false;
- }
- } catch(...) {
- Console::PrintText("Exception with pushing params for hook '%s' and plugin '%s'", hook, this->Name);
- lua_settop(Lua, 0);
- return false;
- }
- try {
- if(lua_pcall(Lua, 1, 0, 0)) {
- Console::PrintText("LUA ERROR: %s", lua_tostring(Lua, -1));
- lua_pop(Lua, 1);
- }
- } catch(...) {
- Console::PrintText("Exception with hook pcall for hook '%s' and plugin '%s'", hook, this->Name);
- lua_settop(Lua, 0);
- return false;
- }
- lua_settop(Lua, 0);
- }
- } catch(...) {
- Console::PrintText("CallHook failed at '%s'. Retrying.", hook);
- lua_settop(Lua, 0);
- return false;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement