summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/BLua.h3
-rw-r--r--includes/BigInt.h2
-rw-r--r--includes/LuaHandle.h22
-rw-r--r--src/BLua.cc16
-rw-r--r--src/LuaHandle.cc8
-rw-r--r--tests/test-Lua.cc1
6 files changed, 27 insertions, 25 deletions
diff --git a/includes/BLua.h b/includes/BLua.h
index b5c147a..d0541f6 100644
--- a/includes/BLua.h
+++ b/includes/BLua.h
@@ -35,8 +35,9 @@ class DeferredCollector : public StacklessTask {
virtual const char * getName() const override { return "DeferredCollector"; }
virtual void Do() override {
StacklessBegin();
- StacklessOperation(delete m_obj);
+ StacklessOperation(m_obj->cleanup());
StacklessEnd();
+ delete m_obj;
}
private:
T * m_obj;
diff --git a/includes/BigInt.h b/includes/BigInt.h
index 3a31b2e..bc956bd 100644
--- a/includes/BigInt.h
+++ b/includes/BigInt.h
@@ -118,6 +118,8 @@ class BigInt {
String toString(int radix = 10) const;
char * makeString(int radix = 10) const;
+ void cleanup() { }
+
private:
void * m_bi = NULL;
};
diff --git a/includes/LuaHandle.h b/includes/LuaHandle.h
index fcde496..b67d084 100644
--- a/includes/LuaHandle.h
+++ b/includes/LuaHandle.h
@@ -6,23 +6,33 @@
namespace Balau {
+class LuaIO {
+ public:
+ LuaIO(IO<Handle> h) : m_h(h) { }
+ LuaIO(const LuaIO & lio) : m_h(lio.m_h) { }
+ IO<Handle> getIO() { return m_h; }
+ void cleanup() { m_h->close(); }
+ private:
+ IO<Handle> m_h;
+};
+
class LuaHandleFactory : public LuaObjectFactory {
public:
- LuaHandleFactory(IO<Handle> h) : m_obj(new IO<Handle>(h)) { }
+ LuaHandleFactory(IO<Handle> h) : m_obj(new LuaIO(h)) { }
static void pushStatics(Lua & L);
protected:
- LuaHandleFactory(IO<Handle> * h) : m_obj(h) { }
- void pushObjectAndMembers(Lua & L);
+ LuaHandleFactory(LuaIO * h) : m_obj(h) { }
+ virtual void pushObjectAndMembers(Lua & L) override;
private:
- IO<Handle> * m_obj;
+ LuaIO * m_obj;
};
class LuaInputFactory : public LuaHandleFactory {
public:
- LuaInputFactory(IO<Input> h) : LuaHandleFactory(new IO<Handle>(h)) { }
+ LuaInputFactory(IO<Input> h) : LuaHandleFactory(h) { }
static void pushStatics(Lua & L);
private:
- void pushObjectAndMembers(Lua & L);
+ virtual void pushObjectAndMembers(Lua & L) override;
};
void registerLuaHandle(Lua &);
diff --git a/src/BLua.cc b/src/BLua.cc
index f70cf99..55daa3f 100644
--- a/src/BLua.cc
+++ b/src/BLua.cc
@@ -11,6 +11,7 @@
#include "HelperTasks.h"
#include "StacklessTask.h"
#include "TaskMan.h"
+#include "LuaHandle.h"
extern "C" {
#include <lualib.h>
@@ -98,7 +99,7 @@ int Balau::LuaStatics::dumpvars(lua_State * __L) {
if (L.isstring(2))
L.getglobal(L.tostring(2).to_charp());
- IO<Handle> h(L.recast<Balau::Handle>());
+ IO<Handle> h(L.recast<LuaIO>()->getIO());
if (!h->canEAgainOnWrite()) {
L.dumpvars(h, prefix);
@@ -312,19 +313,6 @@ int Balau::LuaStatics::callwrap(lua_State * __L, lua_CFunction func) {
return r;
}
-namespace {
-
-class CollectorTask : public Balau::StacklessTask {
- public:
- CollectorTask(Balau::LuaObjectBase * obj) : m_obj(obj) { }
- private:
- virtual const char * getName() const override { return "CollectorTask"; }
- virtual void Do() override { delete m_obj; }
- Balau::LuaObjectBase * m_obj;
-};
-
-};
-
int Balau::LuaStatics::collector(lua_State * __L) {
Lua L(__L);
LuaObjectBase * o = (LuaObjectBase *) L.touserdata();
diff --git a/src/LuaHandle.cc b/src/LuaHandle.cc
index 440a4f3..6ee6691 100644
--- a/src/LuaHandle.cc
+++ b/src/LuaHandle.cc
@@ -2,8 +2,8 @@
#include "LuaBigInt.h"
#include "Handle.h"
-typedef Balau::IO<Balau::Handle> IOHandle;
-typedef IOHandle IOInput;
+typedef Balau::LuaIO IOHandle;
+typedef Balau::LuaIO IOInput;
// Handle exports
@@ -102,7 +102,7 @@ struct sLua_IOHandle {
int sLua_IOHandle::IOHandle_proceed(Balau::Lua & L, int n, IOHandle * obj, int caller) {
int r = 0;
- Balau::IO<Balau::Handle> h = *obj;
+ Balau::IO<Balau::Handle> h = obj->getIO();
switch (caller) {
case IOHANDLE_CLOSE:
@@ -538,7 +538,7 @@ int sLua_IOInput::IOInput_proceed_static(Balau::Lua & L, int n, int caller) {
}
int sLua_IOInput::IOInput_proceed(Balau::Lua & L, int n, IOInput * obj, int caller) {
- Balau::IO<Balau::Input> h = *obj;
+ Balau::IO<Balau::Input> h = obj->getIO();
switch (caller) {
case IOINPUT_OPEN:
diff --git a/tests/test-Lua.cc b/tests/test-Lua.cc
index bffbfaa..48a87fc 100644
--- a/tests/test-Lua.cc
+++ b/tests/test-Lua.cc
@@ -18,6 +18,7 @@ class ObjectTest {
int someMethod2(int p) { Printer::log(M_DEBUG, "ObjectTest::someMethod2() called on %p.", this); callCount++; return p * 2; }
static void someFunction() { Printer::log(M_DEBUG, "ObjectTest::someFunction() called."); callCount++; }
static void someStatic() { Printer::log(M_DEBUG, "ObjectTest::someStatic() called."); callCount++; }
+ void cleanup() { }
};
enum ObjectTest_methods_t {