From 2a2c2e97a9be9fc4db30842ad61e46a1fd7cd125 Mon Sep 17 00:00:00 2001 From: Nicolas Noble Date: Mon, 11 Aug 2014 11:53:25 -0700 Subject: Bugs fixing in Lua - we really can't afford to have destructors throwing exceptions, and also making sure we're using the proper types for Handles. --- includes/BLua.h | 3 ++- includes/BigInt.h | 2 ++ includes/LuaHandle.h | 22 ++++++++++++++++------ 3 files changed, 20 insertions(+), 7 deletions(-) (limited to 'includes') 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 h) : m_h(h) { } + LuaIO(const LuaIO & lio) : m_h(lio.m_h) { } + IO getIO() { return m_h; } + void cleanup() { m_h->close(); } + private: + IO m_h; +}; + class LuaHandleFactory : public LuaObjectFactory { public: - LuaHandleFactory(IO h) : m_obj(new IO(h)) { } + LuaHandleFactory(IO h) : m_obj(new LuaIO(h)) { } static void pushStatics(Lua & L); protected: - LuaHandleFactory(IO * h) : m_obj(h) { } - void pushObjectAndMembers(Lua & L); + LuaHandleFactory(LuaIO * h) : m_obj(h) { } + virtual void pushObjectAndMembers(Lua & L) override; private: - IO * m_obj; + LuaIO * m_obj; }; class LuaInputFactory : public LuaHandleFactory { public: - LuaInputFactory(IO h) : LuaHandleFactory(new IO(h)) { } + LuaInputFactory(IO h) : LuaHandleFactory(h) { } static void pushStatics(Lua & L); private: - void pushObjectAndMembers(Lua & L); + virtual void pushObjectAndMembers(Lua & L) override; }; void registerLuaHandle(Lua &); -- cgit v1.2.3