From 1f97ba72e51f52f351137550239e9dae7f743fc7 Mon Sep 17 00:00:00 2001 From: pixel Date: Thu, 9 Feb 2006 17:08:24 +0000 Subject: In general: better thread handling. Added locks everywhere it should. Added/fixed thread spawning stuff. Also, added Lua's methods: -) copy -) setgcthreshold -) getgcthreshold -) getgccount --- include/BLua.h | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/BLua.h b/include/BLua.h index 77c3a9d..9fa4248 100644 --- a/include/BLua.h +++ b/include/BLua.h @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: BLua.h,v 1.27 2006-01-31 17:02:38 pixel Exp $ */ +/* $Id: BLua.h,v 1.28 2006-02-09 17:08:24 pixel Exp $ */ #ifndef __BLUA_H__ #define __BLUA_H__ @@ -33,6 +33,7 @@ extern "C" { #define lua_unlock(L) do_lua_unlock(L) #include +#include #include #include #include @@ -66,6 +67,7 @@ class Lua : public Base { void push(void *); void push(lua_CFunction, int = 0); void pop(int = 1); + void copy(int = -1); void newtable(); void * newuser(size_t); void settable(int = -3, bool raw = false); @@ -94,11 +96,16 @@ class Lua : public Base { Lua * tothread(int = -1); String escape_string(const String &); void load(Handle *, bool docall = true) throw (GeneralException); + void load(const String &, bool docall = true) throw (GeneralException); void dump(Handle *, bool strip = true); void dumpvars(Handle *, const String &, int = -1); - Lua * thread(); - int yield(int nargs = 0); - int resume(int nresults = 0); + Lua * thread(bool saveit = true); + Lua * thread(const String &, int nargs = 0, bool saveit = true); + Lua * thread(Handle *, int nargs = 0, bool saveit = true); + int yield(int nresults = 0); + void resume(int nargs = 0) throw (GeneralException); + void resume(const String &, int nargs = 0); + void resume(Handle *, int nargs = 0); static Lua * find(lua_State *) throw (GeneralException); void showerror(); int getmetatable(int = -1); @@ -107,16 +114,28 @@ class Lua : public Base { void do_break(); - virtual void lock() {} - virtual void unlock() {} + virtual void lock(); + virtual void unlock(); bool is_protected(); - private: + void openlib(const String & libname, const struct luaL_reg *l, int nup); + + void setgcthreshold(int = 0); + int getgcthreshold(); + int getgccount(); + + protected: + virtual Lua * spawn_from_thread(lua_State *); Lua(lua_State *); + + private: + void setup_state(lua_State *); lua_State * L; static std::map lualist; - bool _protected; + bool _protected, _is_thread; void dumpvars_r(Handle *, int, int = 0) throw (GeneralException); + + friend class LuaStatics; }; class LuaObject : public Base { -- cgit v1.2.3