summaryrefslogtreecommitdiffstats
path: root/source/PluginLua.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-08-25 17:06:51 +0200
committermadmaxoft <github@xoft.cz>2013-08-25 17:06:51 +0200
commit83811b69292bff0ef4b24087a4a4d3e523b0076a (patch)
tree50bf797896f5df82af4cfcd642759d005c598044 /source/PluginLua.cpp
parentProjectile entities get saved into MCA files (diff)
parentReduced LeakFinder's stack buffers to half. (diff)
downloadcuberite-83811b69292bff0ef4b24087a4a4d3e523b0076a.tar
cuberite-83811b69292bff0ef4b24087a4a4d3e523b0076a.tar.gz
cuberite-83811b69292bff0ef4b24087a4a4d3e523b0076a.tar.bz2
cuberite-83811b69292bff0ef4b24087a4a4d3e523b0076a.tar.lz
cuberite-83811b69292bff0ef4b24087a4a4d3e523b0076a.tar.xz
cuberite-83811b69292bff0ef4b24087a4a4d3e523b0076a.tar.zst
cuberite-83811b69292bff0ef4b24087a4a4d3e523b0076a.zip
Diffstat (limited to '')
-rw-r--r--source/PluginLua.cpp30
1 files changed, 20 insertions, 10 deletions
diff --git a/source/PluginLua.cpp b/source/PluginLua.cpp
index 1c8cbef47..81a536838 100644
--- a/source/PluginLua.cpp
+++ b/source/PluginLua.cpp
@@ -1240,13 +1240,16 @@ void cPluginLua::ClearConsoleCommands(void)
-bool cPluginLua::CanAddHook(int a_Hook)
+bool cPluginLua::CanAddOldStyleHook(int a_HookType)
{
- const char * FnName = GetHookFnName(a_Hook);
+ const char * FnName = GetHookFnName(a_HookType);
if (FnName == NULL)
{
// Unknown hook ID
- LOGWARNING("Plugin %s wants to add an unknown hook ID (%d). The plugin need not work properly.", GetName().c_str(), a_Hook);
+ LOGWARNING("Plugin %s wants to add an unknown hook ID (%d). The plugin need not work properly.",
+ GetName().c_str(), a_HookType
+ );
+ m_LuaState.LogStackTrace();
return false;
}
@@ -1257,12 +1260,9 @@ bool cPluginLua::CanAddHook(int a_Hook)
}
LOGWARNING("Plugin %s wants to add a hook (%d), but it doesn't provide the callback function \"%s\" for it. The plugin need not work properly.",
- GetName().c_str(), a_Hook, FnName
+ GetName().c_str(), a_HookType, FnName
);
-
- // Lua stacktrace:
m_LuaState.LogStackTrace();
-
return false;
}
@@ -1270,9 +1270,9 @@ bool cPluginLua::CanAddHook(int a_Hook)
-const char * cPluginLua::GetHookFnName(int a_Hook)
+const char * cPluginLua::GetHookFnName(int a_HookType)
{
- switch (a_Hook)
+ switch (a_HookType)
{
case cPluginManager::HOOK_BLOCK_TO_PICKUPS: return "OnBlockToPickups";
case cPluginManager::HOOK_CHAT: return "OnChat";
@@ -1331,7 +1331,17 @@ bool cPluginLua::AddHookRef(int a_HookType, int a_FnRefIdx)
{
ASSERT(m_CriticalSection.IsLockedByCurrentThread()); // It probably has to be, how else would we have a LuaState?
- m_HookMap[a_HookType].push_back(new cLuaState::cRef(m_LuaState, a_FnRefIdx));
+ // Check if the function reference is valid:
+ cLuaState::cRef * Ref = new cLuaState::cRef(m_LuaState, a_FnRefIdx);
+ if ((Ref == NULL) || !Ref->IsValid())
+ {
+ LOGWARNING("Plugin %s tried to add a hook %d with bad handler function.", GetName().c_str(), a_HookType);
+ m_LuaState.LogStackTrace();
+ delete Ref;
+ return false;
+ }
+
+ m_HookMap[a_HookType].push_back(Ref);
return true;
}