summaryrefslogtreecommitdiffstats
path: root/src/Bindings/ManualBindings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Bindings/ManualBindings.cpp')
-rw-r--r--src/Bindings/ManualBindings.cpp1663
1 files changed, 342 insertions, 1321 deletions
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 6e579b364..ff904d74a 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -5,6 +5,7 @@
#undef TOLUA_TEMPLATE_BIND
#include <sstream>
#include <iomanip>
+#include <array>
#include "tolua++/include/tolua++.h"
#include "polarssl/md5.h"
#include "polarssl/sha1.h"
@@ -32,13 +33,14 @@
#include "../WorldStorage/SchematicFileSerializer.h"
#include "../CompositeChat.h"
#include "../StringCompression.h"
+#include "../CommandOutput.h"
// Better error reporting for Lua
-static int tolua_do_error(lua_State* L, const char * a_pMsg, tolua_Error * a_pToLuaError)
+int cManualBindings::tolua_do_error(lua_State * L, const char * a_pMsg, tolua_Error * a_pToLuaError)
{
// Retrieve current function name
lua_Debug entry;
@@ -58,7 +60,7 @@ static int tolua_do_error(lua_State* L, const char * a_pMsg, tolua_Error * a_pTo
-static int lua_do_error(lua_State* L, const char * a_pFormat, ...)
+int cManualBindings::lua_do_error(lua_State * L, const char * a_pFormat, ...)
{
// Retrieve current function name
lua_Debug entry;
@@ -67,7 +69,7 @@ static int lua_do_error(lua_State* L, const char * a_pFormat, ...)
// Insert function name into error msg
AString msg(a_pFormat);
- ReplaceString(msg, "#funcname#", entry.name?entry.name:"?");
+ ReplaceString(msg, "#funcname#", (entry.name != nullptr) ? entry.name : "?");
// Copied from luaL_error and modified
va_list argp;
@@ -90,12 +92,12 @@ static int tolua_Clamp(lua_State * tolua_S)
int NumArgs = lua_gettop(LuaState);
if (NumArgs != 3)
{
- return lua_do_error(LuaState, "Error in function call '#funcname#': Requires 3 arguments, got %i", NumArgs);
+ return cManualBindings::lua_do_error(LuaState, "Error in function call '#funcname#': Requires 3 arguments, got %i", NumArgs);
}
if (!lua_isnumber(LuaState, 1) || !lua_isnumber(LuaState, 2) || !lua_isnumber(LuaState, 3))
{
- return lua_do_error(LuaState, "Error in function call '#funcname#': Expected a number for parameters #1, #2 and #3");
+ return cManualBindings::lua_do_error(LuaState, "Error in function call '#funcname#': Expected a number for parameters #1, #2 and #3");
}
lua_Number Number = tolua_tonumber(LuaState, 1, 0);
@@ -253,12 +255,13 @@ static int tolua_InflateString(lua_State * tolua_S)
static int tolua_StringSplit(lua_State * tolua_S)
{
+ // Get the params:
cLuaState LuaState(tolua_S);
- std::string str = (std::string)tolua_tocppstring(LuaState, 1, 0);
- std::string delim = (std::string)tolua_tocppstring(LuaState, 2, 0);
+ AString str, delim;
+ LuaState.GetStackValues(1, str, delim);
- AStringVector Split = StringSplit(str, delim);
- LuaState.Push(Split);
+ // Execute and push the result:
+ LuaState.Push(StringSplit(str, delim));
return 1;
}
@@ -286,12 +289,20 @@ static int tolua_StringSplitWithQuotes(lua_State * tolua_S)
static int tolua_StringSplitAndTrim(lua_State * tolua_S)
{
- cLuaState LuaState(tolua_S);
- std::string str = (std::string)tolua_tocppstring(LuaState, 1, 0);
- std::string delim = (std::string)tolua_tocppstring(LuaState, 2, 0);
+ // Check params:
+ cLuaState L(tolua_S);
+ if (
+ !L.CheckParamString(1, 2) ||
+ !L.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
- AStringVector Split = StringSplitAndTrim(str, delim);
- LuaState.Push(Split);
+ // Process:
+ AString str, delim;
+ L.GetStackValues(1, str, delim);
+ L.Push(StringSplitAndTrim(str, delim));
return 1;
}
@@ -450,7 +461,7 @@ static int tolua_Base64Decode(lua_State * tolua_S)
-cPluginLua * GetLuaPlugin(lua_State * L)
+cPluginLua * cManualBindings::GetLuaPlugin(lua_State * L)
{
// Get the plugin identification out of LuaState:
lua_getglobal(L, LUA_PLUGIN_INSTANCE_VAR_NAME);
@@ -472,6 +483,7 @@ cPluginLua * GetLuaPlugin(lua_State * L)
static int tolua_cFile_GetFolderContents(lua_State * tolua_S)
{
+ // Check params:
cLuaState LuaState(tolua_S);
if (
!LuaState.CheckParamUserTable(1, "cFile") ||
@@ -482,10 +494,12 @@ static int tolua_cFile_GetFolderContents(lua_State * tolua_S)
return 0;
}
- AString Folder = (AString)tolua_tocppstring(LuaState, 2, 0);
+ // Get params:
+ AString Folder;
+ LuaState.GetStackValues(2, Folder);
- AStringVector Contents = cFile::GetFolderContents(Folder);
- LuaState.Push(Contents);
+ // Execute and push result:
+ LuaState.Push(cFile::GetFolderContents(Folder));
return 1;
}
@@ -493,447 +507,25 @@ static int tolua_cFile_GetFolderContents(lua_State * tolua_S)
-template <
- class Ty1,
- class Ty2,
- bool (Ty1::*Func1)(const AString &, cItemCallback<Ty2> &)
->
-static int tolua_DoWith(lua_State* tolua_S)
-{
- int NumArgs = lua_gettop(tolua_S) - 1; /* This includes 'self' */
- if ((NumArgs != 2) && (NumArgs != 3))
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 2 or 3 arguments, got %i", NumArgs);
- }
-
- Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, nullptr);
-
- const char * ItemName = tolua_tocppstring(tolua_S, 2, "");
- if ((ItemName == nullptr) || (ItemName[0] == 0))
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a non-empty string for parameter #1", NumArgs);
- }
- if (!lua_isfunction( tolua_S, 3))
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a function for parameter #2", NumArgs);
- }
-
- /* luaL_ref gets reference to value on top of the stack, the table is the last argument and therefore on the top */
- int TableRef = LUA_REFNIL;
- if (NumArgs == 3)
- {
- TableRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
- if (TableRef == LUA_REFNIL)
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get value reference of parameter #3", NumArgs);
- }
- }
-
- /* table value is popped, and now function is on top of the stack */
- int FuncRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
- if (FuncRef == LUA_REFNIL)
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get function reference of parameter #2", NumArgs);
- }
-
- class cLuaCallback : public cItemCallback<Ty2>
- {
- public:
- cLuaCallback(lua_State* a_LuaState, int a_FuncRef, int a_TableRef)
- : LuaState( a_LuaState)
- , FuncRef( a_FuncRef)
- , TableRef( a_TableRef)
- {}
-
- private:
- virtual bool Item(Ty2 * a_Item) override
- {
- lua_rawgeti( LuaState, LUA_REGISTRYINDEX, FuncRef); /* Push function reference */
- tolua_pushusertype(LuaState, a_Item, Ty2::GetClassStatic());
- if (TableRef != LUA_REFNIL)
- {
- lua_rawgeti( LuaState, LUA_REGISTRYINDEX, TableRef); /* Push table reference */
- }
-
- int s = lua_pcall(LuaState, (TableRef == LUA_REFNIL ? 1 : 2), 1, 0);
- if (cLuaState::ReportErrors(LuaState, s))
- {
- return true; // Abort enumeration
- }
- if (lua_isboolean(LuaState, -1))
- {
- return (tolua_toboolean(LuaState, -1, 0) > 0);
- }
- return false; /* Continue enumeration */
- }
- lua_State * LuaState;
- int FuncRef;
- int TableRef;
- } Callback(tolua_S, FuncRef, TableRef);
-
-
- bool bRetVal = (self->*Func1)(ItemName, Callback);
-
- /* Unreference the values again, so the LUA_REGISTRYINDEX can make place for other references */
- luaL_unref(tolua_S, LUA_REGISTRYINDEX, TableRef);
- luaL_unref(tolua_S, LUA_REGISTRYINDEX, FuncRef);
-
- /* Push return value on stack */
- tolua_pushboolean(tolua_S, bRetVal);
- return 1;
-}
-
-
-
-
-
-template <
- class Ty1,
- class Ty2,
- bool (Ty1::*Func1)(UInt32, cItemCallback<Ty2> &)
->
-static int tolua_DoWithID(lua_State* tolua_S)
-{
- int NumArgs = lua_gettop(tolua_S) - 1; /* This includes 'self' */
- if ((NumArgs != 2) && (NumArgs != 3))
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 2 or 3 arguments, got %i", NumArgs);
- }
-
- Ty1 * self = (Ty1 *)tolua_tousertype(tolua_S, 1, nullptr);
-
- int ItemID = (int)tolua_tonumber(tolua_S, 2, 0);
- if (!lua_isfunction(tolua_S, 3))
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a function for parameter #2", NumArgs);
- }
-
- /* luaL_ref gets reference to value on top of the stack, the table is the last argument and therefore on the top */
- int TableRef = LUA_REFNIL;
- if (NumArgs == 3)
- {
- TableRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
- if (TableRef == LUA_REFNIL)
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get value reference of parameter #3", NumArgs);
- }
- }
-
- /* table value is popped, and now function is on top of the stack */
- int FuncRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
- if (FuncRef == LUA_REFNIL)
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get function reference of parameter #2", NumArgs);
- }
-
- class cLuaCallback : public cItemCallback<Ty2>
- {
- public:
- cLuaCallback(lua_State * a_LuaState, int a_FuncRef, int a_TableRef) :
- LuaState(a_LuaState),
- FuncRef(a_FuncRef),
- TableRef(a_TableRef)
- {}
-
- private:
- virtual bool Item(Ty2 * a_Item) override
- {
- lua_rawgeti(LuaState, LUA_REGISTRYINDEX, FuncRef); // Push function to call
- tolua_pushusertype(LuaState, a_Item, a_Item->GetClass()); // Push the item
- if (TableRef != LUA_REFNIL)
- {
- lua_rawgeti(LuaState, LUA_REGISTRYINDEX, TableRef); // Push the optional callbackdata param
- }
-
- int s = lua_pcall(LuaState, (TableRef == LUA_REFNIL ? 1 : 2), 1, 0);
- if (cLuaState::ReportErrors(LuaState, s))
- {
- return true; // Abort enumeration
- }
- if (lua_isboolean(LuaState, -1))
- {
- return (tolua_toboolean(LuaState, -1, 0) > 0);
- }
- return false; /* Continue enumeration */
- }
- lua_State * LuaState;
- int FuncRef;
- int TableRef;
- } Callback(tolua_S, FuncRef, TableRef);
-
-
- bool bRetVal = (self->*Func1)(ItemID, Callback);
-
- /* Unreference the values again, so the LUA_REGISTRYINDEX can make place for other references */
- luaL_unref(tolua_S, LUA_REGISTRYINDEX, TableRef);
- luaL_unref(tolua_S, LUA_REGISTRYINDEX, FuncRef);
-
- /* Push return value on stack */
- tolua_pushboolean(tolua_S, bRetVal);
- return 1;
-}
-
-
-
-
-
-template <
- class Ty1,
- class Ty2,
- bool (Ty1::*Func1)(int, int, int, cItemCallback<Ty2> &)
->
-static int tolua_DoWithXYZ(lua_State* tolua_S)
-{
- int NumArgs = lua_gettop(tolua_S) - 1; /* This includes 'self' */
- if ((NumArgs != 4) && (NumArgs != 5))
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 4 or 5 arguments, got %i", NumArgs);
- }
-
- Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, nullptr);
- if (!lua_isnumber(tolua_S, 2) || !lua_isnumber(tolua_S, 3) || !lua_isnumber(tolua_S, 4))
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a number for parameters #1, #2 and #3");
- }
-
- int ItemX = ((int)tolua_tonumber(tolua_S, 2, 0));
- int ItemY = ((int)tolua_tonumber(tolua_S, 3, 0));
- int ItemZ = ((int)tolua_tonumber(tolua_S, 4, 0));
- if (!lua_isfunction( tolua_S, 5))
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a function for parameter #4");
- }
-
- /* luaL_ref gets reference to value on top of the stack, the table is the last argument and therefore on the top */
- int TableRef = LUA_REFNIL;
- if (NumArgs == 5)
- {
- TableRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
- if (TableRef == LUA_REFNIL)
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get value reference of parameter #5");
- }
- }
-
- /* table value is popped, and now function is on top of the stack */
- int FuncRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
- if (FuncRef == LUA_REFNIL)
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get function reference of parameter #4");
- }
-
- class cLuaCallback : public cItemCallback<Ty2>
- {
- public:
- cLuaCallback(lua_State* a_LuaState, int a_FuncRef, int a_TableRef)
- : LuaState( a_LuaState)
- , FuncRef( a_FuncRef)
- , TableRef( a_TableRef)
- {}
-
- private:
- virtual bool Item(Ty2 * a_Item) override
- {
- lua_rawgeti( LuaState, LUA_REGISTRYINDEX, FuncRef); /* Push function reference */
- tolua_pushusertype(LuaState, a_Item, Ty2::GetClassStatic());
- if (TableRef != LUA_REFNIL)
- {
- lua_rawgeti( LuaState, LUA_REGISTRYINDEX, TableRef); /* Push table reference */
- }
-
- int s = lua_pcall(LuaState, (TableRef == LUA_REFNIL ? 1 : 2), 1, 0);
- if (cLuaState::ReportErrors(LuaState, s))
- {
- return true; // Abort enumeration
- }
- if (lua_isboolean(LuaState, -1))
- {
- return (tolua_toboolean(LuaState, -1, 0) > 0);
- }
- return false; /* Continue enumeration */
- }
- lua_State * LuaState;
- int FuncRef;
- int TableRef;
- } Callback(tolua_S, FuncRef, TableRef);
-
- bool bRetVal = (self->*Func1)(ItemX, ItemY, ItemZ, Callback);
-
- /* Unreference the values again, so the LUA_REGISTRYINDEX can make place for other references */
- luaL_unref(tolua_S, LUA_REGISTRYINDEX, TableRef);
- luaL_unref(tolua_S, LUA_REGISTRYINDEX, FuncRef);
-
- /* Push return value on stack */
- tolua_pushboolean(tolua_S, bRetVal);
- return 1;
-}
-
-
-
-
-
-template <
- class Ty1,
- class Ty2,
- bool (Ty1::*Func1)(int, int, cItemCallback<Ty2> &)
->
-static int tolua_ForEachInChunk(lua_State * tolua_S)
-{
- int NumArgs = lua_gettop(tolua_S) - 1; /* This includes 'self' */
- if ((NumArgs != 3) && (NumArgs != 4))
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 3 or 4 arguments, got %i", NumArgs);
- }
-
- Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, nullptr);
- if (!lua_isnumber(tolua_S, 2) || !lua_isnumber(tolua_S, 3))
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a number for parameters #1 and #2");
- }
-
- int ChunkX = ((int)tolua_tonumber(tolua_S, 2, 0));
- int ChunkZ = ((int)tolua_tonumber(tolua_S, 3, 0));
-
- if (!lua_isfunction( tolua_S, 4))
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a function for parameter #3");
- }
-
- /* luaL_ref gets reference to value on top of the stack, the table is the last argument and therefore on the top */
- int TableRef = LUA_REFNIL;
- if (NumArgs == 4)
- {
- TableRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
- if (TableRef == LUA_REFNIL)
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get value reference of parameter #4");
- }
- }
-
- /* table value is popped, and now function is on top of the stack */
- int FuncRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
- if (FuncRef == LUA_REFNIL)
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get function reference of parameter #3");
- }
-
- class cLuaCallback : public cItemCallback<Ty2>
- {
- public:
- cLuaCallback(lua_State* a_LuaState, int a_FuncRef, int a_TableRef)
- : LuaState( a_LuaState)
- , FuncRef( a_FuncRef)
- , TableRef( a_TableRef)
- {}
-
- private:
- virtual bool Item(Ty2 * a_Item) override
- {
- lua_rawgeti( LuaState, LUA_REGISTRYINDEX, FuncRef); /* Push function reference */
- tolua_pushusertype(LuaState, a_Item, Ty2::GetClassStatic());
- if (TableRef != LUA_REFNIL)
- {
- lua_rawgeti( LuaState, LUA_REGISTRYINDEX, TableRef); /* Push table reference */
- }
-
- int s = lua_pcall(LuaState, (TableRef == LUA_REFNIL ? 1 : 2), 1, 0);
- if (cLuaState::ReportErrors(LuaState, s))
- {
- return true; /* Abort enumeration */
- }
-
- if (lua_isboolean(LuaState, -1))
- {
- return (tolua_toboolean(LuaState, -1, 0) > 0);
- }
- return false; /* Continue enumeration */
- }
- lua_State * LuaState;
- int FuncRef;
- int TableRef;
- } Callback(tolua_S, FuncRef, TableRef);
-
- bool bRetVal = (self->*Func1)(ChunkX, ChunkZ, Callback);
-
- /* Unreference the values again, so the LUA_REGISTRYINDEX can make place for other references */
- luaL_unref(tolua_S, LUA_REGISTRYINDEX, TableRef);
- luaL_unref(tolua_S, LUA_REGISTRYINDEX, FuncRef);
-
- /* Push return value on stack */
- tolua_pushboolean(tolua_S, bRetVal);
- return 1;
-}
-
-
-
-
-
-template <
- class Ty1,
- class Ty2,
- bool (Ty1::*Func1)(const cBoundingBox &, cItemCallback<Ty2> &)
->
-static int tolua_ForEachInBox(lua_State * tolua_S)
+static int tolua_cFile_ReadWholeFile(lua_State * tolua_S)
{
// Check params:
- cLuaState L(tolua_S);
+ cLuaState LuaState(tolua_S);
if (
- !L.CheckParamUserType(1, "cWorld") ||
- !L.CheckParamUserType(2, "cBoundingBox") ||
- !L.CheckParamFunction(3) ||
- !L.CheckParamEnd(4)
+ !LuaState.CheckParamUserTable(1, "cFile") ||
+ !LuaState.CheckParamString (2) ||
+ !LuaState.CheckParamEnd (3)
)
{
return 0;
}
-
- // Get the params:
- Ty1 * Self = nullptr;
- cBoundingBox * Box = nullptr;
- L.GetStackValues(1, Self, Box);
- if ((Self == nullptr) || (Box == nullptr))
- {
- LOGWARNING("Invalid world (%p) or boundingbox (%p)", Self, Box);
- L.LogStackTrace();
- return 0;
- }
- // Create a reference for the function:
- cLuaState::cRef FnRef(L, 3);
+ // Get params:
+ AString FileName;
+ LuaState.GetStackValues(2, FileName);
- // 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)
- {}
-
- private:
- // cItemCallback<Ty2> overrides:
- virtual bool Item(Ty2 * a_Item) override
- {
- bool res = false;
- if (!m_LuaState.Call(m_FnRef, a_Item, cLuaState::Return, res))
- {
- LOGWARNING("Failed to call Lua callback");
- m_LuaState.LogStackTrace();
- return true; // Abort enumeration
- }
-
- return res;
- }
- cLuaState & m_LuaState;
- cLuaState::cRef & m_FnRef;
- } Callback(L, FnRef);
-
- bool bRetVal = (Self->*Func1)(*Box, Callback);
-
- FnRef.UnRef();
-
- /* Push return value on stack */
- tolua_pushboolean(tolua_S, bRetVal);
+ // Execute and push result:
+ LuaState.Push(cFile::ReadWholeFile(FileName));
return 1;
}
@@ -941,535 +533,30 @@ static int tolua_ForEachInBox(lua_State * tolua_S)
-template <
- class Ty1,
- class Ty2,
- bool (Ty1::*Func1)(cItemCallback<Ty2> &)
->
-static int tolua_ForEach(lua_State * tolua_S)
-{
- int NumArgs = lua_gettop(tolua_S) - 1; /* This includes 'self' */
- if ((NumArgs != 1) && (NumArgs != 2))
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 1 or 2 arguments, got %i", NumArgs);
- }
-
- Ty1 * self = (Ty1 *)tolua_tousertype(tolua_S, 1, nullptr);
- if (self == nullptr)
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Not called on an object instance");
- }
-
- if (!lua_isfunction( tolua_S, 2))
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a function for parameter #1");
- }
-
- /* luaL_ref gets reference to value on top of the stack, the table is the last argument and therefore on the top */
- int TableRef = LUA_REFNIL;
- if (NumArgs == 2)
- {
- TableRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
- if (TableRef == LUA_REFNIL)
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get value reference of parameter #2");
- }
- }
-
- /* table value is popped, and now function is on top of the stack */
- int FuncRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
- if (FuncRef == LUA_REFNIL)
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get function reference of parameter #1");
- }
-
- class cLuaCallback : public cItemCallback<Ty2>
- {
- public:
- cLuaCallback(lua_State* a_LuaState, int a_FuncRef, int a_TableRef)
- : LuaState( a_LuaState)
- , FuncRef( a_FuncRef)
- , TableRef( a_TableRef)
- {}
-
- private:
- virtual bool Item(Ty2 * a_Item) override
- {
- lua_rawgeti( LuaState, LUA_REGISTRYINDEX, FuncRef); /* Push function reference */
- tolua_pushusertype( LuaState, a_Item, Ty2::GetClassStatic());
- if (TableRef != LUA_REFNIL)
- {
- lua_rawgeti( LuaState, LUA_REGISTRYINDEX, TableRef); /* Push table reference */
- }
-
- int s = lua_pcall(LuaState, (TableRef == LUA_REFNIL ? 1 : 2), 1, 0);
- if (cLuaState::ReportErrors(LuaState, s))
- {
- return true; /* Abort enumeration */
- }
-
- if (lua_isboolean(LuaState, -1))
- {
- return (tolua_toboolean( LuaState, -1, 0) > 0);
- }
- return false; /* Continue enumeration */
- }
- lua_State * LuaState;
- int FuncRef;
- int TableRef;
- } Callback(tolua_S, FuncRef, TableRef);
-
- bool bRetVal = (self->*Func1)(Callback);
-
- /* Unreference the values again, so the LUA_REGISTRYINDEX can make place for other references */
- luaL_unref(tolua_S, LUA_REGISTRYINDEX, TableRef);
- luaL_unref(tolua_S, LUA_REGISTRYINDEX, FuncRef);
-
- /* Push return value on stack */
- tolua_pushboolean(tolua_S, bRetVal);
- return 1;
-}
-
-
-
-
-
-static int tolua_cWorld_GetBlockInfo(lua_State * tolua_S)
-{
- // Exported manually, because tolua would generate useless additional parameters (a_BlockType .. a_BlockSkyLight)
- // Function signature: GetBlockInfo(BlockX, BlockY, BlockZ) -> BlockValid, [BlockType, BlockMeta, BlockSkyLight, BlockBlockLight]
- #ifndef TOLUA_RELEASE
- tolua_Error tolua_err;
- if (
- !tolua_isusertype (tolua_S, 1, "cWorld", 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 2, 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 3, 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 4, 0, &tolua_err) ||
- !tolua_isnoobj (tolua_S, 5, &tolua_err)
- )
- goto tolua_lerror;
- else
- #endif
- {
- cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, nullptr);
- int BlockX = (int) tolua_tonumber (tolua_S, 2, 0);
- int BlockY = (int) tolua_tonumber (tolua_S, 3, 0);
- int BlockZ = (int) tolua_tonumber (tolua_S, 4, 0);
- #ifndef TOLUA_RELEASE
- if (self == nullptr)
- {
- tolua_error(tolua_S, "invalid 'self' in function 'GetBlockInfo'", nullptr);
- }
- #endif
- {
- BLOCKTYPE BlockType;
- NIBBLETYPE BlockMeta, BlockSkyLight, BlockBlockLight;
- bool res = self->GetBlockInfo(BlockX, BlockY, BlockZ, BlockType, BlockMeta, BlockSkyLight, BlockBlockLight);
- tolua_pushboolean(tolua_S, res ? 1 : 0);
- if (res)
- {
- tolua_pushnumber(tolua_S, BlockType);
- tolua_pushnumber(tolua_S, BlockMeta);
- tolua_pushnumber(tolua_S, BlockSkyLight);
- tolua_pushnumber(tolua_S, BlockBlockLight);
- return 5;
- }
- }
- }
- return 1;
-
- #ifndef TOLUA_RELEASE
-tolua_lerror:
- tolua_error(tolua_S, "#ferror in function 'GetBlockInfo'.", &tolua_err);
- return 0;
- #endif
-}
-
-
-
-
-
-static int tolua_cWorld_GetBlockTypeMeta(lua_State * tolua_S)
-{
- // Exported manually, because tolua would generate useless additional parameters (a_BlockType, a_BlockMeta)
- // Function signature: GetBlockTypeMeta(BlockX, BlockY, BlockZ) -> BlockValid, [BlockType, BlockMeta]
- #ifndef TOLUA_RELEASE
- tolua_Error tolua_err;
- if (
- !tolua_isusertype (tolua_S, 1, "cWorld", 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 2, 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 3, 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 4, 0, &tolua_err) ||
- !tolua_isnoobj (tolua_S, 5, &tolua_err)
- )
- goto tolua_lerror;
- else
- #endif
- {
- cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, nullptr);
- int BlockX = (int) tolua_tonumber (tolua_S, 2, 0);
- int BlockY = (int) tolua_tonumber (tolua_S, 3, 0);
- int BlockZ = (int) tolua_tonumber (tolua_S, 4, 0);
- #ifndef TOLUA_RELEASE
- if (self == nullptr)
- {
- tolua_error(tolua_S, "invalid 'self' in function 'GetBlockTypeMeta'", nullptr);
- }
- #endif
- {
- BLOCKTYPE BlockType;
- NIBBLETYPE BlockMeta;
- bool res = self->GetBlockTypeMeta(BlockX, BlockY, BlockZ, BlockType, BlockMeta);
- tolua_pushboolean(tolua_S, res ? 1 : 0);
- if (res)
- {
- tolua_pushnumber(tolua_S, BlockType);
- tolua_pushnumber(tolua_S, BlockMeta);
- return 3;
- }
- }
- }
- return 1;
-
- #ifndef TOLUA_RELEASE
-tolua_lerror:
- tolua_error(tolua_S, "#ferror in function 'GetBlockTypeMeta'.", &tolua_err);
- return 0;
- #endif
-}
-
-
-
-
-
-static int tolua_cWorld_GetSignLines(lua_State * tolua_S)
-{
- // Exported manually, because tolua would generate useless additional parameters (a_Line1 .. a_Line4)
- #ifndef TOLUA_RELEASE
- tolua_Error tolua_err;
- if (
- !tolua_isusertype (tolua_S, 1, "cWorld", 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 2, 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 3, 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 4, 0, &tolua_err) ||
- !tolua_isnoobj (tolua_S, 10, &tolua_err)
- )
- goto tolua_lerror;
- else
- #endif
- {
- cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, nullptr);
- int BlockX = (int) tolua_tonumber (tolua_S, 2, 0);
- int BlockY = (int) tolua_tonumber (tolua_S, 3, 0);
- int BlockZ = (int) tolua_tonumber (tolua_S, 4, 0);
- #ifndef TOLUA_RELEASE
- if (self == nullptr)
- {
- tolua_error(tolua_S, "invalid 'self' in function 'GetSignLines'", nullptr);
- }
- #endif
- {
- AString Line1, Line2, Line3, Line4;
- bool res = self->GetSignLines(BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4);
- tolua_pushboolean(tolua_S, res ? 1 : 0);
- if (res)
- {
- tolua_pushstring(tolua_S, Line1.c_str());
- tolua_pushstring(tolua_S, Line2.c_str());
- tolua_pushstring(tolua_S, Line3.c_str());
- tolua_pushstring(tolua_S, Line4.c_str());
- return 5;
- }
- }
- }
- return 1;
-
- #ifndef TOLUA_RELEASE
-tolua_lerror:
- tolua_error(tolua_S, "#ferror in function 'GetSignLines'.", &tolua_err);
- return 0;
- #endif
-}
-
-
-
-
-
-static int tolua_cWorld_SetSignLines(lua_State * tolua_S)
+static int tolua_cPluginManager_GetAllPlugins(lua_State * tolua_S)
{
- // Exported manually, because tolua would generate useless additional return values (a_Line1 .. a_Line4)
- #ifndef TOLUA_RELEASE
- tolua_Error tolua_err;
- if (
- !tolua_isusertype (tolua_S, 1, "cWorld", 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 2, 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 3, 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 4, 0, &tolua_err) ||
- !tolua_iscppstring(tolua_S, 5, 0, &tolua_err) ||
- !tolua_iscppstring(tolua_S, 6, 0, &tolua_err) ||
- !tolua_iscppstring(tolua_S, 7, 0, &tolua_err) ||
- !tolua_iscppstring(tolua_S, 8, 0, &tolua_err) ||
- !tolua_isusertype (tolua_S, 9, "cPlayer", 1, &tolua_err) ||
- !tolua_isnoobj (tolua_S, 10, &tolua_err)
- )
- goto tolua_lerror;
- else
- #endif
- {
- cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, nullptr);
- int BlockX = (int) tolua_tonumber (tolua_S, 2, 0);
- int BlockY = (int) tolua_tonumber (tolua_S, 3, 0);
- int BlockZ = (int) tolua_tonumber (tolua_S, 4, 0);
- const AString Line1 = tolua_tocppstring(tolua_S, 5, 0);
- const AString Line2 = tolua_tocppstring(tolua_S, 6, 0);
- const AString Line3 = tolua_tocppstring(tolua_S, 7, 0);
- const AString Line4 = tolua_tocppstring(tolua_S, 8, 0);
- cPlayer * Player = (cPlayer *)tolua_tousertype (tolua_S, 9, nullptr);
- #ifndef TOLUA_RELEASE
- if (self == nullptr)
- {
- tolua_error(tolua_S, "invalid 'self' in function 'SetSignLines'", nullptr);
- }
- #endif
- {
- bool res = self->SetSignLines(BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4, Player);
- tolua_pushboolean(tolua_S, res ? 1 : 0);
- }
- }
- return 1;
-
- #ifndef TOLUA_RELEASE
-tolua_lerror:
- tolua_error(tolua_S, "#ferror in function 'SetSignLines'.", &tolua_err);
- return 0;
- #endif
-}
-
-
-
+ // API function no longer available:
+ LOGWARNING("cPluginManager:GetAllPlugins() is no longer available, use cPluginManager:ForEachPlugin() instead");
+ cLuaState::LogStackTrace(tolua_S);
-static int tolua_cWorld_TryGetHeight(lua_State * tolua_S)
-{
- // Exported manually, because tolua would require the out-only param a_Height to be used when calling
- // Takes a_World, a_BlockX, a_BlockZ
- // Returns Height, IsValid
- #ifndef TOLUA_RELEASE
- tolua_Error tolua_err;
- if (
- !tolua_isusertype (tolua_S, 1, "cWorld", 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 2, 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 3, 0, &tolua_err) ||
- !tolua_isnoobj (tolua_S, 4, &tolua_err)
- )
- goto tolua_lerror;
- else
- #endif
- {
- cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, nullptr);
- int BlockX = (int) tolua_tonumber (tolua_S, 2, 0);
- int BlockZ = (int) tolua_tonumber (tolua_S, 3, 0);
- #ifndef TOLUA_RELEASE
- if (self == nullptr)
- {
- tolua_error(tolua_S, "Invalid 'self' in function 'TryGetHeight'", nullptr);
- }
- #endif
- {
- int Height = 0;
- bool res = self->TryGetHeight(BlockX, BlockZ, Height);
- tolua_pushboolean(tolua_S, res ? 1 : 0);
- if (res)
- {
- tolua_pushnumber(tolua_S, Height);
- return 2;
- }
- }
- }
+ // Return an empty table:
+ lua_newtable(tolua_S);
return 1;
-
- #ifndef TOLUA_RELEASE
-tolua_lerror:
- tolua_error(tolua_S, "#ferror in function 'TryGetHeight'.", &tolua_err);
- return 0;
- #endif
}
-class cLuaWorldTask :
- public cWorld::cTask,
- public cPluginLua::cResettable
-{
-public:
- cLuaWorldTask(cPluginLua & a_Plugin, int a_FnRef) :
- cPluginLua::cResettable(a_Plugin),
- m_FnRef(a_FnRef)
- {
- }
-
-protected:
- int m_FnRef;
-
- // cWorld::cTask overrides:
- virtual void Run(cWorld & a_World) override
- {
- cCSLock Lock(m_CSPlugin);
- if (m_Plugin != nullptr)
- {
- m_Plugin->Call(m_FnRef, &a_World);
- }
- }
-} ;
-
-
-
-
-
-static int tolua_cWorld_QueueTask(lua_State * tolua_S)
-{
- // Binding for cWorld::QueueTask
- // Params: function
-
- // Retrieve the cPlugin from the LuaState:
- cPluginLua * Plugin = GetLuaPlugin(tolua_S);
- if (Plugin == nullptr)
- {
- // An error message has been already printed in GetLuaPlugin()
- return 0;
- }
-
- // Retrieve the args:
- cWorld * self = (cWorld *)tolua_tousertype(tolua_S, 1, nullptr);
- if (self == nullptr)
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Not called on an object instance");
- }
- if (!lua_isfunction(tolua_S, 2))
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a function for parameter #1");
- }
-
- // Create a reference to the function:
- int FnRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
- if (FnRef == LUA_REFNIL)
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get function reference of parameter #1");
- }
-
- auto task = std::make_shared<cLuaWorldTask>(*Plugin, FnRef);
- Plugin->AddResettable(task);
- self->QueueTask(task);
- return 0;
-}
-
-
-
-
-
-class cLuaScheduledWorldTask :
- public cWorld::cTask,
- public cPluginLua::cResettable
-{
-public:
- cLuaScheduledWorldTask(cPluginLua & a_Plugin, int a_FnRef) :
- cPluginLua::cResettable(a_Plugin),
- m_FnRef(a_FnRef)
- {
- }
-
-protected:
- int m_FnRef;
-
- // cWorld::cTask overrides:
- virtual void Run(cWorld & a_World) override
- {
- cCSLock Lock(m_CSPlugin);
- if (m_Plugin != nullptr)
- {
- m_Plugin->Call(m_FnRef, &a_World);
- }
- }
-};
-
-
-
-
-
-static int tolua_cWorld_ScheduleTask(lua_State * tolua_S)
+static int tolua_cPluginManager_GetCurrentPlugin(lua_State * S)
{
- // Binding for cWorld::ScheduleTask
- // Params: function, Ticks
-
- // Retrieve the cPlugin from the LuaState:
- cPluginLua * Plugin = GetLuaPlugin(tolua_S);
+ cPluginLua * Plugin = cManualBindings::GetLuaPlugin(S);
if (Plugin == nullptr)
{
- // An error message has been already printed in GetLuaPlugin()
- return 0;
- }
-
- // Retrieve the args:
- cLuaState L(tolua_S);
- if (
- !L.CheckParamUserType(1, "cWorld") ||
- !L.CheckParamNumber (2) ||
- !L.CheckParamFunction(3)
- )
- {
+ // An error message has already been printed in GetLuaPlugin()
return 0;
}
- cWorld * World = (cWorld *)tolua_tousertype(tolua_S, 1, nullptr);
- if (World == nullptr)
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Not called on an object instance");
- }
-
- // Create a reference to the function:
- int FnRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
- if (FnRef == LUA_REFNIL)
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get function reference of parameter #1");
- }
-
- int DelayTicks = (int)tolua_tonumber(tolua_S, 2, 0);
-
- auto task = std::make_shared<cLuaScheduledWorldTask>(*Plugin, FnRef);
- Plugin->AddResettable(task);
- World->ScheduleTask(DelayTicks, task);
- return 0;
-}
-
-
-
-
-
-static int tolua_cPluginManager_GetAllPlugins(lua_State * tolua_S)
-{
- cPluginManager * self = (cPluginManager *)tolua_tousertype(tolua_S, 1, nullptr);
-
- const cPluginManager::PluginMap & AllPlugins = self->GetAllPlugins();
-
- lua_newtable(tolua_S);
- int index = 1;
- cPluginManager::PluginMap::const_iterator iter = AllPlugins.begin();
- while (iter != AllPlugins.end())
- {
- const cPlugin* Plugin = iter->second;
- tolua_pushstring(tolua_S, iter->first.c_str());
- if (Plugin != nullptr)
- {
- tolua_pushusertype(tolua_S, (void *)Plugin, "const cPlugin");
- }
- else
- {
- tolua_pushboolean(tolua_S, 0);
- }
- lua_rawset(tolua_S, -3);
- ++iter;
- ++index;
- }
+ tolua_pushusertype(S, Plugin, "cPluginLua");
return 1;
}
@@ -1477,16 +564,12 @@ static int tolua_cPluginManager_GetAllPlugins(lua_State * tolua_S)
-static int tolua_cPluginManager_GetCurrentPlugin(lua_State * S)
+static int tolua_cPluginManager_GetPlugin(lua_State * tolua_S)
{
- cPluginLua * Plugin = GetLuaPlugin(S);
- if (Plugin == nullptr)
- {
- // An error message has already been printed in GetLuaPlugin()
- return 0;
- }
- tolua_pushusertype(S, Plugin, "cPluginLua");
- return 1;
+ // API function no longer available:
+ LOGWARNING("cPluginManager:GetPlugin() is no longer available. Use cPluginManager:DoWithPlugin() or cPluginManager:CallPlugin() instead.");
+ cLuaState::LogStackTrace(tolua_S);
+ return 0;
}
@@ -1510,7 +593,7 @@ static int tolua_cPluginManager_AddHook_FnRef(cPluginManager * a_PluginManager,
// The arg types have already been checked
// Retrieve the cPlugin from the LuaState:
- cPluginLua * Plugin = GetLuaPlugin(S);
+ cPluginLua * Plugin = cManualBindings::GetLuaPlugin(S);
if (Plugin == nullptr)
{
// An error message has been already printed in GetLuaPlugin()
@@ -1557,7 +640,7 @@ static int tolua_cPluginManager_AddHook_DefFn(cPluginManager * a_PluginManager,
S.LogStackTrace();
return 0;
}
- if (Plugin != GetLuaPlugin(S))
+ if (Plugin != cManualBindings::GetLuaPlugin(S))
{
// The plugin parameter passed to us is not our stored plugin. Disallow this!
LOGWARNING("cPluginManager.AddHook(): Invalid Plugin parameter, cannot add hook to foreign plugins. Hook not added.");
@@ -1664,74 +747,55 @@ static int tolua_cPluginManager_AddHook(lua_State * tolua_S)
static int tolua_cPluginManager_ForEachCommand(lua_State * tolua_S)
{
- int NumArgs = lua_gettop(tolua_S) - 1; /* This includes 'self' */
- if (NumArgs != 1)
- {
- LOGWARN("Error in function call 'ForEachCommand': Requires 1 argument, got %i", NumArgs);
- return 0;
- }
-
- cPluginManager * self = (cPluginManager *)tolua_tousertype(tolua_S, 1, nullptr);
- if (self == nullptr)
- {
- LOGWARN("Error in function call 'ForEachCommand': Not called on an object instance");
- return 0;
- }
+ /*
+ Function signature:
+ cPluginManager:Get():ForEachCommand(a_CallbackFn) -> bool
+ */
- if (!lua_isfunction(tolua_S, 2))
+ // Check params:
+ cLuaState L(tolua_S);
+ if (
+ !L.CheckParamUserType(1, "cPluginManager") ||
+ !L.CheckParamFunction(2) ||
+ !L.CheckParamEnd(3)
+ )
{
- LOGWARN("Error in function call 'ForEachCommand': Expected a function for parameter #1");
return 0;
}
- int FuncRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
- if (FuncRef == LUA_REFNIL)
+ // Get the params:
+ cLuaState::cRef FnRef;
+ L.GetStackValues(2, FnRef);
+ if (!FnRef.IsValid())
{
LOGWARN("Error in function call 'ForEachCommand': Could not get function reference of parameter #1");
return 0;
}
+ // Callback for enumerating all commands:
class cLuaCallback : public cPluginManager::cCommandEnumCallback
{
public:
- cLuaCallback(lua_State * a_LuaState, int a_FuncRef)
- : LuaState( a_LuaState)
- , FuncRef( a_FuncRef)
- {}
+ cLuaCallback(cLuaState & a_LuaState, cLuaState::cRef & a_FnRef):
+ m_LuaState(a_LuaState),
+ m_FnRef(a_FnRef)
+ {
+ }
private:
virtual bool Command(const AString & a_Command, const cPlugin * a_Plugin, const AString & a_Permission, const AString & a_HelpString) override
{
UNUSED(a_Plugin);
-
- lua_rawgeti(LuaState, LUA_REGISTRYINDEX, FuncRef); /* Push function reference */
- tolua_pushcppstring(LuaState, a_Command);
- tolua_pushcppstring(LuaState, a_Permission);
- tolua_pushcppstring(LuaState, a_HelpString);
-
- int s = lua_pcall(LuaState, 3, 1, 0);
- if (cLuaState::ReportErrors(LuaState, s))
- {
- return true; /* Abort enumeration */
- }
-
- if (lua_isboolean(LuaState, -1))
- {
- return (tolua_toboolean( LuaState, -1, 0) > 0);
- }
- return false; /* Continue enumeration */
+ bool ret = false;
+ m_LuaState.Call(m_FnRef, a_Command, a_Permission, a_HelpString, cLuaState::Return, ret);
+ return ret;
}
- lua_State * LuaState;
- int FuncRef;
- } Callback(tolua_S, FuncRef);
-
- bool bRetVal = self->ForEachCommand(Callback);
-
- /* Unreference the values again, so the LUA_REGISTRYINDEX can make place for other references */
- luaL_unref(tolua_S, LUA_REGISTRYINDEX, FuncRef);
+ cLuaState & m_LuaState;
+ cLuaState::cRef & m_FnRef;
+ } Callback(L, FnRef);
- /* Push return value on stack */
- tolua_pushboolean(tolua_S, bRetVal);
+ // Execute and push the returned value:
+ L.Push(cPluginManager::Get()->ForEachCommand(Callback));
return 1;
}
@@ -1741,74 +805,56 @@ static int tolua_cPluginManager_ForEachCommand(lua_State * tolua_S)
static int tolua_cPluginManager_ForEachConsoleCommand(lua_State * tolua_S)
{
- int NumArgs = lua_gettop(tolua_S) - 1; /* This includes 'self' */
- if (NumArgs != 1)
- {
- LOGWARN("Error in function call 'ForEachConsoleCommand': Requires 1 argument, got %i", NumArgs);
- return 0;
- }
-
- cPluginManager * self = (cPluginManager *)tolua_tousertype(tolua_S, 1, nullptr);
- if (self == nullptr)
- {
- LOGWARN("Error in function call 'ForEachConsoleCommand': Not called on an object instance");
- return 0;
- }
+ /*
+ Function signature:
+ cPluginManager:Get():ForEachConsoleCommand(a_CallbackFn) -> bool
+ */
- if (!lua_isfunction(tolua_S, 2))
+ // Check params:
+ cLuaState L(tolua_S);
+ if (
+ !L.CheckParamUserType(1, "cPluginManager") ||
+ !L.CheckParamFunction(2) ||
+ !L.CheckParamEnd(3)
+ )
{
- LOGWARN("Error in function call 'ForEachConsoleCommand': Expected a function for parameter #1");
return 0;
}
- int FuncRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
- if (FuncRef == LUA_REFNIL)
+ // Get the params:
+ cLuaState::cRef FnRef;
+ L.GetStackValues(2, FnRef);
+ if (!FnRef.IsValid())
{
LOGWARN("Error in function call 'ForEachConsoleCommand': Could not get function reference of parameter #1");
return 0;
}
+ // Callback for enumerating all commands:
class cLuaCallback : public cPluginManager::cCommandEnumCallback
{
public:
- cLuaCallback(lua_State * a_LuaState, int a_FuncRef)
- : LuaState( a_LuaState)
- , FuncRef( a_FuncRef)
- {}
+ cLuaCallback(cLuaState & a_LuaState, cLuaState::cRef & a_FnRef):
+ m_LuaState(a_LuaState),
+ m_FnRef(a_FnRef)
+ {
+ }
private:
virtual bool Command(const AString & a_Command, const cPlugin * a_Plugin, const AString & a_Permission, const AString & a_HelpString) override
{
UNUSED(a_Plugin);
UNUSED(a_Permission);
-
- lua_rawgeti(LuaState, LUA_REGISTRYINDEX, FuncRef); /* Push function reference */
- tolua_pushcppstring(LuaState, a_Command);
- tolua_pushcppstring(LuaState, a_HelpString);
-
- int s = lua_pcall(LuaState, 2, 1, 0);
- if (cLuaState::ReportErrors(LuaState, s))
- {
- return true; /* Abort enumeration */
- }
-
- if (lua_isboolean(LuaState, -1))
- {
- return (tolua_toboolean( LuaState, -1, 0) > 0);
- }
- return false; /* Continue enumeration */
+ bool ret = false;
+ m_LuaState.Call(m_FnRef, a_Command, a_HelpString, cLuaState::Return, ret);
+ return ret;
}
- lua_State * LuaState;
- int FuncRef;
- } Callback(tolua_S, FuncRef);
-
- bool bRetVal = self->ForEachConsoleCommand(Callback);
-
- /* Unreference the values again, so the LUA_REGISTRYINDEX can make place for other references */
- luaL_unref(tolua_S, LUA_REGISTRYINDEX, FuncRef);
+ cLuaState & m_LuaState;
+ cLuaState::cRef & m_FnRef;
+ } Callback(L, FnRef);
- /* Push return value on stack */
- tolua_pushboolean(tolua_S, bRetVal);
+ // Execute and push the returned value:
+ L.Push(cPluginManager::Get()->ForEachConsoleCommand(Callback));
return 1;
}
@@ -1822,7 +868,7 @@ static int tolua_cPluginManager_BindCommand(lua_State * L)
cPluginManager:BindCommand(Command, Permission, Function, HelpString)
cPluginManager.BindCommand(Command, Permission, Function, HelpString) -- without the "self" param
*/
- cPluginLua * Plugin = GetLuaPlugin(L);
+ cPluginLua * Plugin = cManualBindings::GetLuaPlugin(L);
if (Plugin == nullptr)
{
return 0;
@@ -1892,7 +938,7 @@ static int tolua_cPluginManager_BindConsoleCommand(lua_State * L)
*/
// Get the plugin identification out of LuaState:
- cPluginLua * Plugin = GetLuaPlugin(L);
+ cPluginLua * Plugin = cManualBindings::GetLuaPlugin(L);
if (Plugin == nullptr)
{
return 0;
@@ -1980,7 +1026,7 @@ static int tolua_cPluginManager_CallPlugin(lua_State * tolua_S)
}
// If requesting calling the current plugin, refuse:
- cPluginLua * ThisPlugin = GetLuaPlugin(L);
+ cPluginLua * ThisPlugin = cManualBindings::GetLuaPlugin(L);
if (ThisPlugin == nullptr)
{
return 0;
@@ -2011,7 +1057,11 @@ static int tolua_cPluginManager_CallPlugin(lua_State * tolua_S)
virtual bool Item(cPlugin * a_Plugin) override
{
- m_NumReturns = ((cPluginLua *)a_Plugin)->CallFunctionFromForeignState(
+ if (!a_Plugin->IsLoaded())
+ {
+ return false;
+ }
+ m_NumReturns = static_cast<cPluginLua *>(a_Plugin)->CallFunctionFromForeignState(
m_FunctionName, m_SrcLuaState, 4, lua_gettop(m_SrcLuaState)
);
return true;
@@ -2019,9 +1069,11 @@ static int tolua_cPluginManager_CallPlugin(lua_State * tolua_S)
} Callback(FunctionName, L);
if (!cPluginManager::Get()->DoWithPlugin(PluginName, Callback))
{
- // TODO 2014_01_20 _X: This might be too much logging, plugins cannot know if other plugins are loaded (async)
- LOGWARNING("cPluginManager::CallPlugin: No such plugin name (\"%s\")", PluginName.c_str());
- L.LogStackTrace();
+ return 0;
+ }
+ if (Callback.m_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;
@@ -2031,48 +1083,48 @@ static int tolua_cPluginManager_CallPlugin(lua_State * tolua_S)
-static int tolua_cWorld_ChunkStay(lua_State * tolua_S)
+static int tolua_cPluginManager_ExecuteConsoleCommand(lua_State * tolua_S)
{
- /* Function signature:
- World:ChunkStay(ChunkCoordTable, OnChunkAvailable, OnAllChunksAvailable)
- ChunkCoordTable == { {Chunk1x, Chunk1z}, {Chunk2x, Chunk2z}, ... }
+ /*
+ Function signature:
+ cPluginManager:ExecuteConsoleCommand(EntireCommandStr) -> OutputString
*/
-
+
+ // Check params:
cLuaState L(tolua_S);
if (
- !L.CheckParamUserType (1, "cWorld") ||
- !L.CheckParamTable (2) ||
- !L.CheckParamFunctionOrNil(3, 4)
+ !L.CheckParamUserTable(1, "cPluginManager") ||
+ !L.CheckParamString(2) ||
+ !L.CheckParamEnd(3)
)
{
return 0;
}
-
- cPluginLua * Plugin = GetLuaPlugin(tolua_S);
- if (Plugin == nullptr)
- {
- return 0;
- }
-
- // Read the params:
- cWorld * World = (cWorld *)tolua_tousertype(tolua_S, 1, nullptr);
- if (World == nullptr)
- {
- LOGWARNING("World:ChunkStay(): invalid world parameter");
- L.LogStackTrace();
- return 0;
- }
- cLuaChunkStay * ChunkStay = new cLuaChunkStay(*Plugin);
+ // Get the params:
+ AString Command;
+ L.GetStackValues(2, Command);
+ auto Split = StringSplit(Command, " ");
+
+ // Store the command output in a string:
+ cStringAccumCommandOutputCallback CommandOutput;
+ L.Push(cPluginManager::Get()->ExecuteConsoleCommand(Split, CommandOutput, Command));
+ L.Push(CommandOutput.GetAccum());
+ return 2;
+}
- if (!ChunkStay->AddChunks(2))
- {
- delete ChunkStay;
- ChunkStay = nullptr;
- return 0;
- }
- ChunkStay->Enable(*World->GetChunkMap(), 3, 4);
+
+
+
+static int tolua_cPluginManager_FindPlugins(lua_State * tolua_S)
+{
+ // API function no longer exists:
+ LOGWARNING("cPluginManager:FindPlugins() is obsolete, use cPluginManager:RefreshPluginList() instead!");
+ cLuaState::LogStackTrace(tolua_S);
+
+ // Still, do the actual work performed by the API function when it existed:
+ cPluginManager::Get()->RefreshPluginList();
return 0;
}
@@ -2080,75 +1132,40 @@ static int tolua_cWorld_ChunkStay(lua_State * tolua_S)
-static int tolua_cWorld_PrepareChunk(lua_State * tolua_S)
+static int tolua_cPlayer_GetPermissions(lua_State * tolua_S)
{
- /* Function signature:
- World:PrepareChunk(ChunkX, ChunkZ, Callback)
- */
-
- // Check the param types:
+ // Function signature: cPlayer:GetPermissions() -> {permissions-array}
+
+ // Check the params:
cLuaState L(tolua_S);
if (
- !L.CheckParamUserType (1, "cWorld") ||
- !L.CheckParamNumber (2, 3) ||
- !L.CheckParamFunctionOrNil(4)
+ !L.CheckParamUserType(1, "cPlayer") ||
+ !L.CheckParamEnd (2)
)
{
return 0;
}
-
- // Read the params:
- cWorld * world = nullptr;
- int chunkX = 0, chunkZ = 0;
- L.GetStackValues(1, world, chunkX, chunkZ);
- if (world == nullptr)
+
+ // Get the params:
+ cPlayer * self = (cPlayer *)tolua_tousertype(tolua_S, 1, nullptr);
+ if (self == nullptr)
{
- LOGWARNING("World:PrepareChunk(): invalid world parameter");
- L.LogStackTrace();
+ LOGWARNING("%s: invalid self (%p)", __FUNCTION__, self);
return 0;
}
-
- // Wrap the Lua callback inside a C++ callback class:
- class cCallback:
- public cChunkCoordCallback
- {
- public:
- cCallback(lua_State * a_LuaState):
- m_LuaState(a_LuaState),
- m_Callback(m_LuaState, 4)
- {
- }
-
- // cChunkCoordCallback override:
- virtual void Call(int a_CBChunkX, int a_CBChunkZ) override
- {
- if (m_Callback.IsValid())
- {
- m_LuaState.Call(m_Callback, a_CBChunkX, a_CBChunkZ);
- }
-
- // This is the last reference of this object, we must delete it so that it doesn't leak:
- delete this;
- }
-
- protected:
- cLuaState m_LuaState;
- cLuaState::cRef m_Callback;
- };
- cCallback * callback = new cCallback(tolua_S);
-
- // Call the chunk preparation:
- world->PrepareChunk(chunkX, chunkZ, callback);
- return 0;
+
+ // Push the permissions:
+ L.Push(self->GetPermissions());
+ return 1;
}
-static int tolua_cPlayer_GetPermissions(lua_State * tolua_S)
+static int tolua_cPlayer_GetRestrictions(lua_State * tolua_S)
{
- // Function signature: cPlayer:GetPermissions() -> {permissions-array}
+ // Function signature: cPlayer:GetRestrictions() -> {restrictions-array}
// Check the params:
cLuaState L(tolua_S);
@@ -2169,7 +1186,7 @@ static int tolua_cPlayer_GetPermissions(lua_State * tolua_S)
}
// Push the permissions:
- L.Push(self->GetPermissions());
+ L.Push(self->GetRestrictions());
return 1;
}
@@ -2182,7 +1199,7 @@ static int tolua_cPlayer_OpenWindow(lua_State * tolua_S)
// Function signature: cPlayer:OpenWindow(Window)
// Retrieve the plugin instance from the Lua state
- cPluginLua * Plugin = GetLuaPlugin(tolua_S);
+ cPluginLua * Plugin = cManualBindings::GetLuaPlugin(tolua_S);
if (Plugin == nullptr)
{
return 0;
@@ -2263,7 +1280,7 @@ static int tolua_SetObjectCallback(lua_State * tolua_S)
// Function signature: OBJTYPE:SetWhateverCallback(CallbackFunction)
// Retrieve the plugin instance from the Lua state
- cPluginLua * Plugin = GetLuaPlugin(tolua_S);
+ cPluginLua * Plugin = cManualBindings::GetLuaPlugin(tolua_S);
if (Plugin == nullptr)
{
// Warning message has already been printed by GetLuaPlugin(), bail out silently
@@ -2315,7 +1332,7 @@ static int tolua_cPluginLua_AddWebTab(lua_State * tolua_S)
}
else
{
- return tolua_do_error(tolua_S, "#ferror calling function '#funcname#'", &tolua_err);
+ return cManualBindings::tolua_do_error(tolua_S, "#ferror calling function '#funcname#'", &tolua_err);
}
if (Reference != LUA_REFNIL)
@@ -2337,40 +1354,40 @@ static int tolua_cPluginLua_AddWebTab(lua_State * tolua_S)
-static int tolua_cPluginLua_AddTab(lua_State* tolua_S)
+static int tolua_cPlugin_GetDirectory(lua_State * tolua_S)
{
- cPluginLua * self = (cPluginLua *) tolua_tousertype(tolua_S, 1, nullptr);
- LOGWARN("WARNING: Using deprecated function AddTab()! Use AddWebTab() instead. (plugin \"%s\" in folder \"%s\")",
- self->GetName().c_str(), self->GetDirectory().c_str()
- );
- return tolua_cPluginLua_AddWebTab( tolua_S);
+ cLuaState L(tolua_S);
+
+ // Log the obsoletion warning:
+ LOGWARNING("cPlugin:GetDirectory() is obsolete, use cPlugin:GetFolderName() instead.");
+ L.LogStackTrace();
+
+ // Retrieve the params:
+ cPlugin * Plugin = static_cast<cPluginLua *>(tolua_tousertype(tolua_S, 1, nullptr));
+
+ // Get the folder name:
+ L.Push(Plugin->GetFolderName());
+ return 1;
}
-static int tolua_cPlugin_Call(lua_State * tolua_S)
+static int tolua_cPlugin_GetLocalDirectory(lua_State * tolua_S)
{
cLuaState L(tolua_S);
// Log the obsoletion warning:
- LOGWARNING("cPlugin:Call() is obsolete and unsafe, use cPluginManager:CallPlugin() instead.");
+ LOGWARNING("cPlugin:GetLocalDirectory() is obsolete, use cPlugin:GetLocalFolder() instead.");
L.LogStackTrace();
- // Retrieve the params: plugin and the function name to call
- cPluginLua * TargetPlugin = (cPluginLua *) tolua_tousertype(tolua_S, 1, nullptr);
- AString FunctionName = tolua_tostring(tolua_S, 2, "");
+ // Retrieve the params:
+ cPlugin * Plugin = static_cast<cPluginLua *>(tolua_tousertype(tolua_S, 1, nullptr));
- // Call the function:
- int NumReturns = TargetPlugin->CallFunctionFromForeignState(FunctionName, L, 3, lua_gettop(L));
- if (NumReturns < 0)
- {
- LOGWARNING("cPlugin::Call() failed to call destination function");
- L.LogStackTrace();
- return 0;
- }
- return NumReturns;
+ // Get the folder:
+ L.Push(Plugin->GetLocalFolder());
+ return 1;
}
@@ -2488,8 +1505,8 @@ static int tolua_push_StringStringMap(lua_State* tolua_S, std::map< std::string,
for (std::map<std::string, std::string>::iterator it = a_StringStringMap.begin(); it != a_StringStringMap.end(); ++it)
{
- const char* key = it->first.c_str();
- const char* value = it->second.c_str();
+ const char * key = it->first.c_str();
+ const char * value = it->second.c_str();
lua_pushstring(tolua_S, key);
lua_pushstring(tolua_S, value);
lua_settable(tolua_S, top);
@@ -2504,7 +1521,7 @@ static int tolua_push_StringStringMap(lua_State* tolua_S, std::map< std::string,
static int tolua_get_HTTPRequest_Params(lua_State* tolua_S)
{
- HTTPRequest* self = (HTTPRequest*) tolua_tousertype(tolua_S, 1, nullptr);
+ HTTPRequest * self = reinterpret_cast<HTTPRequest *>(tolua_tousertype(tolua_S, 1, nullptr));
return tolua_push_StringStringMap(tolua_S, self->Params);
}
@@ -2514,7 +1531,7 @@ static int tolua_get_HTTPRequest_Params(lua_State* tolua_S)
static int tolua_get_HTTPRequest_PostParams(lua_State* tolua_S)
{
- HTTPRequest* self = (HTTPRequest*) tolua_tousertype(tolua_S, 1, nullptr);
+ HTTPRequest * self = reinterpret_cast<HTTPRequest *>(tolua_tousertype(tolua_S, 1, nullptr));
return tolua_push_StringStringMap(tolua_S, self->PostParams);
}
@@ -2524,8 +1541,8 @@ static int tolua_get_HTTPRequest_PostParams(lua_State* tolua_S)
static int tolua_get_HTTPRequest_FormData(lua_State* tolua_S)
{
- HTTPRequest* self = (HTTPRequest*) tolua_tousertype(tolua_S, 1, nullptr);
- std::map< std::string, HTTPFormData >& FormData = self->FormData;
+ HTTPRequest * self = reinterpret_cast<HTTPRequest *>(tolua_tousertype(tolua_S, 1, nullptr));
+ std::map<std::string, HTTPFormData> & FormData = self->FormData;
lua_newtable(tolua_S);
int top = lua_gettop(tolua_S);
@@ -2628,22 +1645,16 @@ static int tolua_AllToLua_cWebAdmin_GetURLEncodedString(lua_State * tolua_S)
static int tolua_cWebPlugin_GetTabNames(lua_State * tolua_S)
{
- cWebPlugin* self = (cWebPlugin*) tolua_tousertype(tolua_S, 1, nullptr);
-
- const cWebPlugin::TabNameList & TabNames = self->GetTabNames();
-
+ // Returns a map of (SafeTitle -> Title) for the plugin's web tabs.
+ auto self = reinterpret_cast<cWebPlugin *>(tolua_tousertype(tolua_S, 1, nullptr));
+ auto TabNames = self->GetTabNames();
lua_newtable(tolua_S);
int index = 1;
- cWebPlugin::TabNameList::const_iterator iter = TabNames.begin();
- while (iter != TabNames.end())
- {
- const AString & FancyName = iter->first;
- const AString & WebName = iter->second;
- tolua_pushstring( tolua_S, WebName.c_str()); // Because the WebName is supposed to be unique, use it as key
- tolua_pushstring( tolua_S, FancyName.c_str());
- //
+ for (auto itr = TabNames.cbegin(), end = TabNames.cend(); itr != end; ++itr)
+ {
+ tolua_pushstring(tolua_S, itr->second.c_str()); // Because the SafeTitle is supposed to be unique, use it as key
+ tolua_pushstring(tolua_S, itr->first.c_str());
lua_rawset(tolua_S, -3);
- ++iter;
++index;
}
return 1;
@@ -3214,6 +2225,44 @@ static int tolua_cBlockArea_GetOrigin(lua_State * tolua_S)
+static int tolua_cBlockArea_GetNonAirCropRelCoords(lua_State * tolua_S)
+{
+ // function cBlockArea::GetNonAirCropRelCoords()
+ // Exported manually because tolua would generate extra input params for the outputs
+
+ cLuaState L(tolua_S);
+ if (!L.CheckParamUserType(1, "cBlockArea"))
+ {
+ return 0;
+ }
+
+ cBlockArea * self = nullptr;
+ BLOCKTYPE IgnoreBlockType = E_BLOCK_AIR;
+ L.GetStackValues(1, self, IgnoreBlockType);
+ if (self == nullptr)
+ {
+ tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea:GetNonAirCropRelCoords'", nullptr);
+ return 0;
+ }
+
+ // Calculate the crop coords:
+ int MinRelX, MinRelY, MinRelZ, MaxRelX, MaxRelY, MaxRelZ;
+ self->GetNonAirCropRelCoords(MinRelX, MinRelY, MinRelZ, MaxRelX, MaxRelY, MaxRelZ, IgnoreBlockType);
+
+ // Push the six crop coords:
+ L.Push(MinRelX);
+ L.Push(MinRelY);
+ L.Push(MinRelZ);
+ L.Push(MaxRelX);
+ L.Push(MaxRelY);
+ L.Push(MaxRelZ);
+ return 6;
+}
+
+
+
+
+
static int tolua_cBlockArea_GetRelBlockTypeMeta(lua_State * tolua_S)
{
// function cBlockArea::GetRelBlockTypeMeta()
@@ -3680,17 +2729,17 @@ static int tolua_cCompositeChat_UnderlineUrls(lua_State * tolua_S)
-void ManualBindings::Bind(lua_State * tolua_S)
+void cManualBindings::Bind(lua_State * tolua_S)
{
tolua_beginmodule(tolua_S, nullptr);
// Create the new classes:
tolua_usertype(tolua_S, "cCryptoHash");
- tolua_cclass(tolua_S, "cCryptoHash", "cCryptoHash", "", nullptr);
+ tolua_usertype(tolua_S, "cLineBlockTracer");
tolua_usertype(tolua_S, "cStringCompression");
+ tolua_cclass(tolua_S, "cCryptoHash", "cCryptoHash", "", nullptr);
+ tolua_cclass(tolua_S, "cLineBlockTracer", "cLineBlockTracer", "", nullptr);
tolua_cclass(tolua_S, "cStringCompression", "cStringCompression", "", nullptr);
- tolua_usertype(tolua_S, "cLineBlockTracer");
- tolua_cclass(tolua_S, "cLineBlockTracer", "cLineBlockTracer", "", nullptr);
// Globals:
tolua_function(tolua_S, "Clamp", tolua_Clamp);
@@ -3705,15 +2754,12 @@ void ManualBindings::Bind(lua_State * tolua_S)
tolua_function(tolua_S, "Base64Encode", tolua_Base64Encode);
tolua_function(tolua_S, "Base64Decode", tolua_Base64Decode);
tolua_function(tolua_S, "md5", tolua_md5_obsolete); // OBSOLETE, use cCryptoHash.md5() instead
-
- tolua_beginmodule(tolua_S, "cFile");
- tolua_function(tolua_S, "GetFolderContents", tolua_cFile_GetFolderContents);
- tolua_endmodule(tolua_S);
-
+
tolua_beginmodule(tolua_S, "cBlockArea");
tolua_function(tolua_S, "GetBlockTypeMeta", tolua_cBlockArea_GetBlockTypeMeta);
tolua_function(tolua_S, "GetCoordRange", tolua_cBlockArea_GetCoordRange);
tolua_function(tolua_S, "GetOrigin", tolua_cBlockArea_GetOrigin);
+ tolua_function(tolua_S, "GetNonAirCropRelCoords", tolua_cBlockArea_GetNonAirCropRelCoords);
tolua_function(tolua_S, "GetRelBlockTypeMeta", tolua_cBlockArea_GetRelBlockTypeMeta);
tolua_function(tolua_S, "GetSize", tolua_cBlockArea_GetSize);
tolua_function(tolua_S, "LoadFromSchematicFile", tolua_cBlockArea_LoadFromSchematicFile);
@@ -3721,7 +2767,13 @@ void ManualBindings::Bind(lua_State * tolua_S)
tolua_function(tolua_S, "SaveToSchematicFile", tolua_cBlockArea_SaveToSchematicFile);
tolua_function(tolua_S, "SaveToSchematicString", tolua_cBlockArea_SaveToSchematicString);
tolua_endmodule(tolua_S);
-
+
+ tolua_beginmodule(tolua_S, "cClientHandle");
+ tolua_constant(tolua_S, "MAX_VIEW_DISTANCE", cClientHandle::MAX_VIEW_DISTANCE);
+ tolua_constant(tolua_S, "MIN_VIEW_DISTANCE", cClientHandle::MIN_VIEW_DISTANCE);
+ tolua_function(tolua_S, "SendPluginMessage", tolua_cClientHandle_SendPluginMessage);
+ tolua_endmodule(tolua_S);
+
tolua_beginmodule(tolua_S, "cCompositeChat");
tolua_function(tolua_S, "AddRunCommandPart", tolua_cCompositeChat_AddRunCommandPart);
tolua_function(tolua_S, "AddSuggestCommandPart", tolua_cCompositeChat_AddSuggestCommandPart);
@@ -3731,105 +2783,105 @@ void ManualBindings::Bind(lua_State * tolua_S)
tolua_function(tolua_S, "SetMessageType", tolua_cCompositeChat_SetMessageType);
tolua_function(tolua_S, "UnderlineUrls", tolua_cCompositeChat_UnderlineUrls);
tolua_endmodule(tolua_S);
-
+
+ tolua_beginmodule(tolua_S, "cCryptoHash");
+ tolua_function(tolua_S, "md5", tolua_md5);
+ tolua_function(tolua_S, "md5HexString", tolua_md5HexString);
+ tolua_function(tolua_S, "sha1", tolua_sha1);
+ tolua_function(tolua_S, "sha1HexString", tolua_sha1HexString);
+ tolua_endmodule(tolua_S);
+
+ tolua_beginmodule(tolua_S, "cEntity");
+ tolua_constant(tolua_S, "INVALID_ID", cEntity::INVALID_ID);
+ tolua_endmodule(tolua_S);
+
+ tolua_beginmodule(tolua_S, "cFile");
+ tolua_function(tolua_S, "GetFolderContents", tolua_cFile_GetFolderContents);
+ tolua_function(tolua_S, "ReadWholeFile", tolua_cFile_ReadWholeFile);
+ tolua_endmodule(tolua_S);
+
tolua_beginmodule(tolua_S, "cHopperEntity");
tolua_function(tolua_S, "GetOutputBlockPos", tolua_cHopperEntity_GetOutputBlockPos);
tolua_endmodule(tolua_S);
-
+
+ tolua_beginmodule(tolua_S, "cItemGrid");
+ tolua_function(tolua_S, "GetSlotCoords", Lua_ItemGrid_GetSlotCoords);
+ tolua_endmodule(tolua_S);
+
tolua_beginmodule(tolua_S, "cLineBlockTracer");
tolua_function(tolua_S, "Trace", tolua_cLineBlockTracer_Trace);
tolua_endmodule(tolua_S);
-
- tolua_beginmodule(tolua_S, "cRoot");
- tolua_function(tolua_S, "FindAndDoWithPlayer", tolua_DoWith <cRoot, cPlayer, &cRoot::FindAndDoWithPlayer>);
- tolua_function(tolua_S, "DoWithPlayerByUUID", tolua_DoWith <cRoot, cPlayer, &cRoot::DoWithPlayerByUUID>);
- tolua_function(tolua_S, "ForEachPlayer", tolua_ForEach<cRoot, cPlayer, &cRoot::ForEachPlayer>);
- tolua_function(tolua_S, "ForEachWorld", tolua_ForEach<cRoot, cWorld, &cRoot::ForEachWorld>);
- tolua_function(tolua_S, "GetFurnaceRecipe", tolua_cRoot_GetFurnaceRecipe);
- tolua_endmodule(tolua_S);
-
- tolua_beginmodule(tolua_S, "cWorld");
- tolua_function(tolua_S, "ChunkStay", tolua_cWorld_ChunkStay);
- tolua_function(tolua_S, "DoWithBlockEntityAt", tolua_DoWithXYZ<cWorld, cBlockEntity, &cWorld::DoWithBlockEntityAt>);
- tolua_function(tolua_S, "DoWithBeaconAt", tolua_DoWithXYZ<cWorld, cBeaconEntity, &cWorld::DoWithBeaconAt>);
- tolua_function(tolua_S, "DoWithChestAt", tolua_DoWithXYZ<cWorld, cChestEntity, &cWorld::DoWithChestAt>);
- tolua_function(tolua_S, "DoWithDispenserAt", tolua_DoWithXYZ<cWorld, cDispenserEntity, &cWorld::DoWithDispenserAt>);
- tolua_function(tolua_S, "DoWithDropSpenserAt", tolua_DoWithXYZ<cWorld, cDropSpenserEntity, &cWorld::DoWithDropSpenserAt>);
- tolua_function(tolua_S, "DoWithDropperAt", tolua_DoWithXYZ<cWorld, cDropperEntity, &cWorld::DoWithDropperAt>);
- tolua_function(tolua_S, "DoWithEntityByID", tolua_DoWithID< cWorld, cEntity, &cWorld::DoWithEntityByID>);
- tolua_function(tolua_S, "DoWithFurnaceAt", tolua_DoWithXYZ<cWorld, cFurnaceEntity, &cWorld::DoWithFurnaceAt>);
- tolua_function(tolua_S, "DoWithNoteBlockAt", tolua_DoWithXYZ<cWorld, cNoteEntity, &cWorld::DoWithNoteBlockAt>);
- tolua_function(tolua_S, "DoWithCommandBlockAt", tolua_DoWithXYZ<cWorld, cCommandBlockEntity, &cWorld::DoWithCommandBlockAt>);
- tolua_function(tolua_S, "DoWithMobHeadAt", tolua_DoWithXYZ<cWorld, cMobHeadEntity, &cWorld::DoWithMobHeadAt>);
- tolua_function(tolua_S, "DoWithFlowerPotAt", tolua_DoWithXYZ<cWorld, cFlowerPotEntity, &cWorld::DoWithFlowerPotAt>);
- tolua_function(tolua_S, "DoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::DoWithPlayer>);
- tolua_function(tolua_S, "FindAndDoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::FindAndDoWithPlayer>);
- tolua_function(tolua_S, "DoWithPlayerByUUID", tolua_DoWith< cWorld, cPlayer, &cWorld::DoWithPlayerByUUID>);
- tolua_function(tolua_S, "ForEachBlockEntityInChunk", tolua_ForEachInChunk<cWorld, cBlockEntity, &cWorld::ForEachBlockEntityInChunk>);
- tolua_function(tolua_S, "ForEachChestInChunk", tolua_ForEachInChunk<cWorld, cChestEntity, &cWorld::ForEachChestInChunk>);
- tolua_function(tolua_S, "ForEachEntity", tolua_ForEach< cWorld, cEntity, &cWorld::ForEachEntity>);
- tolua_function(tolua_S, "ForEachEntityInBox", tolua_ForEachInBox< cWorld, cEntity, &cWorld::ForEachEntityInBox>);
- tolua_function(tolua_S, "ForEachEntityInChunk", tolua_ForEachInChunk<cWorld, cEntity, &cWorld::ForEachEntityInChunk>);
- tolua_function(tolua_S, "ForEachFurnaceInChunk", tolua_ForEachInChunk<cWorld, cFurnaceEntity, &cWorld::ForEachFurnaceInChunk>);
- tolua_function(tolua_S, "ForEachPlayer", tolua_ForEach< cWorld, cPlayer, &cWorld::ForEachPlayer>);
- tolua_function(tolua_S, "GetBlockInfo", tolua_cWorld_GetBlockInfo);
- tolua_function(tolua_S, "GetBlockTypeMeta", tolua_cWorld_GetBlockTypeMeta);
- tolua_function(tolua_S, "GetSignLines", tolua_cWorld_GetSignLines);
- tolua_function(tolua_S, "PrepareChunk", tolua_cWorld_PrepareChunk);
- tolua_function(tolua_S, "QueueTask", tolua_cWorld_QueueTask);
- tolua_function(tolua_S, "ScheduleTask", tolua_cWorld_ScheduleTask);
- tolua_function(tolua_S, "SetSignLines", tolua_cWorld_SetSignLines);
- tolua_function(tolua_S, "TryGetHeight", tolua_cWorld_TryGetHeight);
+
+ tolua_beginmodule(tolua_S, "cLuaWindow");
+ tolua_function(tolua_S, "SetOnClosing", tolua_SetObjectCallback<cLuaWindow, &cLuaWindow::SetOnClosing>);
+ tolua_function(tolua_S, "SetOnSlotChanged", tolua_SetObjectCallback<cLuaWindow, &cLuaWindow::SetOnSlotChanged>);
tolua_endmodule(tolua_S);
-
+
tolua_beginmodule(tolua_S, "cMapManager");
- tolua_function(tolua_S, "DoWithMap", tolua_DoWithID<cMapManager, cMap, &cMapManager::DoWithMap>);
+ tolua_function(tolua_S, "DoWithMap", DoWithID<cMapManager, cMap, &cMapManager::DoWithMap>);
tolua_endmodule(tolua_S);
- tolua_beginmodule(tolua_S, "cScoreboard");
- tolua_function(tolua_S, "ForEachObjective", tolua_ForEach<cScoreboard, cObjective, &cScoreboard::ForEachObjective>);
- tolua_function(tolua_S, "ForEachTeam", tolua_ForEach<cScoreboard, cTeam, &cScoreboard::ForEachTeam>);
+ tolua_beginmodule(tolua_S, "cMojangAPI");
+ tolua_function(tolua_S, "AddPlayerNameToUUIDMapping", tolua_cMojangAPI_AddPlayerNameToUUIDMapping);
+ tolua_function(tolua_S, "GetPlayerNameFromUUID", tolua_cMojangAPI_GetPlayerNameFromUUID);
+ tolua_function(tolua_S, "GetUUIDFromPlayerName", tolua_cMojangAPI_GetUUIDFromPlayerName);
+ tolua_function(tolua_S, "GetUUIDsFromPlayerNames", tolua_cMojangAPI_GetUUIDsFromPlayerNames);
+ tolua_function(tolua_S, "MakeUUIDDashed", tolua_cMojangAPI_MakeUUIDDashed);
+ tolua_function(tolua_S, "MakeUUIDShort", tolua_cMojangAPI_MakeUUIDShort);
tolua_endmodule(tolua_S);
-
+
+ tolua_beginmodule(tolua_S, "cPlayer");
+ tolua_function(tolua_S, "GetPermissions", tolua_cPlayer_GetPermissions);
+ tolua_function(tolua_S, "GetRestrictions", tolua_cPlayer_GetRestrictions);
+ tolua_function(tolua_S, "OpenWindow", tolua_cPlayer_OpenWindow);
+ tolua_function(tolua_S, "PermissionMatches", tolua_cPlayer_PermissionMatches);
+ tolua_endmodule(tolua_S);
+
tolua_beginmodule(tolua_S, "cPlugin");
- tolua_function(tolua_S, "Call", tolua_cPlugin_Call);
+ tolua_function(tolua_S, "GetDirectory", tolua_cPlugin_GetDirectory);
+ tolua_function(tolua_S, "GetLocalDirectory", tolua_cPlugin_GetLocalDirectory);
tolua_endmodule(tolua_S);
+ tolua_beginmodule(tolua_S, "cPluginLua");
+ tolua_function(tolua_S, "AddWebTab", tolua_cPluginLua_AddWebTab);
+ tolua_endmodule(tolua_S);
+
tolua_beginmodule(tolua_S, "cPluginManager");
tolua_function(tolua_S, "AddHook", tolua_cPluginManager_AddHook);
tolua_function(tolua_S, "BindCommand", tolua_cPluginManager_BindCommand);
tolua_function(tolua_S, "BindConsoleCommand", tolua_cPluginManager_BindConsoleCommand);
tolua_function(tolua_S, "CallPlugin", tolua_cPluginManager_CallPlugin);
+ tolua_function(tolua_S, "DoWithPlugin", StaticDoWith<cPluginManager, cPlugin, &cPluginManager::DoWithPlugin>);
+ tolua_function(tolua_S, "ExecuteConsoleCommand", tolua_cPluginManager_ExecuteConsoleCommand);
+ tolua_function(tolua_S, "FindPlugins", tolua_cPluginManager_FindPlugins);
tolua_function(tolua_S, "ForEachCommand", tolua_cPluginManager_ForEachCommand);
tolua_function(tolua_S, "ForEachConsoleCommand", tolua_cPluginManager_ForEachConsoleCommand);
+ tolua_function(tolua_S, "ForEachPlugin", StaticForEach<cPluginManager, cPlugin, &cPluginManager::ForEachPlugin>);
tolua_function(tolua_S, "GetAllPlugins", tolua_cPluginManager_GetAllPlugins);
tolua_function(tolua_S, "GetCurrentPlugin", tolua_cPluginManager_GetCurrentPlugin);
+ tolua_function(tolua_S, "GetPlugin", tolua_cPluginManager_GetPlugin);
tolua_function(tolua_S, "LogStackTrace", tolua_cPluginManager_LogStackTrace);
tolua_endmodule(tolua_S);
-
- tolua_beginmodule(tolua_S, "cPlayer");
- tolua_function(tolua_S, "GetPermissions", tolua_cPlayer_GetPermissions);
- tolua_function(tolua_S, "OpenWindow", tolua_cPlayer_OpenWindow);
- tolua_function(tolua_S, "PermissionMatches", tolua_cPlayer_PermissionMatches);
- tolua_endmodule(tolua_S);
-
- tolua_beginmodule(tolua_S, "cLuaWindow");
- tolua_function(tolua_S, "SetOnClosing", tolua_SetObjectCallback<cLuaWindow, &cLuaWindow::SetOnClosing>);
- tolua_function(tolua_S, "SetOnSlotChanged", tolua_SetObjectCallback<cLuaWindow, &cLuaWindow::SetOnSlotChanged>);
+
+ tolua_beginmodule(tolua_S, "cRoot");
+ tolua_function(tolua_S, "FindAndDoWithPlayer", DoWith <cRoot, cPlayer, &cRoot::FindAndDoWithPlayer>);
+ tolua_function(tolua_S, "DoWithPlayerByUUID", DoWith <cRoot, cPlayer, &cRoot::DoWithPlayerByUUID>);
+ tolua_function(tolua_S, "ForEachPlayer", ForEach<cRoot, cPlayer, &cRoot::ForEachPlayer>);
+ tolua_function(tolua_S, "ForEachWorld", ForEach<cRoot, cWorld, &cRoot::ForEachWorld>);
+ tolua_function(tolua_S, "GetFurnaceRecipe", tolua_cRoot_GetFurnaceRecipe);
tolua_endmodule(tolua_S);
- tolua_beginmodule(tolua_S, "cPluginLua");
- tolua_function(tolua_S, "AddTab", tolua_cPluginLua_AddTab);
- tolua_function(tolua_S, "AddWebTab", tolua_cPluginLua_AddWebTab);
+ tolua_beginmodule(tolua_S, "cScoreboard");
+ tolua_function(tolua_S, "ForEachObjective", ForEach<cScoreboard, cObjective, &cScoreboard::ForEachObjective>);
+ tolua_function(tolua_S, "ForEachTeam", ForEach<cScoreboard, cTeam, &cScoreboard::ForEachTeam>);
tolua_endmodule(tolua_S);
- tolua_cclass(tolua_S, "HTTPRequest", "HTTPRequest", "", nullptr);
- tolua_beginmodule(tolua_S, "HTTPRequest");
- // tolua_variable(tolua_S, "Method", tolua_get_HTTPRequest_Method, tolua_set_HTTPRequest_Method);
- // tolua_variable(tolua_S, "Path", tolua_get_HTTPRequest_Path, tolua_set_HTTPRequest_Path);
- tolua_variable(tolua_S, "FormData", tolua_get_HTTPRequest_FormData, 0);
- tolua_variable(tolua_S, "Params", tolua_get_HTTPRequest_Params, 0);
- tolua_variable(tolua_S, "PostParams", tolua_get_HTTPRequest_PostParams, 0);
+ tolua_beginmodule(tolua_S, "cStringCompression");
+ tolua_function(tolua_S, "CompressStringZLIB", tolua_CompressStringZLIB);
+ tolua_function(tolua_S, "UncompressStringZLIB", tolua_UncompressStringZLIB);
+ tolua_function(tolua_S, "CompressStringGZIP", tolua_CompressStringGZIP);
+ tolua_function(tolua_S, "UncompressStringGZIP", tolua_UncompressStringGZIP);
+ tolua_function(tolua_S, "InflateString", tolua_InflateString);
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "cWebAdmin");
@@ -3841,47 +2893,16 @@ void ManualBindings::Bind(lua_State * tolua_S)
tolua_beginmodule(tolua_S, "cWebPlugin");
tolua_function(tolua_S, "GetTabNames", tolua_cWebPlugin_GetTabNames);
tolua_endmodule(tolua_S);
-
- tolua_beginmodule(tolua_S, "cClientHandle");
- tolua_constant(tolua_S, "MAX_VIEW_DISTANCE", cClientHandle::MAX_VIEW_DISTANCE);
- tolua_constant(tolua_S, "MIN_VIEW_DISTANCE", cClientHandle::MIN_VIEW_DISTANCE);
- tolua_function(tolua_S, "SendPluginMessage", tolua_cClientHandle_SendPluginMessage);
- tolua_endmodule(tolua_S);
- tolua_beginmodule(tolua_S, "cMojangAPI");
- tolua_function(tolua_S, "AddPlayerNameToUUIDMapping", tolua_cMojangAPI_AddPlayerNameToUUIDMapping);
- tolua_function(tolua_S, "GetPlayerNameFromUUID", tolua_cMojangAPI_GetPlayerNameFromUUID);
- tolua_function(tolua_S, "GetUUIDFromPlayerName", tolua_cMojangAPI_GetUUIDFromPlayerName);
- tolua_function(tolua_S, "GetUUIDsFromPlayerNames", tolua_cMojangAPI_GetUUIDsFromPlayerNames);
- tolua_function(tolua_S, "MakeUUIDDashed", tolua_cMojangAPI_MakeUUIDDashed);
- tolua_function(tolua_S, "MakeUUIDShort", tolua_cMojangAPI_MakeUUIDShort);
- tolua_endmodule(tolua_S);
-
- tolua_beginmodule(tolua_S, "cItemGrid");
- tolua_function(tolua_S, "GetSlotCoords", Lua_ItemGrid_GetSlotCoords);
+ tolua_beginmodule(tolua_S, "HTTPRequest");
+ tolua_variable(tolua_S, "FormData", tolua_get_HTTPRequest_FormData, nullptr);
+ tolua_variable(tolua_S, "Params", tolua_get_HTTPRequest_Params, nullptr);
+ tolua_variable(tolua_S, "PostParams", tolua_get_HTTPRequest_PostParams, nullptr);
tolua_endmodule(tolua_S);
- tolua_beginmodule(tolua_S, "cCryptoHash");
- tolua_function(tolua_S, "md5", tolua_md5);
- tolua_function(tolua_S, "md5HexString", tolua_md5HexString);
- tolua_function(tolua_S, "sha1", tolua_sha1);
- tolua_function(tolua_S, "sha1HexString", tolua_sha1HexString);
- tolua_endmodule(tolua_S);
-
- tolua_beginmodule(tolua_S, "cStringCompression");
- tolua_function(tolua_S, "CompressStringZLIB", tolua_CompressStringZLIB);
- tolua_function(tolua_S, "UncompressStringZLIB", tolua_UncompressStringZLIB);
- tolua_function(tolua_S, "CompressStringGZIP", tolua_CompressStringGZIP);
- tolua_function(tolua_S, "UncompressStringGZIP", tolua_UncompressStringGZIP);
- tolua_function(tolua_S, "InflateString", tolua_InflateString);
- tolua_endmodule(tolua_S);
-
- BindRankManager(tolua_S);
BindNetwork(tolua_S);
-
- tolua_beginmodule(tolua_S, "cEntity");
- tolua_constant(tolua_S, "INVALID_ID", cEntity::INVALID_ID);
- tolua_endmodule(tolua_S);
+ BindRankManager(tolua_S);
+ BindWorld(tolua_S);
tolua_endmodule(tolua_S);
}