1
0
Fork 0

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.
This commit is contained in:
Mattes D 2014-10-19 11:46:38 +02:00
parent fe153cc763
commit ebd31ff132
2 changed files with 8 additions and 6 deletions

View File

@ -16,6 +16,8 @@ extern "C"
#include "Bindings.h" #include "Bindings.h"
#include "ManualBindings.h" #include "ManualBindings.h"
#include "DeprecatedBindings.h" #include "DeprecatedBindings.h"
#include "../Entities/Entity.h"
#include "../BlockEntities/BlockEntity.h"
// fwd: SQLite/lsqlite3.c // fwd: SQLite/lsqlite3.c
extern "C" extern "C"
@ -556,7 +558,7 @@ void cLuaState::Push(cEntity * a_Entity)
{ {
ASSERT(IsValid()); 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; m_NumCurrentFunctionArgs += 1;
} }

View File

@ -172,13 +172,13 @@ public:
/// Returns true if the entity is of the specified class or a subclass (cPawn's IsA("cEntity") returns true) /// Returns true if the entity is of the specified class or a subclass (cPawn's IsA("cEntity") returns true)
virtual bool IsA(const char * a_ClassName) const; virtual bool IsA(const char * a_ClassName) const;
/// Returns the topmost class name for the object /** Returns the class name of this class */
virtual const char * GetClass(void) const;
// Returns the class name of this class
static const char * GetClassStatic(void); static const char * GetClassStatic(void);
/// Returns the topmost class's parent class name for the object. cEntity returns an empty string (no parent). /** Returns the topmost class name for the object */
virtual const char * GetClass(void) const;
/** Returns the topmost class's parent class name for the object. cEntity returns an empty string (no parent). */
virtual const char * GetParentClass(void) const; virtual const char * GetParentClass(void) const;
cWorld * GetWorld(void) const { return m_World; } cWorld * GetWorld(void) const { return m_World; }