From 2eb1240e14986e1cccc02a96713133a003347f8b Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Thu, 30 May 2013 20:40:43 +0000 Subject: Added the OnClosing callback to cLuaWindow API git-svn-id: http://mc-server.googlecode.com/svn/trunk@1534 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/ManualBindings.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'source/ManualBindings.cpp') diff --git a/source/ManualBindings.cpp b/source/ManualBindings.cpp index ceb24da30..96cd14370 100644 --- a/source/ManualBindings.cpp +++ b/source/ManualBindings.cpp @@ -938,6 +938,41 @@ static int tolua_cPlayer_OpenWindow(lua_State * tolua_S) +static int tolua_cLuaWindow_SetOnClosing(lua_State * tolua_S) +{ + // Function signature: cPlayer:SetOnClosing(CallbackFunction) + + // Retrieve the plugin instance from the Lua state + cPlugin_NewLua * Plugin = GetLuaPlugin(tolua_S); + if (Plugin == NULL) + { + // Warning message has already been printed by GetLuaPlugin(), bail out silently + return 0; + } + + // Get the parameters: + cLuaWindow * self = (cLuaWindow *)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 + if (FnRef == LUA_REFNIL) + { + LOGERROR("%s: Cannot create a function reference. Callback not set.", __FUNCTION__); + return 0; + } + + // Set the callback + self->SetOnClosing(Plugin, FnRef); + return 0; +} + + + + + static int tolua_cPlugin_NewLua_AddWebTab(lua_State * tolua_S) { cPlugin_NewLua * self = (cPlugin_NewLua*)tolua_tousertype(tolua_S,1,0); @@ -1265,6 +1300,10 @@ void ManualBindings::Bind( lua_State* tolua_S ) tolua_function(tolua_S, "OpenWindow", tolua_cPlayer_OpenWindow); tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cLuaWindow"); + tolua_function(tolua_S, "SetOnClosing", tolua_cLuaWindow_SetOnClosing); + tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cPlugin_NewLua"); tolua_function(tolua_S, "AddWebTab", tolua_cPlugin_NewLua_AddWebTab); tolua_function(tolua_S, "AddTab", tolua_cPlugin_NewLua_AddTab); -- cgit v1.2.3