summaryrefslogtreecommitdiffstats
path: root/source/ManualBindings.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-05-31 09:16:14 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-05-31 09:16:14 +0200
commitbf7c2fe783133cd9f15d96981053ef7ab6aaf49a (patch)
tree3c30a01cd8690a59af2db1ee440bf7e8d2bc61f4 /source/ManualBindings.cpp
parentAdded the OnClosing callback to cLuaWindow API (diff)
downloadcuberite-bf7c2fe783133cd9f15d96981053ef7ab6aaf49a.tar
cuberite-bf7c2fe783133cd9f15d96981053ef7ab6aaf49a.tar.gz
cuberite-bf7c2fe783133cd9f15d96981053ef7ab6aaf49a.tar.bz2
cuberite-bf7c2fe783133cd9f15d96981053ef7ab6aaf49a.tar.lz
cuberite-bf7c2fe783133cd9f15d96981053ef7ab6aaf49a.tar.xz
cuberite-bf7c2fe783133cd9f15d96981053ef7ab6aaf49a.tar.zst
cuberite-bf7c2fe783133cd9f15d96981053ef7ab6aaf49a.zip
Diffstat (limited to 'source/ManualBindings.cpp')
-rw-r--r--source/ManualBindings.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/source/ManualBindings.cpp b/source/ManualBindings.cpp
index 96cd14370..0f8f1ad27 100644
--- a/source/ManualBindings.cpp
+++ b/source/ManualBindings.cpp
@@ -938,9 +938,13 @@ static int tolua_cPlayer_OpenWindow(lua_State * tolua_S)
-static int tolua_cLuaWindow_SetOnClosing(lua_State * tolua_S)
+template <
+ class OBJTYPE,
+ void (OBJTYPE::*SetCallback)(cPlugin_NewLua * a_Plugin, int a_FnRef)
+>
+static int tolua_SetObjectCallback(lua_State * tolua_S)
{
- // Function signature: cPlayer:SetOnClosing(CallbackFunction)
+ // Function signature: OBJTYPE:SetWhateverCallback(CallbackFunction)
// Retrieve the plugin instance from the Lua state
cPlugin_NewLua * Plugin = GetLuaPlugin(tolua_S);
@@ -950,14 +954,14 @@ static int tolua_cLuaWindow_SetOnClosing(lua_State * tolua_S)
return 0;
}
- // Get the parameters:
- cLuaWindow * self = (cLuaWindow *)tolua_tousertype(tolua_S, 1, NULL);
+ // Get the parameters - self and the function reference:
+ OBJTYPE * self = (OBJTYPE *)tolua_tousertype(tolua_S, 1, NULL);
if (self == NULL)
{
LOGWARNING("%s: invalid self (%p)", __FUNCTION__, self);
return 0;
}
- int FnRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX); // Store function reference
+ int FnRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX); // Store function reference for later retrieval
if (FnRef == LUA_REFNIL)
{
LOGERROR("%s: Cannot create a function reference. Callback not set.", __FUNCTION__);
@@ -965,7 +969,7 @@ static int tolua_cLuaWindow_SetOnClosing(lua_State * tolua_S)
}
// Set the callback
- self->SetOnClosing(Plugin, FnRef);
+ (self->*SetCallback)(Plugin, FnRef);
return 0;
}
@@ -1301,7 +1305,8 @@ void ManualBindings::Bind( lua_State* tolua_S )
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "cLuaWindow");
- tolua_function(tolua_S, "SetOnClosing", tolua_cLuaWindow_SetOnClosing);
+ tolua_function(tolua_S, "SetOnClosing", tolua_SetObjectCallback<cLuaWindow, &cLuaWindow::SetOnClosing>);
+ tolua_function(tolua_S, "SetOnSlotChanged", tolua_SetObjectCallback<cLuaWindow, &cLuaWindow::SetOnSlotChanged>);
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "cPlugin_NewLua");