diff options
author | peterbell10 <peterbell10@live.co.uk> | 2017-09-11 23:20:49 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2017-09-11 23:20:49 +0200 |
commit | e225b7f8262df48ad4d7094bc295add3007b0649 (patch) | |
tree | a42e9afcc88cfe6e9d1258458e3ad42764083d0e /src/Bindings/ManualBindings.cpp | |
parent | cBlockArea: change MakeIndex to return size_t (diff) | |
download | cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.gz cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.bz2 cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.lz cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.xz cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.zst cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Bindings/ManualBindings.cpp | 68 |
1 files changed, 20 insertions, 48 deletions
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 38dc2cf83..5f8a3507d 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -1483,44 +1483,29 @@ static int tolua_cPluginManager_CallPlugin(lua_State * tolua_S) } // Call the destination plugin using a plugin callback: - class cCallback : - public cPluginManager::cPluginCallback - { - public: - int m_NumReturns; - - cCallback(const AString & a_FunctionName, cLuaState & a_SrcLuaState) : - m_NumReturns(0), - m_FunctionName(a_FunctionName), - m_SrcLuaState(a_SrcLuaState) + int NumReturns = 0; + auto PluginCallback = [&](cPlugin & a_Plugin) { - } - protected: - const AString & m_FunctionName; - cLuaState & m_SrcLuaState; - - virtual bool Item(cPlugin * a_Plugin) override - { - if (!a_Plugin->IsLoaded()) + if (!a_Plugin.IsLoaded()) { return false; } - m_NumReturns = static_cast<cPluginLua *>(a_Plugin)->CallFunctionFromForeignState( - m_FunctionName, m_SrcLuaState, 4, lua_gettop(m_SrcLuaState) + NumReturns = static_cast<cPluginLua &>(a_Plugin).CallFunctionFromForeignState( + FunctionName, L, 4, lua_gettop(L) ); return true; - } - } Callback(FunctionName, L); - if (!cPluginManager::Get()->DoWithPlugin(PluginName, Callback)) + }; + + if (!cPluginManager::Get()->DoWithPlugin(PluginName, PluginCallback)) { return 0; } - if (Callback.m_NumReturns < 0) + if (NumReturns < 0) { // The call has failed, there are zero return values. Do NOT return negative number (Lua considers that a "yield") return 0; } - return Callback.m_NumReturns; + return NumReturns; } @@ -3243,42 +3228,29 @@ static int tolua_cRoot_DoWithPlayerByUUID(lua_State * tolua_S) return 0; } - class cCallback : - public cPlayerListCallback - { - public: - cCallback(cLuaState & a_LuaState) : - m_LuaState(a_LuaState) - { - } - - virtual bool Item(cPlayer * a_Player) override - { - bool ret = false; - m_LuaState.Call(m_FnRef, a_Player, cLuaState::Return, ret); - return ret; - } - - cLuaState & m_LuaState; - cLuaState::cRef m_FnRef; - } Callback(L); - // Get parameters: cRoot * Self; cUUID PlayerUUID; - L.GetStackValues(1, Self, PlayerUUID, Callback.m_FnRef); + cLuaState::cRef FnRef; + L.GetStackValues(1, Self, PlayerUUID, FnRef); if (PlayerUUID.IsNil()) { return L.ApiParamError("Expected a non-nil UUID for parameter #1"); } - if (!Callback.m_FnRef.IsValid()) + if (!FnRef.IsValid()) { return L.ApiParamError("Expected a valid callback function for parameter #2"); } // Call the function: - bool res = Self->DoWithPlayerByUUID(PlayerUUID, Callback); + bool res = Self->DoWithPlayerByUUID(PlayerUUID, [&](cPlayer & a_Player) + { + bool ret = false; + L.Call(FnRef, &a_Player, cLuaState::Return, ret); + return ret; + } + ); // Push the result as the return value: L.Push(res); |