summaryrefslogtreecommitdiff
path: root/includes/BLua.h
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2012-03-29 08:44:48 -0700
committerPixel <pixel@nobis-crew.org>2012-03-29 08:44:48 -0700
commit01e69854c5445ea1ae73cfc0f386d1a7c7b687f3 (patch)
tree5d8b7a6e500de6e8c9fa055001d7754b08207b61 /includes/BLua.h
parent11478487e7b3eb24dccb829aa201c3358cfc7e68 (diff)
Working / cleaning a bit the Lua class.
Diffstat (limited to 'includes/BLua.h')
-rw-r--r--includes/BLua.h36
1 files changed, 21 insertions, 15 deletions
diff --git a/includes/BLua.h b/includes/BLua.h
index fe84db9..be78660 100644
--- a/includes/BLua.h
+++ b/includes/BLua.h
@@ -1,7 +1,5 @@
#pragma once
-#include <typeinfo>
-
extern "C" {
#include <lua.h>
#include <lauxlib.h>
@@ -14,16 +12,16 @@ namespace Balau {
class Lua;
-class LuaExport {
+class LuaObject {
public:
- virtual ~LuaExport() { }
+ virtual ~LuaObject() { }
};
-class LuaObject {
+class LuaObjectFactory {
public:
- LuaObject() : m_wantsDestruct(false), m_pushed(false) { }
- virtual void push(Lua & L) throw (GeneralException);
- void pushDestruct(Lua & L) throw (GeneralException);
+ LuaObjectFactory() : m_wantsDestruct(false), m_pushed(false) { }
+ virtual void push(Lua & L);
+ void pushDestruct(Lua & L);
template<class T>
static T * getMe(Lua & L, int idx = 1);
protected:
@@ -35,6 +33,8 @@ class LuaObject {
friend class Lua;
private:
bool m_wantsDestruct, m_pushed;
+ LuaObjectFactory & operator=(const LuaObjectFactory &) = delete;
+ LuaObjectFactory(const LuaObjectFactory &) = delete;
};
typedef int (*openlualib_t)(lua_State * L);
@@ -43,13 +43,16 @@ class Lua {
public:
Lua();
Lua(lua_State * __L) : L(__L) { }
- Lua(const Lua &) throw (GeneralException) { throw GeneralException("Error: can't duplicate a Lua object."); }
+ Lua(Lua && oL) : L(oL.L) { oL.L = NULL; }
+
+ Lua & operator=(Lua && oL);
typedef int (*lua_CallWrapper)(lua_State *, lua_CFunction);
int ref(int t = -2) { return luaL_ref(L, t); }
void unref(int ref, int t = -1) { luaL_unref(L, t, ref); }
+ void close();
void open_base();
void open_table();
void open_string();
@@ -132,17 +135,17 @@ class Lua {
template<class T>
T * recast(int n = 1) {
- LuaExport * b;
+ LuaObject * b;
T * r;
- b = (LuaExport *) LuaObject::getMeInternal(*this, n);
+ b = (LuaObject *) LuaObjectFactory::getMeInternal(*this, n);
if (!b)
- error("LuaExport base object required; got null.");
+ error("LuaObject base object required; got null.");
r = dynamic_cast<T *>(b);
if (!r)
- error(String("Object not compatible; expecting ") + typeid(r).name() + " but got *" + typeid(*b).name() + " instead.");
+ error(String("Object not compatible; expecting ") + ClassName(r).c_str() + " but got *" + ClassName(b).c_str() + " instead.");
return r;
}
@@ -156,6 +159,9 @@ class Lua {
lua_State * L;
friend class LuaStatics;
+
+ Lua & operator=(const Lua &) = delete;
+ Lua(const Lua &) = delete;
};
class LuaException : public GeneralException {
@@ -249,7 +255,7 @@ struct lua_functypes_t {
}
template <class T>
-T * LuaObject::getMe(Lua & L, int idx) { return L.recast<T>(idx); }
+T * LuaObjectFactory::getMe(Lua & L, int idx) { return L.recast<T>(idx); }
template <class T>
class LuaHelpers {
@@ -263,7 +269,7 @@ class LuaHelpers {
bool invalid = false, arg_valid;
if (method)
- obj = LuaObject::getMe<T>(L);
+ obj = LuaObjectFactory::getMe<T>(L);
if ((n < tab[caller].minargs) || (n > tab[caller].maxargs)) {
invalid = true;