From ebd31ff1321aeb23b5698d74c08f599a2fa62988 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 19 Oct 2014 11:46:38 +0200 Subject: LuaState: Pushing a cEntity pushes the correct class name. This makes Lua scripts easier, as they don't need to cast values from cEntity to the specific descendant. --- src/Bindings/LuaState.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/Bindings/LuaState.cpp') diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 85e3f9fc5..63170660b 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -16,6 +16,8 @@ extern "C" #include "Bindings.h" #include "ManualBindings.h" #include "DeprecatedBindings.h" +#include "../Entities/Entity.h" +#include "../BlockEntities/BlockEntity.h" // fwd: SQLite/lsqlite3.c extern "C" @@ -556,7 +558,7 @@ void cLuaState::Push(cEntity * a_Entity) { ASSERT(IsValid()); - tolua_pushusertype(m_LuaState, a_Entity, "cEntity"); + tolua_pushusertype(m_LuaState, a_Entity, (a_Entity == nullptr) ? "cEntity" : a_Entity->GetClass()); m_NumCurrentFunctionArgs += 1; } -- cgit v1.2.3 From b0a59927fb7531f6c909e6f581035568c79b625c Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 19 Oct 2014 12:46:25 +0200 Subject: cLuaState: cBlockEntity descendants are pushed with proper class type. --- src/Bindings/LuaState.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Bindings/LuaState.cpp') diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 63170660b..49d643688 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -522,7 +522,7 @@ void cLuaState::Push(cBlockEntity * a_BlockEntity) { ASSERT(IsValid()); - tolua_pushusertype(m_LuaState, a_BlockEntity, "cBlockEntity"); + tolua_pushusertype(m_LuaState, a_BlockEntity, (a_BlockEntity == nullptr) ? "cBlockEntity" : a_BlockEntity->GetClass()); m_NumCurrentFunctionArgs += 1; } -- cgit v1.2.3 From d50bbf3899a1f28b23f98718e8acc76e294454a8 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 19 Oct 2014 12:49:54 +0200 Subject: cLuaState: cMonster descendants don't push their specific type. The individual mob types aren't exported to Lua, so pushing them would crash the server. --- src/Bindings/LuaState.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/Bindings/LuaState.cpp') diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 49d643688..2c4d89b01 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -558,7 +558,16 @@ void cLuaState::Push(cEntity * a_Entity) { ASSERT(IsValid()); - tolua_pushusertype(m_LuaState, a_Entity, (a_Entity == nullptr) ? "cEntity" : a_Entity->GetClass()); + if (a_Entity->IsMob()) + { + // Don't push specific mob types, as those are not exported in the API: + tolua_pushusertype(m_LuaState, a_Entity, "cMonster"); + } + else + { + // Push the specific class type: + tolua_pushusertype(m_LuaState, a_Entity, (a_Entity == nullptr) ? "cEntity" : a_Entity->GetClass()); + } m_NumCurrentFunctionArgs += 1; } -- cgit v1.2.3