Some performance and warning fixes

This commit is contained in:
Rochet2
2016-01-05 14:57:29 +02:00
parent 3f3de007ef
commit 972ff3d010
3 changed files with 60 additions and 45 deletions

View File

@@ -66,10 +66,8 @@ public:
class ElunaObject
{
public:
ElunaObject(void* obj, bool manageMemory) : _isvalid(false), _invalidate(!manageMemory), object(obj)
{
SetValid(true);
}
template<typename T>
ElunaObject::ElunaObject(T * obj, bool manageMemory);
~ElunaObject()
{
@@ -81,6 +79,8 @@ public:
bool IsValid() const { return _isvalid; }
// Returns whether the object can be invalidated or not
bool CanInvalidate() const { return _invalidate; }
// Returns pointer to the wrapped object's type name
const char* GetTypeName() const { return type_name; }
// Sets the object pointer that is wrapped
void SetObj(void* obj)
@@ -111,6 +111,7 @@ private:
bool _isvalid;
bool _invalidate;
void* object;
const char* type_name;
};
template<typename T>
@@ -288,7 +289,7 @@ public:
lua_pushnil(L);
return 1;
}
*ptrHold = new ElunaObject(obj_voidptr, manageMemory);
*ptrHold = new ElunaObject(const_cast<T*>(obj), manageMemory);
// Set metatable for it
lua_getglobal(L, tname);
@@ -404,4 +405,10 @@ public:
static int Call(lua_State* L) { return luaL_error(L, "attempt to call a %s value", tname); }
};
template<typename T>
ElunaObject::ElunaObject(T * obj, bool manageMemory) : _isvalid(false), _invalidate(!manageMemory), object(obj), type_name(ElunaTemplate<T>::tname)
{
SetValid(true);
}
#endif