summaryrefslogtreecommitdiffstats
path: root/src/Bindings
diff options
context:
space:
mode:
Diffstat (limited to 'src/Bindings')
-rw-r--r--src/Bindings/LuaState.cpp4
-rw-r--r--src/Bindings/LuaState.h5
-rw-r--r--src/Bindings/LuaWindow.cpp15
-rw-r--r--src/Bindings/LuaWindow.h2
-rw-r--r--src/Bindings/ManualBindings.cpp68
-rw-r--r--src/Bindings/ManualBindings.h235
-rw-r--r--src/Bindings/ManualBindings_World.cpp6
-rw-r--r--src/Bindings/PluginManager.cpp8
-rw-r--r--src/Bindings/PluginManager.h9
9 files changed, 94 insertions, 258 deletions
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp
index 7bd4becb6..82dbfb780 100644
--- a/src/Bindings/LuaState.cpp
+++ b/src/Bindings/LuaState.cpp
@@ -379,7 +379,7 @@ cLuaState::cStackTable::cStackTable(cLuaState & a_LuaState, int a_StackPos):
-void cLuaState::cStackTable::ForEachArrayElement(std::function<bool(cLuaState & a_LuaState, int a_Index)> a_ElementCallback) const
+void cLuaState::cStackTable::ForEachArrayElement(cFunctionRef<bool(cLuaState & a_LuaState, int a_Index)> a_ElementCallback) const
{
auto numElements = luaL_getn(m_LuaState, m_StackPos);
#ifdef _DEBUG
@@ -404,7 +404,7 @@ void cLuaState::cStackTable::ForEachArrayElement(std::function<bool(cLuaState &
-void cLuaState::cStackTable::ForEachElement(std::function<bool(cLuaState & a_LuaState)> a_ElementCallback) const
+void cLuaState::cStackTable::ForEachElement(cFunctionRef<bool(cLuaState & a_LuaState)> a_ElementCallback) const
{
#ifdef _DEBUG
auto stackTop = lua_gettop(m_LuaState);
diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h
index 98f1cbc28..60af36228 100644
--- a/src/Bindings/LuaState.h
+++ b/src/Bindings/LuaState.h
@@ -39,6 +39,7 @@ extern "C"
#include <functional>
#include "../Defines.h"
+#include "../FunctionRef.h"
#include "PluginManager.h"
#include "LuaState_Typedefs.inc"
@@ -521,14 +522,14 @@ public:
The callback receives the LuaState in which the table resides, and the element's index. The LuaState has
the element on top of its stack. If the callback returns true, the iteration is aborted, if it returns
false, the iteration continues with the next element. */
- void ForEachArrayElement(std::function<bool(cLuaState & a_LuaState, int a_Index)> a_ElementCallback) const;
+ void ForEachArrayElement(cFunctionRef<bool(cLuaState & a_LuaState, int a_Index)> a_ElementCallback) const;
/** Iterates over all dictionary elements in the table in random order, and calls the a_ElementCallback for
each of them.
The callback receives the LuaState in which the table reside. The LuaState has the element on top of its
stack, and the element's key just below it. If the callback returns true, the iteration is aborted, if it
returns false, the iteration continues with the next element. */
- void ForEachElement(std::function<bool(cLuaState & a_LuaState)> a_ElementCallback) const;
+ void ForEachElement(cFunctionRef<bool(cLuaState & a_LuaState)> a_ElementCallback) const;
cLuaState & GetLuaState(void) const { return m_LuaState; }
diff --git a/src/Bindings/LuaWindow.cpp b/src/Bindings/LuaWindow.cpp
index 2802c69db..ae390e576 100644
--- a/src/Bindings/LuaWindow.cpp
+++ b/src/Bindings/LuaWindow.cpp
@@ -54,22 +54,15 @@ cLuaWindow::~cLuaWindow()
m_Contents.RemoveListener(*this);
// Close open lua window from players, to avoid dangling pointers
- class cPlayerCallback : public cPlayerListCallback
- {
- virtual bool Item(cPlayer * a_Player)
+ cRoot::Get()->ForEachPlayer([this](cPlayer & a_Player)
{
- if (a_Player->GetWindow() == m_LuaWindow)
+ if (a_Player.GetWindow() == this)
{
- a_Player->CloseWindow(false);
+ a_Player.CloseWindow(false);
}
return false;
}
- cLuaWindow * m_LuaWindow;
- public:
- cPlayerCallback(cLuaWindow & a_LuaWindow) { m_LuaWindow = &a_LuaWindow; }
- } PlayerCallback(*this);
-
- cRoot::Get()->ForEachPlayer(PlayerCallback);
+ );
// Must delete slot areas now, because they are referencing this->m_Contents and would try to access it in cWindow's
// destructor, when the member is already gone.
diff --git a/src/Bindings/LuaWindow.h b/src/Bindings/LuaWindow.h
index 8f3349d00..6177b2cbe 100644
--- a/src/Bindings/LuaWindow.h
+++ b/src/Bindings/LuaWindow.h
@@ -15,7 +15,7 @@
class cPlayer;
-typedef cItemCallback<cPlayer> cPlayerListCallback;
+typedef cFunctionRef<bool(cPlayer &)> cPlayerListCallback;
/** A window that has been created by a Lua plugin and is handled entirely by that plugin
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);
diff --git a/src/Bindings/ManualBindings.h b/src/Bindings/ManualBindings.h
index dc9d9462f..0272e993b 100644
--- a/src/Bindings/ManualBindings.h
+++ b/src/Bindings/ManualBindings.h
@@ -1,4 +1,4 @@
-
+
// ManualBindings.h
// Declares the cManualBindings class used as a namespace for functions exported to the Lua API manually
@@ -57,7 +57,7 @@ public:
template <
class Ty1,
class Ty2,
- bool (Ty1::*DoWithFn)(const AString &, cItemCallback<Ty2> &)
+ bool (Ty1::*DoWithFn)(const AString &, cFunctionRef<bool(Ty2 &)>)
>
static int DoWith(lua_State * tolua_S)
{
@@ -89,28 +89,14 @@ public:
return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a valid callback function for parameter #2");
}
- class cLuaCallback : public cItemCallback<Ty2>
- {
- public:
- cLuaCallback(cLuaState & a_LuaState, cLuaState::cRef & a_FnRef):
- m_LuaState(a_LuaState),
- m_FnRef(a_FnRef)
- {
- }
-
- private:
- virtual bool Item(Ty2 * a_Item) override
+ // Call the DoWith function:
+ bool res = (Self->*DoWithFn)(ItemName, [&](Ty2 & a_Item)
{
bool ret = false;
- m_LuaState.Call(m_FnRef, a_Item, cLuaState::Return, ret);
+ L.Call(FnRef, &a_Item, cLuaState::Return, ret);
return ret;
}
- cLuaState & m_LuaState;
- cLuaState::cRef & m_FnRef;
- } Callback(L, FnRef);
-
- // Call the DoWith function:
- bool res = (Self->*DoWithFn)(ItemName, Callback);
+ );
// Push the result as the return value:
L.Push(res);
@@ -125,7 +111,7 @@ public:
template <
class Ty1,
class Ty2,
- bool (Ty1::*DoWithFn)(const AString &, cItemCallback<Ty2> &)
+ bool (Ty1::*DoWithFn)(const AString &, cFunctionRef<bool(Ty2 &)>)
>
static int StaticDoWith(lua_State * tolua_S)
{
@@ -152,28 +138,14 @@ public:
return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a valid callback function for parameter #2");
}
- class cLuaCallback : public cItemCallback<Ty2>
- {
- public:
- cLuaCallback(cLuaState & a_LuaState, cLuaState::cRef & a_FnRef):
- m_LuaState(a_LuaState),
- m_FnRef(a_FnRef)
- {
- }
-
- private:
- virtual bool Item(Ty2 * a_Item) override
+ // Call the DoWith function:
+ bool res = (Ty1::Get()->*DoWithFn)(ItemName, [&](Ty2 & a_Item)
{
bool ret = false;
- m_LuaState.Call(m_FnRef, a_Item, cLuaState::Return, ret);
+ L.Call(FnRef, &a_Item, cLuaState::Return, ret);
return ret;
}
- cLuaState & m_LuaState;
- cLuaState::cRef & m_FnRef;
- } Callback(L, FnRef);
-
- // Call the DoWith function:
- bool res = (Ty1::Get()->*DoWithFn)(ItemName, Callback);
+ );
// Push the result as the return value:
L.Push(res);
@@ -187,7 +159,7 @@ public:
template <
class Ty1,
class Ty2,
- bool (Ty1::*DoWithFn)(UInt32, cItemCallback<Ty2> &)
+ bool (Ty1::*DoWithFn)(UInt32, cFunctionRef<bool(Ty2 &)>)
>
static int DoWithID(lua_State * tolua_S)
{
@@ -215,28 +187,14 @@ public:
return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a valid callback function for parameter #2");
}
- class cLuaCallback : public cItemCallback<Ty2>
- {
- public:
- cLuaCallback(cLuaState & a_LuaState, cLuaState::cRef & a_FnRef):
- m_LuaState(a_LuaState),
- m_FnRef(a_FnRef)
- {
- }
-
- private:
- virtual bool Item(Ty2 * a_Item) override
+ // Call the DoWith function:
+ bool res = (Self->*DoWithFn)(ItemID, [&](Ty2 & a_Item)
{
bool ret = false;
- m_LuaState.Call(m_FnRef, a_Item, cLuaState::Return, ret);
+ L.Call(FnRef, &a_Item, cLuaState::Return, ret);
return ret;
}
- cLuaState & m_LuaState;
- cLuaState::cRef & m_FnRef;
- } Callback(L, FnRef);
-
- // Call the DoWith function:
- bool res = (Self->*DoWithFn)(ItemID, Callback);
+ );
// Push the result as the return value:
L.Push(res);
@@ -251,7 +209,7 @@ public:
template <
class SELF,
class ITEM,
- bool (SELF::*DoWithFn)(int, int, int, cItemCallback<ITEM> &)
+ bool (SELF::*DoWithFn)(int, int, int, cFunctionRef<bool(ITEM &)>)
>
static int DoWithXYZ(lua_State * tolua_S)
{
@@ -282,28 +240,14 @@ public:
return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a valid callback function for parameter #5");
}
- class cLuaCallback : public cItemCallback<ITEM>
- {
- public:
- cLuaCallback(cLuaState & a_LuaState, cLuaState::cRef & a_FnRef):
- m_LuaState(a_LuaState),
- m_FnRef(a_FnRef)
- {
- }
-
- private:
- virtual bool Item(ITEM * a_Item) override
+ // Call the DoWith function:
+ bool res = (Self->*DoWithFn)(BlockX, BlockY, BlockZ, [&](ITEM & a_Item)
{
bool ret = false;
- m_LuaState.Call(m_FnRef, a_Item, cLuaState::Return, ret);
+ L.Call(FnRef, &a_Item, cLuaState::Return, ret);
return ret;
}
- cLuaState & m_LuaState;
- cLuaState::cRef & m_FnRef;
- } Callback(L, FnRef);
-
- // Call the DoWith function:
- bool res = (Self->*DoWithFn)(BlockX, BlockY, BlockZ, Callback);
+ );
// Push the result as the return value:
L.Push(res);
@@ -318,7 +262,7 @@ public:
template <
class SELF,
class ITEM,
- bool (SELF::*DoWithFn)(int, int, int, cItemCallback<ITEM> &),
+ bool (SELF::*DoWithFn)(int, int, int, cFunctionRef<bool(ITEM &)>),
bool (SELF::*CoordCheckFn)(int, int, int) const
>
static int DoWithXYZ(lua_State * tolua_S)
@@ -356,28 +300,14 @@ public:
).c_str());
}
- class cLuaCallback : public cItemCallback<ITEM>
- {
- public:
- cLuaCallback(cLuaState & a_LuaState, cLuaState::cRef & a_FnRef):
- m_LuaState(a_LuaState),
- m_FnRef(a_FnRef)
- {
- }
-
- private:
- virtual bool Item(ITEM * a_Item) override
+ // Call the DoWith function:
+ bool res = (Self->*DoWithFn)(BlockX, BlockY, BlockZ, [&](ITEM & a_Item)
{
bool ret = false;
- m_LuaState.Call(m_FnRef, a_Item, cLuaState::Return, ret);
+ L.Call(FnRef, &a_Item, cLuaState::Return, ret);
return ret;
}
- cLuaState & m_LuaState;
- cLuaState::cRef & m_FnRef;
- } Callback(L, FnRef);
-
- // Call the DoWith function:
- bool res = (Self->*DoWithFn)(BlockX, BlockY, BlockZ, Callback);
+ );
// Push the result as the return value:
L.Push(res);
@@ -391,7 +321,7 @@ public:
template <
class Ty1,
class Ty2,
- bool (Ty1::*ForEachFn)(int, int, cItemCallback<Ty2> &)
+ bool (Ty1::*ForEachFn)(int, int, cFunctionRef<bool(Ty2 &)>)
>
static int ForEachInChunk(lua_State * tolua_S)
{
@@ -421,28 +351,14 @@ public:
return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a valid callback function for parameter #4");
}
- class cLuaCallback : public cItemCallback<Ty2>
- {
- public:
- cLuaCallback(cLuaState & a_LuaState, cLuaState::cRef & a_FnRef):
- m_LuaState(a_LuaState),
- m_FnRef(a_FnRef)
- {
- }
-
- private:
- virtual bool Item(Ty2 * a_Item) override
+ // Call the DoWith function:
+ bool res = (Self->*ForEachFn)(ChunkX, ChunkZ, [&](Ty2 & a_Item)
{
bool ret = false;
- m_LuaState.Call(m_FnRef, a_Item, cLuaState::Return, ret);
+ L.Call(FnRef, &a_Item, cLuaState::Return, ret);
return ret;
}
- cLuaState & m_LuaState;
- cLuaState::cRef & m_FnRef;
- } Callback(L, FnRef);
-
- // Call the DoWith function:
- bool res = (Self->*ForEachFn)(ChunkX, ChunkZ, Callback);
+ );
// Push the result as the return value:
L.Push(res);
@@ -456,7 +372,7 @@ public:
template <
class Ty1,
class Ty2,
- bool (Ty1::*ForEachFn)(const cBoundingBox &, cItemCallback<Ty2> &)
+ bool (Ty1::*ForEachFn)(const cBoundingBox &, cFunctionRef<bool(Ty2 &)>)
>
static int ForEachInBox(lua_State * tolua_S)
{
@@ -488,36 +404,19 @@ public:
return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a valid callback function for parameter #2");
}
- // Callback wrapper for the Lua function:
- class cLuaCallback : public cItemCallback<Ty2>
- {
- public:
- cLuaCallback(cLuaState & a_LuaState, cLuaState::cRef & a_FuncRef) :
- m_LuaState(a_LuaState),
- m_FnRef(a_FuncRef)
+ bool res = (Self->*ForEachFn)(*Box, [&](Ty2 & a_Item)
{
- }
-
- private:
- cLuaState & m_LuaState;
- cLuaState::cRef & m_FnRef;
-
- // cItemCallback<Ty2> overrides:
- virtual bool Item(Ty2 * a_Item) override
- {
- bool res = false;
- if (!m_LuaState.Call(m_FnRef, a_Item, cLuaState::Return, res))
+ bool ret = false;
+ if (!L.Call(FnRef, &a_Item, cLuaState::Return, ret))
{
LOGWARNING("Failed to call Lua callback");
- m_LuaState.LogStackTrace();
+ L.LogStackTrace();
return true; // Abort enumeration
}
- return res;
+ return ret;
}
- } Callback(L, FnRef);
-
- bool res = (Self->*ForEachFn)(*Box, Callback);
+ );
// Push the result as the return value:
L.Push(res);
@@ -531,7 +430,7 @@ public:
template <
class Ty1,
class Ty2,
- bool (Ty1::*ForEachFn)(cItemCallback<Ty2> &)
+ bool (Ty1::*ForEachFn)(cFunctionRef<bool(Ty2 &)>)
>
static int ForEach(lua_State * tolua_S)
{
@@ -558,29 +457,14 @@ public:
return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a valid callback function for parameter #1");
}
- class cLuaCallback : public cItemCallback<Ty2>
- {
- public:
- cLuaCallback(cLuaState & a_LuaState, cLuaState::cRef & a_FnRef):
- m_LuaState(a_LuaState),
- m_FnRef(a_FnRef)
- {
- }
-
- private:
- cLuaState & m_LuaState;
- cLuaState::cRef & m_FnRef;
-
- virtual bool Item(Ty2 * a_Item) override
+ // Call the enumeration:
+ bool res = (Self->*ForEachFn)([&](Ty2 & a_Item)
{
- bool res = false; // By default continue the enumeration
- m_LuaState.Call(m_FnRef, a_Item, cLuaState::Return, res);
- return res;
+ bool ret = false; // By default continue the enumeration
+ L.Call(FnRef, &a_Item, cLuaState::Return, ret);
+ return ret;
}
- } Callback(L, FnRef);
-
- // Call the enumeration:
- bool res = (Self->*ForEachFn)(Callback);
+ );
// Push the return value:
L.Push(res);
@@ -595,7 +479,7 @@ public:
template <
class Ty1,
class Ty2,
- bool (Ty1::*ForEachFn)(cItemCallback<Ty2> &)
+ bool (Ty1::*ForEachFn)(cFunctionRef<bool(Ty2 &)>)
>
static int StaticForEach(lua_State * tolua_S)
{
@@ -616,29 +500,14 @@ public:
return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a valid callback function for parameter #1");
}
- class cLuaCallback : public cItemCallback<Ty2>
- {
- public:
- cLuaCallback(cLuaState & a_LuaState, cLuaState::cRef & a_FnRef):
- m_LuaState(a_LuaState),
- m_FnRef(a_FnRef)
- {
- }
-
- private:
- cLuaState & m_LuaState;
- cLuaState::cRef & m_FnRef;
-
- virtual bool Item(Ty2 * a_Item) override
+ // Call the enumeration:
+ bool res = (Ty1::Get()->*ForEachFn)([&](Ty2 & a_Item)
{
- bool res = false; // By default continue the enumeration
- m_LuaState.Call(m_FnRef, a_Item, cLuaState::Return, res);
- return res;
+ bool ret = false; // By default continue the enumeration
+ L.Call(FnRef, &a_Item, cLuaState::Return, ret);
+ return ret;
}
- } Callback(L, FnRef);
-
- // Call the enumeration:
- bool res = (Ty1::Get()->*ForEachFn)(Callback);
+ );
// Push the return value:
L.Push(res);
diff --git a/src/Bindings/ManualBindings_World.cpp b/src/Bindings/ManualBindings_World.cpp
index 10b5daf1e..826439e3f 100644
--- a/src/Bindings/ManualBindings_World.cpp
+++ b/src/Bindings/ManualBindings_World.cpp
@@ -1,4 +1,4 @@
-
+
// ManualBindings_World.cpp
// Implements the manual Lua API bindings for the cWorld class
@@ -237,10 +237,10 @@ static int tolua_cWorld_DoWithPlayerByUUID(lua_State * tolua_S)
}
// Call the function:
- bool res = Self->DoWithPlayerByUUID(PlayerUUID, [&](cPlayer * a_Player)
+ bool res = Self->DoWithPlayerByUUID(PlayerUUID, [&](cPlayer & a_Player)
{
bool ret = false;
- L.Call(FnRef, a_Player, cLuaState::Return, ret);
+ L.Call(FnRef, &a_Player, cLuaState::Return, ret);
return ret;
}
);
diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp
index 7c4712f0f..9a9b56792 100644
--- a/src/Bindings/PluginManager.cpp
+++ b/src/Bindings/PluginManager.cpp
@@ -1993,14 +1993,14 @@ bool cPluginManager::IsValidHookType(int a_HookType)
-bool cPluginManager::DoWithPlugin(const AString & a_PluginName, cPluginCallback & a_Callback)
+bool cPluginManager::DoWithPlugin(const AString & a_PluginName, cPluginCallback a_Callback)
{
// TODO: Implement locking for plugins
for (auto & plugin: m_Plugins)
{
if (plugin->GetName() == a_PluginName)
{
- return a_Callback.Item(plugin.get());
+ return a_Callback(*plugin);
}
}
return false;
@@ -2010,12 +2010,12 @@ bool cPluginManager::DoWithPlugin(const AString & a_PluginName, cPluginCallback
-bool cPluginManager::ForEachPlugin(cPluginCallback & a_Callback)
+bool cPluginManager::ForEachPlugin(cPluginCallback a_Callback)
{
// TODO: Implement locking for plugins
for (auto & plugin: m_Plugins)
{
- if (a_Callback.Item(plugin.get()))
+ if (a_Callback(*plugin))
{
return false;
}
diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h
index 66f7d290a..fdc1d1e7a 100644
--- a/src/Bindings/PluginManager.h
+++ b/src/Bindings/PluginManager.h
@@ -3,6 +3,7 @@
#include "Defines.h"
+#include "FunctionRef.h"
@@ -194,7 +195,7 @@ public:
/** The interface used for enumerating and extern-calling plugins */
- typedef cItemCallback<cPlugin> cPluginCallback;
+ using cPluginCallback = cFunctionRef<bool(cPlugin &)>;
typedef std::list<cPlugin *> PluginList;
@@ -372,18 +373,18 @@ public:
/** Calls the specified callback with the plugin object of the specified plugin.
Returns false if plugin not found, otherwise returns the value that the callback has returned. */
- bool DoWithPlugin(const AString & a_PluginName, cPluginCallback & a_Callback);
+ bool DoWithPlugin(const AString & a_PluginName, cPluginCallback a_Callback);
/** Calls the specified callback for each plugin in m_Plugins.
Returns true if all plugins have been reported, false if the callback has aborted the enumeration by returning true. */
- bool ForEachPlugin(cPluginCallback & a_Callback);
+ bool ForEachPlugin(cPluginCallback a_Callback);
/** Returns the name of the folder (cPlugin::GetFolderName()) from which the specified plugin was loaded. */
AString GetPluginFolderName(const AString & a_PluginName); // tolua_export
/** Returns the path where individual plugins' folders are expected.
The path doesn't end in a slash. */
- static AString GetPluginsPath(void) { return FILE_IO_PREFIX + AString("Plugins"); } // tolua_export
+ static AString GetPluginsPath(void) { return FILE_IO_PREFIX "Plugins"; } // tolua_export
private:
friend class cRoot;