summaryrefslogtreecommitdiffstats
path: root/src/Bindings/ManualBindings.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Bindings/ManualBindings.h')
-rw-r--r--src/Bindings/ManualBindings.h117
1 files changed, 55 insertions, 62 deletions
diff --git a/src/Bindings/ManualBindings.h b/src/Bindings/ManualBindings.h
index f0b7cb607..233c438c3 100644
--- a/src/Bindings/ManualBindings.h
+++ b/src/Bindings/ManualBindings.h
@@ -25,11 +25,11 @@ class cPluginLua;
/** Provides namespace for the bindings. */
class cManualBindings
{
-public:
+ public:
/** Binds all the manually implemented functions to tolua_S. */
static void Bind(lua_State * tolua_S);
-protected:
+ protected:
/** Binds the manually implemented cNetwork-related API to tolua_S.
Implemented in ManualBindings_Network.cpp. */
static void BindNetwork(lua_State * tolua_S);
@@ -47,32 +47,24 @@ protected:
static void BindBlockArea(lua_State * tolua_S);
-public:
+ public:
// Helper functions:
static cPluginLua * GetLuaPlugin(lua_State * L);
static int tolua_do_error(lua_State * L, const char * a_pMsg, tolua_Error * a_pToLuaError);
static int vlua_do_error(lua_State * L, const char * a_pFormat, fmt::printf_args a_ArgList);
- template <typename... Args>
- static int lua_do_error(lua_State * L, const char * a_Format, const Args & ... a_Args)
+ template <typename... Args> static int lua_do_error(lua_State * L, const char * a_Format, const Args &... a_Args)
{
return vlua_do_error(L, a_Format, fmt::make_printf_args(a_Args...));
}
/** Binds the DoWith(ItemName) functions of regular classes. */
- template <
- class Ty1,
- class Ty2,
- bool (Ty1::*DoWithFn)(const AString &, cFunctionRef<bool(Ty2 &)>)
- >
+ template <class Ty1, class Ty2, bool (Ty1::*DoWithFn)(const AString &, cFunctionRef<bool(Ty2 &)>)>
static int DoWith(lua_State * tolua_S)
{
// Check params:
cLuaState L(tolua_S);
- if (
- !L.CheckParamString(2) ||
- !L.CheckParamFunction(3)
- )
+ if (!L.CheckParamString(2) || !L.CheckParamFunction(3))
{
return 0;
}
@@ -88,15 +80,23 @@ public:
}
if (ItemName.empty() || (ItemName[0] == 0))
{
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a non-empty string for parameter #1");
+ return lua_do_error(
+ tolua_S,
+ "Error in function call '#funcname#': Expected a non-empty string for parameter #1"
+ );
}
if (!FnRef.IsValid())
{
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a valid callback function for parameter #2");
+ return lua_do_error(
+ tolua_S,
+ "Error in function call '#funcname#': Expected a valid callback function for parameter #2"
+ );
}
// Call the DoWith function:
- bool res = (Self->*DoWithFn)(ItemName, [&](Ty2 & a_Item)
+ bool res = (Self->*DoWithFn)(
+ ItemName,
+ [&](Ty2 & a_Item)
{
bool ret = false;
L.Call(FnRef, &a_Item, cLuaState::Return, ret);
@@ -114,19 +114,12 @@ public:
/** Template for static functions DoWith(ItemName), on a type that has a static ::Get() function. */
- template <
- class Ty1,
- class Ty2,
- bool (Ty1::*DoWithFn)(const AString &, cFunctionRef<bool(Ty2 &)>)
- >
+ template <class Ty1, class Ty2, bool (Ty1::*DoWithFn)(const AString &, cFunctionRef<bool(Ty2 &)>)>
static int StaticDoWith(lua_State * tolua_S)
{
// Check params:
cLuaState L(tolua_S);
- if (
- !L.CheckParamString(2) ||
- !L.CheckParamFunction(3)
- )
+ if (!L.CheckParamString(2) || !L.CheckParamFunction(3))
{
return 0;
}
@@ -137,15 +130,23 @@ public:
L.GetStackValues(2, ItemName, FnRef);
if (ItemName.empty() || (ItemName[0] == 0))
{
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a non-empty string for parameter #1");
+ return lua_do_error(
+ tolua_S,
+ "Error in function call '#funcname#': Expected a non-empty string for parameter #1"
+ );
}
if (!FnRef.IsValid())
{
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a valid callback function for parameter #2");
+ return lua_do_error(
+ tolua_S,
+ "Error in function call '#funcname#': Expected a valid callback function for parameter #2"
+ );
}
// Call the DoWith function:
- bool res = (Ty1::Get()->*DoWithFn)(ItemName, [&](Ty2 & a_Item)
+ bool res = (Ty1::Get()->*DoWithFn)(
+ ItemName,
+ [&](Ty2 & a_Item)
{
bool ret = false;
L.Call(FnRef, &a_Item, cLuaState::Return, ret);
@@ -162,19 +163,12 @@ public:
- template <
- class Ty1,
- class Ty2,
- bool (Ty1::*DoWithFn)(UInt32, cFunctionRef<bool(Ty2 &)>)
- >
+ template <class Ty1, class Ty2, bool (Ty1::*DoWithFn)(UInt32, cFunctionRef<bool(Ty2 &)>)>
static int DoWithID(lua_State * tolua_S)
{
// Check params:
cLuaState L(tolua_S);
- if (
- !L.CheckParamNumber(2) ||
- !L.CheckParamFunction(3)
- )
+ if (!L.CheckParamNumber(2) || !L.CheckParamFunction(3))
{
return 0;
}
@@ -190,11 +184,16 @@ public:
}
if (!FnRef.IsValid())
{
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a valid callback function for parameter #2");
+ return lua_do_error(
+ tolua_S,
+ "Error in function call '#funcname#': Expected a valid callback function for parameter #2"
+ );
}
// Call the DoWith function:
- bool res = (Self->*DoWithFn)(ItemID, [&](Ty2 & a_Item)
+ bool res = (Self->*DoWithFn)(
+ ItemID,
+ [&](Ty2 & a_Item)
{
bool ret = false;
L.Call(FnRef, &a_Item, cLuaState::Return, ret);
@@ -211,19 +210,12 @@ public:
- template <
- class Ty1,
- class Ty2,
- bool (Ty1::*ForEachFn)(cFunctionRef<bool(Ty2 &)>)
- >
+ template <class Ty1, class Ty2, bool (Ty1::*ForEachFn)(cFunctionRef<bool(Ty2 &)>)>
static int ForEach(lua_State * tolua_S)
{
// Check params:
cLuaState L(tolua_S);
- if (
- !L.CheckParamFunction(2) ||
- !L.CheckParamEnd(3)
- )
+ if (!L.CheckParamFunction(2) || !L.CheckParamEnd(3))
{
return 0;
}
@@ -238,11 +230,15 @@ public:
}
if (!FnRef.IsValid())
{
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a valid callback function for parameter #1");
+ return lua_do_error(
+ tolua_S,
+ "Error in function call '#funcname#': Expected a valid callback function for parameter #1"
+ );
}
// Call the enumeration:
- bool res = (Self->*ForEachFn)([&](Ty2 & a_Item)
+ bool res = (Self->*ForEachFn)(
+ [&](Ty2 & a_Item)
{
bool ret = false; // By default continue the enumeration
L.Call(FnRef, &a_Item, cLuaState::Return, ret);
@@ -260,19 +256,12 @@ public:
/** Implements bindings for ForEach() functions in a class that is static (has a ::Get() static function). */
- template <
- class Ty1,
- class Ty2,
- bool (Ty1::*ForEachFn)(cFunctionRef<bool(Ty2 &)>)
- >
+ template <class Ty1, class Ty2, bool (Ty1::*ForEachFn)(cFunctionRef<bool(Ty2 &)>)>
static int StaticForEach(lua_State * tolua_S)
{
// Check params:
cLuaState L(tolua_S);
- if (
- !L.CheckParamFunction(2) ||
- !L.CheckParamEnd(3)
- )
+ if (!L.CheckParamFunction(2) || !L.CheckParamEnd(3))
{
return 0;
}
@@ -281,11 +270,15 @@ public:
cLuaState::cRef FnRef(L, 2);
if (!FnRef.IsValid())
{
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a valid callback function for parameter #1");
+ return lua_do_error(
+ tolua_S,
+ "Error in function call '#funcname#': Expected a valid callback function for parameter #1"
+ );
}
// Call the enumeration:
- bool res = (Ty1::Get()->*ForEachFn)([&](Ty2 & a_Item)
+ bool res = (Ty1::Get()->*ForEachFn)(
+ [&](Ty2 & a_Item)
{
bool ret = false; // By default continue the enumeration
L.Call(FnRef, &a_Item, cLuaState::Return, ret);