diff options
author | Mattes D <github@xoft.cz> | 2016-03-02 10:12:43 +0100 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2016-06-27 20:51:49 +0200 |
commit | 4489a89fdec9f4a507400150af34623899b64f46 (patch) | |
tree | 442c2c06ec3c06598d86e28c0745ecbbc5dc2feb /src/Bindings/ManualBindings.cpp | |
parent | Removed cWebPlugin, WebAdmin uses cLuaState::cCallback. (diff) | |
download | cuberite-4489a89fdec9f4a507400150af34623899b64f46.tar cuberite-4489a89fdec9f4a507400150af34623899b64f46.tar.gz cuberite-4489a89fdec9f4a507400150af34623899b64f46.tar.bz2 cuberite-4489a89fdec9f4a507400150af34623899b64f46.tar.lz cuberite-4489a89fdec9f4a507400150af34623899b64f46.tar.xz cuberite-4489a89fdec9f4a507400150af34623899b64f46.tar.zst cuberite-4489a89fdec9f4a507400150af34623899b64f46.zip |
Diffstat (limited to 'src/Bindings/ManualBindings.cpp')
-rw-r--r-- | src/Bindings/ManualBindings.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index bd781f766..7cf79d5da 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -993,7 +993,13 @@ static int tolua_cPluginManager_AddHook_FnRef(cPluginManager * a_PluginManager, } // Retrieve and check the hook type - int HookType = static_cast<int>(tolua_tonumber(S, a_ParamIdx, -1)); + int HookType; + if (!S.GetStackValue(a_ParamIdx, HookType)) + { + LOGWARNING("cPluginManager.AddHook(): Cannot read the hook type."); + S.LogStackTrace(); + return 0; + } if (!a_PluginManager->IsValidHookType(HookType)) { LOGWARNING("cPluginManager.AddHook(): Invalid HOOK_TYPE parameter: %d", HookType); @@ -1002,7 +1008,14 @@ static int tolua_cPluginManager_AddHook_FnRef(cPluginManager * a_PluginManager, } // Add the hook to the plugin - if (!Plugin->AddHookRef(HookType, a_ParamIdx + 1)) + auto callback = std::make_shared<cLuaState::cCallback>(); + if (!S.GetStackValue(a_ParamIdx + 1, callback)) + { + LOGWARNING("cPluginManager.AddHook(): Cannot read the callback parameter"); + S.LogStackTrace(); + return 0; + } + if (!Plugin->AddHookCallback(HookType, callback)) { LOGWARNING("cPluginManager.AddHook(): Cannot add hook %d, unknown error.", HookType); S.LogStackTrace(); @@ -1059,10 +1072,11 @@ static int tolua_cPluginManager_AddHook_DefFn(cPluginManager * a_PluginManager, } // Retrieve the function to call and add it to the plugin: - lua_pushstring(S, FnName); - bool res = Plugin->AddHookRef(HookType, 1); - lua_pop(S, 1); // Pop the function off the stack - if (!res) + auto callback = std::make_shared<cLuaState::cCallback>(); + lua_getglobal(S, FnName); + bool res = S.GetStackValue(-1, callback); + lua_pop(S, 1); + if (!res || !callback->IsValid()) { LOGWARNING("cPluginManager.AddHook(): Function %s not found. Hook not added.", FnName); S.LogStackTrace(); |