summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2016-06-27 20:49:59 +0200
committerMattes D <github@xoft.cz>2016-06-27 20:51:53 +0200
commitbf88312a1664311968736b4ba7ce1458c8b0954e (patch)
tree59bae2de637b5f3c629db8e55fb44a3106266709 /src
parentRemoved dead code related to callbacks. (diff)
downloadcuberite-bf88312a1664311968736b4ba7ce1458c8b0954e.tar
cuberite-bf88312a1664311968736b4ba7ce1458c8b0954e.tar.gz
cuberite-bf88312a1664311968736b4ba7ce1458c8b0954e.tar.bz2
cuberite-bf88312a1664311968736b4ba7ce1458c8b0954e.tar.lz
cuberite-bf88312a1664311968736b4ba7ce1458c8b0954e.tar.xz
cuberite-bf88312a1664311968736b4ba7ce1458c8b0954e.tar.zst
cuberite-bf88312a1664311968736b4ba7ce1458c8b0954e.zip
Diffstat (limited to 'src')
-rw-r--r--src/Bindings/LuaChunkStay.cpp4
-rw-r--r--src/Bindings/LuaState.cpp13
-rw-r--r--src/Bindings/LuaState.h4
-rw-r--r--src/Bindings/LuaWindow.cpp8
-rw-r--r--src/Bindings/LuaWindow.h4
-rw-r--r--src/Bindings/ManualBindings.cpp18
-rw-r--r--src/Bindings/ManualBindings_World.cpp4
-rw-r--r--src/Bindings/PluginLua.cpp6
-rw-r--r--src/Bindings/PluginLua.h2
9 files changed, 39 insertions, 24 deletions
diff --git a/src/Bindings/LuaChunkStay.cpp b/src/Bindings/LuaChunkStay.cpp
index 819e10f19..145a9ee1b 100644
--- a/src/Bindings/LuaChunkStay.cpp
+++ b/src/Bindings/LuaChunkStay.cpp
@@ -115,8 +115,8 @@ void cLuaChunkStay::AddChunkCoord(cLuaState & L, int a_Index)
void cLuaChunkStay::Enable(cChunkMap & a_ChunkMap, cLuaState::cCallbackPtr a_OnChunkAvailable, cLuaState::cCallbackPtr a_OnAllChunksAvailable)
{
- m_OnChunkAvailable = a_OnChunkAvailable;
- m_OnAllChunksAvailable = a_OnAllChunksAvailable;
+ m_OnChunkAvailable = std::move(a_OnChunkAvailable);
+ m_OnAllChunksAvailable = std::move(a_OnAllChunksAvailable);
// Enable the ChunkStay:
super::Enable(a_ChunkMap);
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp
index 109809cab..5e6c24365 100644
--- a/src/Bindings/LuaState.cpp
+++ b/src/Bindings/LuaState.cpp
@@ -1023,6 +1023,19 @@ bool cLuaState::GetStackValue(int a_StackPos, cCallbackPtr & a_Callback)
{
if (a_Callback == nullptr)
{
+ a_Callback = cpp14::make_unique<cCallback>();
+ }
+ return a_Callback->RefStack(*this, a_StackPos);
+}
+
+
+
+
+
+bool cLuaState::GetStackValue(int a_StackPos, cCallbackSharedPtr & a_Callback)
+{
+ if (a_Callback == nullptr)
+ {
a_Callback = std::make_shared<cCallback>();
}
return a_Callback->RefStack(*this, a_StackPos);
diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h
index d3acb2797..106d8a783 100644
--- a/src/Bindings/LuaState.h
+++ b/src/Bindings/LuaState.h
@@ -216,7 +216,8 @@ public:
Use cCallbackPtr for a copyable object. */
cCallback(cCallback &&) = delete;
};
- typedef SharedPtr<cCallback> cCallbackPtr;
+ typedef UniquePtr<cCallback> cCallbackPtr;
+ typedef SharedPtr<cCallback> cCallbackSharedPtr;
/** A dummy class that's used only to delimit function args from return values for cLuaState::Call() */
@@ -380,6 +381,7 @@ public:
bool GetStackValue(int a_StackPos, bool & a_Value);
bool GetStackValue(int a_StackPos, cCallback & a_Callback);
bool GetStackValue(int a_StackPos, cCallbackPtr & a_Callback);
+ bool GetStackValue(int a_StackPos, cCallbackSharedPtr & a_Callback);
bool GetStackValue(int a_StackPos, cPluginManager::CommandResult & a_Result);
bool GetStackValue(int a_StackPos, cRef & a_Ref);
bool GetStackValue(int a_StackPos, double & a_Value);
diff --git a/src/Bindings/LuaWindow.cpp b/src/Bindings/LuaWindow.cpp
index bf3f7cfde..6fffa7aac 100644
--- a/src/Bindings/LuaWindow.cpp
+++ b/src/Bindings/LuaWindow.cpp
@@ -66,26 +66,26 @@ cLuaWindow::~cLuaWindow()
-void cLuaWindow::SetOnClosing(cLuaState::cCallbackPtr a_OnClosing)
+void cLuaWindow::SetOnClosing(cLuaState::cCallbackPtr && a_OnClosing)
{
// Only one Lua state can be a cLuaWindow object callback:
ASSERT(a_OnClosing->IsSameLuaState(*m_LuaState));
// Store the new reference, releasing the old one if appropriate:
- m_OnClosing = a_OnClosing;
+ m_OnClosing = std::move(a_OnClosing);
}
-void cLuaWindow::SetOnSlotChanged(cLuaState::cCallbackPtr a_OnSlotChanged)
+void cLuaWindow::SetOnSlotChanged(cLuaState::cCallbackPtr && a_OnSlotChanged)
{
// Only one Lua state can be a cLuaWindow object callback:
ASSERT(a_OnSlotChanged->IsSameLuaState(*m_LuaState));
// Store the new reference, releasing the old one if appropriate:
- m_OnSlotChanged = a_OnSlotChanged;
+ m_OnSlotChanged = std::move(a_OnSlotChanged);
}
diff --git a/src/Bindings/LuaWindow.h b/src/Bindings/LuaWindow.h
index 2a16d91ed..5f987d4c6 100644
--- a/src/Bindings/LuaWindow.h
+++ b/src/Bindings/LuaWindow.h
@@ -50,10 +50,10 @@ public:
// tolua_end
/** Sets the Lua callback function to call when the window is about to close */
- void SetOnClosing(cLuaState::cCallbackPtr a_OnClosing);
+ void SetOnClosing(cLuaState::cCallbackPtr && a_OnClosing);
/** Sets the Lua callback function to call when a slot is changed */
- void SetOnSlotChanged(cLuaState::cCallbackPtr a_OnSlotChanged);
+ void SetOnSlotChanged(cLuaState::cCallbackPtr && a_OnSlotChanged);
protected:
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 12cdd3d71..1d735ac83 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -51,8 +51,8 @@ class LuaCommandHandler:
public cPluginManager::cCommandHandler
{
public:
- LuaCommandHandler(cLuaState::cCallbackPtr a_Callback):
- m_Callback(a_Callback)
+ LuaCommandHandler(cLuaState::cCallbackPtr && a_Callback):
+ m_Callback(std::move(a_Callback))
{
}
@@ -1052,14 +1052,14 @@ static int tolua_cPluginManager_AddHook_FnRef(cPluginManager * a_PluginManager,
}
// Add the hook to the plugin
- auto callback = std::make_shared<cLuaState::cCallback>();
+ cLuaState::cCallbackPtr callback;
if (!S.GetStackValue(a_ParamIdx + 1, callback))
{
LOGWARNING("cPluginManager.AddHook(): Cannot read the callback parameter");
S.LogStackTrace();
return 0;
}
- if (!Plugin->AddHookCallback(HookType, callback))
+ if (!Plugin->AddHookCallback(HookType, std::move(callback)))
{
LOGWARNING("cPluginManager.AddHook(): Cannot add hook %d, unknown error.", HookType);
S.LogStackTrace();
@@ -1116,7 +1116,7 @@ static int tolua_cPluginManager_AddHook_DefFn(cPluginManager * a_PluginManager,
}
// Retrieve the function to call and add it to the plugin:
- auto callback = std::make_shared<cLuaState::cCallback>();
+ cLuaState::cCallbackPtr callback;
lua_getglobal(S, FnName);
bool res = S.GetStackValue(-1, callback);
lua_pop(S, 1);
@@ -1360,7 +1360,7 @@ static int tolua_cPluginManager_BindCommand(lua_State * a_LuaState)
return 0;
}
- auto CommandHandler = std::make_shared<LuaCommandHandler>(Handler);
+ auto CommandHandler = std::make_shared<LuaCommandHandler>(std::move(Handler));
if (!self->BindCommand(Command, Plugin, CommandHandler, Permission, HelpString))
{
// Refused. Possibly already bound. Error message has been given, display the callstack:
@@ -1425,7 +1425,7 @@ static int tolua_cPluginManager_BindConsoleCommand(lua_State * a_LuaState)
return 0;
}
- auto CommandHandler = std::make_shared<LuaCommandHandler>(Handler);
+ auto CommandHandler = std::make_shared<LuaCommandHandler>(std::move(Handler));
if (!self->BindConsoleCommand(Command, Plugin, CommandHandler, HelpString))
{
// Refused. Possibly already bound. Error message has been given, display the callstack:
@@ -1666,7 +1666,7 @@ static int tolua_cPlayer_PermissionMatches(lua_State * tolua_S)
template <
class OBJTYPE,
- void (OBJTYPE::*SetCallback)(cLuaState::cCallbackPtr a_CallbackFn)
+ void (OBJTYPE::*SetCallback)(cLuaState::cCallbackPtr && a_CallbackFn)
>
static int tolua_SetObjectCallback(lua_State * tolua_S)
{
@@ -1684,7 +1684,7 @@ static int tolua_SetObjectCallback(lua_State * tolua_S)
}
// Set the callback
- (self->*SetCallback)(callback);
+ (self->*SetCallback)(std::move(callback));
return 0;
}
diff --git a/src/Bindings/ManualBindings_World.cpp b/src/Bindings/ManualBindings_World.cpp
index 3f9f5f94d..b3170a636 100644
--- a/src/Bindings/ManualBindings_World.cpp
+++ b/src/Bindings/ManualBindings_World.cpp
@@ -105,7 +105,7 @@ static int tolua_cWorld_ChunkStay(lua_State * tolua_S)
cLuaState::cCallbackPtr onChunkAvailable, onAllChunksAvailable;
L.GetStackValues(3, onChunkAvailable, onAllChunksAvailable); // Callbacks may be unassigned at all - as a request to load / generate chunks
- ChunkStay->Enable(*World->GetChunkMap(), onChunkAvailable, onAllChunksAvailable);
+ ChunkStay->Enable(*World->GetChunkMap(), std::move(onChunkAvailable), std::move(onAllChunksAvailable));
return 0;
}
@@ -484,7 +484,7 @@ static int tolua_cWorld_QueueTask(lua_State * tolua_S)
return 0;
}
cWorld * World;
- auto Task = std::make_shared<cLuaState::cCallback>();
+ cLuaState::cCallbackSharedPtr Task;
if (!L.GetStackValues(1, World, Task))
{
return cManualBindings::lua_do_error(tolua_S, "Error in function call '#funcname#': Cannot read parameters");
diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp
index 07d0a7526..d1fc2ae4f 100644
--- a/src/Bindings/PluginLua.cpp
+++ b/src/Bindings/PluginLua.cpp
@@ -260,7 +260,7 @@ bool cPluginLua::OnChat(cPlayer & a_Player, AString & a_Message)
}
bool res = false;
auto & hooks = m_HookMap[cPluginManager::HOOK_CHAT];
- for (auto hook: hooks)
+ for (auto & hook: hooks)
{
hook->Call(&a_Player, a_Message, cLuaState::Return, res, a_Message);
if (res)
@@ -1096,9 +1096,9 @@ const char * cPluginLua::GetHookFnName(int a_HookType)
-bool cPluginLua::AddHookCallback(int a_HookType, cLuaState::cCallbackPtr a_Callback)
+bool cPluginLua::AddHookCallback(int a_HookType, cLuaState::cCallbackPtr && a_Callback)
{
- m_HookMap[a_HookType].push_back(a_Callback);
+ m_HookMap[a_HookType].push_back(std::move(a_Callback));
return true;
}
diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h
index e28e30698..dc3c91880 100644
--- a/src/Bindings/PluginLua.h
+++ b/src/Bindings/PluginLua.h
@@ -146,7 +146,7 @@ public:
/** Adds a Lua callback to be called for the specified hook.
Returns true if the hook was added successfully. */
- bool AddHookCallback(int a_HookType, cLuaState::cCallbackPtr a_Callback);
+ bool AddHookCallback(int a_HookType, cLuaState::cCallbackPtr && a_Callback);
/** Calls a function in this plugin's LuaState with parameters copied over from a_ForeignState.
The values that the function returns are placed onto a_ForeignState.