From b4bf13aa4f004a7819e262679a295d8ca886557b Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 11 Mar 2014 16:01:17 +0200 Subject: Unified Vector classes --- src/Bindings/AllToLua.pkg | 10 +++++++--- src/Bindings/LuaState.h | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'src/Bindings') diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index 2676281f9..302714318 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,9 +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" @@ -97,4 +95,10 @@ typedef unsigned char Byte; +// Aliases +$renaming Vector3 @ Vector3d +$renaming Vector3 @ Vector3f +$renaming Vector3 @ Vector3i + + diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 4a7a6fadb..1156f5363 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; -- cgit v1.2.3 From 9810d57a394b2bb56fbcfddb05d34dcd504a7b35 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 11 Mar 2014 18:32:33 +0200 Subject: Unified Matrix4 code --- src/Bindings/AllToLua.pkg | 1 - 1 file changed, 1 deletion(-) (limited to 'src/Bindings') diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index 302714318..1cd7c74f8 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -63,7 +63,6 @@ $cfile "../BlockEntities/MobHeadEntity.h" $cfile "../BlockEntities/FlowerPotEntity.h" $cfile "../WebAdmin.h" $cfile "../Root.h" -$cfile "../Matrix4f.h" $cfile "../Cuboid.h" $cfile "../BoundingBox.h" $cfile "../Tracer.h" -- cgit v1.2.3 From 16b27c4b7ae2ccb03355148fa7fc7116190cc5fb Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 11 Mar 2014 14:16:08 -0700 Subject: Fixed a load of format string errors --- src/Bindings/LuaState.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/Bindings') diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index aa6ee05b3..2351f0c24 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -1281,7 +1281,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; -- cgit v1.2.3 From 0c15fdf7b05ee6ad0705b2a789f6b709bbde2733 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 12 Mar 2014 13:05:28 +0100 Subject: Moved Lua API registering into a separate function. This will allow us to use Lua as lite-config files as well, should we want to. --- src/Bindings/LuaState.cpp | 10 +++++++++- src/Bindings/LuaState.h | 7 ++++++- src/Bindings/PluginLua.cpp | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) (limited to 'src/Bindings') diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index aa6ee05b3..1f0549a59 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; } diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 4a7a6fadb..1495c72f0 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -139,9 +139,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); 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); -- cgit v1.2.3 From a7f9df24d4537a0c7567fa5bbc9e62bb4ef16e56 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 12 Mar 2014 13:11:34 +0100 Subject: The entire unknown command is echoed back to the user on error. --- src/Bindings/PluginManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Bindings') diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index c7df6357e..b9cf160c4 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -248,7 +248,7 @@ bool cPluginManager::CallHookChat(cPlayer * a_Player, AString & a_Message) { AStringVector Split(StringSplit(a_Message, " ")); ASSERT(!Split.empty()); // This should not happen - we know there's at least one char in the message so the split needs to be at least one item long - a_Player->SendMessageInfo(Printf("Unknown command: \"%s\"", Split[0].c_str())); + a_Player->SendMessageInfo(Printf("Unknown command: \"%s\"", a_Message.c_str())); LOGINFO("Player %s issued an unknown command: \"%s\"", a_Player->GetName().c_str(), a_Message.c_str()); return true; // Cancel sending } -- cgit v1.2.3 From 5d7df54e35e99d41f69a44c5ea9c78a98fb557d0 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 12 Mar 2014 14:11:28 +0100 Subject: Fixed Lua string return values. Fixes #773. --- src/Bindings/LuaState.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/Bindings') diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 1f0549a59..dfc428bbc 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -742,10 +742,6 @@ void cLuaState::GetStackValue(int a_StackPos, AString & a_Value) { a_Value.assign(data, len); } - else - { - a_Value.clear(); - } } -- cgit v1.2.3 From bba090ebddd4662f30dc86d3ce20073ef0fc2f6c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 14 Mar 2014 11:18:14 +0100 Subject: cPluginManager:Bind[Console]Command returns true on success. Fixes #801. --- src/Bindings/ManualBindings.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/Bindings') diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index a5247bbe6..462ef3682 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; } @@ -1561,7 +1562,8 @@ static int tolua_cPluginManager_BindConsoleCommand(lua_State * L) } Plugin->BindConsoleCommand(Command, FnRef); - return 0; + lua_pushboolean(L, true); + return 1; } -- cgit v1.2.3 From 9b63156447882c57698aba48da37c82cc0f0b428 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 14 Mar 2014 14:37:39 +0100 Subject: cPlugin:BindConsoleCommand can be called statically. This has been documented before it was written. --- src/Bindings/ManualBindings.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/Bindings') diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 462ef3682..20bbc48f2 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -1522,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++; } -- cgit v1.2.3 From 8e11c270fc786a8b8b72aed71cf8feee659c4876 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 14 Mar 2014 07:59:25 -0700 Subject: Added Noreturn attribtes to a couple of functions and made a missing noreturn an error --- src/Bindings/LuaState.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Bindings') diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 73f9629cb..f5cb8379d 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -200,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); -- cgit v1.2.3