summaryrefslogtreecommitdiff
path: root/src
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 /src
parent11478487e7b3eb24dccb829aa201c3358cfc7e68 (diff)
Working / cleaning a bit the Lua class.
Diffstat (limited to 'src')
-rw-r--r--src/BLua.cc47
1 files changed, 31 insertions, 16 deletions
diff --git a/src/BLua.cc b/src/BLua.cc
index 2f0a5c4..4c52c7c 100644
--- a/src/BLua.cc
+++ b/src/BLua.cc
@@ -232,7 +232,7 @@ int Balau::LuaStatics::collector(lua_State * __L) {
Lua L(__L);
ObjData * u = (ObjData *) L.touserdata();
if (u->isObj) {
- LuaExport * obj = (LuaExport *) u->ptr;
+ LuaObjectFactory * obj = (LuaObjectFactory *) u->ptr;
delete obj;
} else {
free(u->ptr);
@@ -247,7 +247,7 @@ int Balau::LuaStatics::destructor(lua_State * __L) {
L.gettable(-2, true);
ObjData * u = (ObjData *) L.touserdata();
if (u->isObj) {
- LuaExport * obj = (LuaExport *) u->ptr;
+ LuaObjectFactory * obj = (LuaObjectFactory *) u->ptr;
delete obj;
} else {
free(u->ptr);
@@ -273,6 +273,25 @@ Balau::Lua::Lua() : L(lua_open()) {
settable(LUA_REGISTRYINDEX);
}
+Balau::Lua & Balau::Lua::operator=(Lua && oL) {
+ if (this == &oL)
+ return *this;
+
+ AAssert(!L, "Can't assign a Lua VM to another one.");
+
+ L = oL.L;
+ oL.L = NULL;
+
+ return *this;
+}
+
+void Balau::Lua::close() {
+ AAssert(L, "Can't close an already closed VM");
+
+ lua_close(L);
+ L = NULL;
+}
+
#define IntPoint(p) ((unsigned int)(lu_mem)(p))
typedef size_t lu_mem;
@@ -676,15 +695,13 @@ Balau::Lua Balau::Lua::thread(bool saveit) {
}
Balau::Lua Balau::Lua::thread(const String & code, int nargs, bool saveit) {
- Lua L1;
- L1 = thread(saveit);
+ Lua L1 = thread(saveit);
L1.resume(code, nargs);
return L1;
}
Balau::Lua Balau::Lua::thread(IO<Handle> h, int nargs, bool saveit) {
- Lua L1;
- L1 = thread(saveit);
+ Lua L1 = thread(saveit);
L1.resume(h, nargs);
return L1;
}
@@ -783,15 +800,14 @@ void Balau::Lua::showerror() {
showstack(M_ERROR);
}
-void Balau::LuaObject::push(Lua & L) throw (GeneralException) {
- if (m_pushed && m_wantsDestruct)
- throw GeneralException("Error: object is owned by the LUA script and can not be pushed.");
+void Balau::LuaObjectFactory::push(Lua & L) {
+ AAssert(!(m_pushed && m_wantsDestruct), "Error: object is owned by the LUA script and can not be pushed.");
L.newtable();
pushMembers(L);
m_pushed = true;
}
-void Balau::LuaObject::pushMe(Lua & L, void * o, const char * objname, bool obj) {
+void Balau::LuaObjectFactory::pushMe(Lua & L, void * o, const char * objname, bool obj) {
ObjData * u;
L.push("__obj");
u = (ObjData *) L.newuser(sizeof(ObjData));
@@ -805,7 +821,7 @@ void Balau::LuaObject::pushMe(Lua & L, void * o, const char * objname, bool obj)
}
}
-void * Balau::LuaObject::getMeInternal(Lua & L, int i) {
+void * Balau::LuaObjectFactory::getMeInternal(Lua & L, int i) {
ObjData * u = NULL;
if (L.istable(i)) {
@@ -825,13 +841,13 @@ void * Balau::LuaObject::getMeInternal(Lua & L, int i) {
return u ? u->ptr : NULL;
}
-void Balau::LuaObject::pushIt(Lua & L, const char * s, lua_CFunction f) {
+void Balau::LuaObjectFactory::pushIt(Lua & L, const char * s, lua_CFunction f) {
L.push(s);
L.push(f);
L.settable(-3, true);
}
-void Balau::LuaObject::pushMeta(Lua & L, const char * s, lua_CFunction f) {
+void Balau::LuaObjectFactory::pushMeta(Lua & L, const char * s, lua_CFunction f) {
if (!L.getmetatable())
L.newtable();
L.push(s);
@@ -840,9 +856,8 @@ void Balau::LuaObject::pushMeta(Lua & L, const char * s, lua_CFunction f) {
L.setmetatable();
}
-void Balau::LuaObject::pushDestruct(Lua & L) throw (GeneralException) {
- if (m_pushed)
- throw GeneralException("Error: can't push destructor, object already pushed");
+void Balau::LuaObjectFactory::pushDestruct(Lua & L) {
+ AAssert(!m_pushed, "Error: can't push destructor, object already pushed");
push(L);
L.push("__obj");
L.gettable(-2, true);