summaryrefslogtreecommitdiffstats
path: root/src/Bindings
diff options
context:
space:
mode:
Diffstat (limited to 'src/Bindings')
-rw-r--r--src/Bindings/AllToLua.pkg11
-rw-r--r--src/Bindings/LuaState.cpp19
-rw-r--r--src/Bindings/LuaState.h12
-rw-r--r--src/Bindings/ManualBindings.cpp11
-rw-r--r--src/Bindings/PluginLua.cpp1
5 files changed, 38 insertions, 16 deletions
diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg
index 2676281f9..1cd7c74f8 100644
--- a/src/Bindings/AllToLua.pkg
+++ b/src/Bindings/AllToLua.pkg
@@ -11,6 +11,7 @@ typedef unsigned int UInt32;
typedef unsigned short UInt16;
+$cfile "../Vector3.h"
$cfile "../ChunkDef.h"
$cfile "../BiomeDef.h"
@@ -62,10 +63,6 @@ $cfile "../BlockEntities/MobHeadEntity.h"
$cfile "../BlockEntities/FlowerPotEntity.h"
$cfile "../WebAdmin.h"
$cfile "../Root.h"
-$cfile "../Vector3f.h"
-$cfile "../Vector3d.h"
-$cfile "../Vector3i.h"
-$cfile "../Matrix4f.h"
$cfile "../Cuboid.h"
$cfile "../BoundingBox.h"
$cfile "../Tracer.h"
@@ -97,4 +94,10 @@ typedef unsigned char Byte;
+// Aliases
+$renaming Vector3<double> @ Vector3d
+$renaming Vector3<float> @ Vector3f
+$renaming Vector3<int> @ Vector3i
+
+
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp
index 1890dcfe5..f24e15c3b 100644
--- a/src/Bindings/LuaState.cpp
+++ b/src/Bindings/LuaState.cpp
@@ -94,12 +94,20 @@ void cLuaState::Create(void)
}
m_LuaState = lua_open();
luaL_openlibs(m_LuaState);
+ m_IsOwned = true;
+}
+
+
+
+
+
+void cLuaState::RegisterAPILibs(void)
+{
tolua_AllToLua_open(m_LuaState);
ManualBindings::Bind(m_LuaState);
DeprecatedBindings::Bind(m_LuaState);
luaopen_lsqlite3(m_LuaState);
luaopen_lxp(m_LuaState);
- m_IsOwned = true;
}
@@ -677,6 +685,7 @@ void cLuaState::Push(Vector3i * a_Vector)
void cLuaState::Push(void * a_Ptr)
{
+ UNUSED(a_Ptr);
ASSERT(IsValid());
// Investigate the cause of this - what is the callstack?
@@ -733,10 +742,6 @@ void cLuaState::GetStackValue(int a_StackPos, AString & a_Value)
{
a_Value.assign(data, len);
}
- else
- {
- a_Value.clear();
- }
}
@@ -1280,7 +1285,9 @@ void cLuaState::LogStack(lua_State * a_LuaState, const char * a_Header)
{
UNUSED(a_Header); // The param seems unused when compiling for release, so the compiler warns
- LOGD((a_Header != NULL) ? a_Header : "Lua C API Stack contents:");
+
+ // Format string consisting only of %s is used to appease the compiler
+ LOGD("%s",(a_Header != NULL) ? a_Header : "Lua C API Stack contents:");
for (int i = lua_gettop(a_LuaState); i > 0; i--)
{
AString Value;
diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h
index 4a7a6fadb..f5cb8379d 100644
--- a/src/Bindings/LuaState.h
+++ b/src/Bindings/LuaState.h
@@ -29,6 +29,8 @@ extern "C"
#include "lua/src/lauxlib.h"
}
+#include "../Vector3.h"
+
@@ -52,7 +54,6 @@ class cWebAdmin;
struct HTTPTemplateRequest;
class cTNTEntity;
class cCreeper;
-class Vector3i;
class cHopperEntity;
class cBlockEntity;
@@ -139,9 +140,14 @@ public:
/** Allows this object to be used in the same way as a lua_State *, for example in the LuaLib functions */
operator lua_State * (void) { return m_LuaState; }
- /** Creates the m_LuaState, if not closed already. This state will be automatically closed in the destructor */
+ /** Creates the m_LuaState, if not closed already. This state will be automatically closed in the destructor.
+ The regular Lua libs are registered, but the MCS API is not registered (so that Lua can be used as
+ lite-config as well), use RegisterAPILibs() to do that. */
void Create(void);
+ /** Registers all the API libraries that MCS provides into m_LuaState. */
+ void RegisterAPILibs(void);
+
/** Closes the m_LuaState, if not closed already */
void Close(void);
@@ -194,7 +200,7 @@ public:
void Push(const HTTPTemplateRequest * a_Request);
void Push(cTNTEntity * a_TNTEntity);
void Push(Vector3i * a_Vector);
- void Push(void * a_Ptr);
+ NORETURNDEBUG void Push(void * a_Ptr);
void Push(cHopperEntity * a_Hopper);
void Push(cBlockEntity * a_BlockEntity);
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index a5247bbe6..20bbc48f2 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -1497,7 +1497,8 @@ static int tolua_cPluginManager_BindCommand(lua_State * L)
}
Plugin->BindCommand(Command, FnRef);
- return 0;
+ lua_pushboolean(L, true);
+ return 1;
}
@@ -1521,7 +1522,10 @@ static int tolua_cPluginManager_BindConsoleCommand(lua_State * L)
// Read the arguments to this API call:
tolua_Error tolua_err;
int idx = 1;
- if (tolua_isusertype(L, 1, "cPluginManager", 0, &tolua_err))
+ if (
+ tolua_isusertype(L, 1, "cPluginManager", 0, &tolua_err) ||
+ tolua_isusertable(L, 1, "cPluginManager", 0, &tolua_err)
+ )
{
idx++;
}
@@ -1561,7 +1565,8 @@ static int tolua_cPluginManager_BindConsoleCommand(lua_State * L)
}
Plugin->BindConsoleCommand(Command, FnRef);
- return 0;
+ lua_pushboolean(L, true);
+ return 1;
}
diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp
index 45c8216be..cccbc3c93 100644
--- a/src/Bindings/PluginLua.cpp
+++ b/src/Bindings/PluginLua.cpp
@@ -75,6 +75,7 @@ bool cPluginLua::Initialize(void)
if (!m_LuaState.IsValid())
{
m_LuaState.Create();
+ m_LuaState.RegisterAPILibs();
// Inject the identification global variables into the state:
lua_pushlightuserdata(m_LuaState, this);