diff options
Diffstat (limited to 'lib/BLua.cc')
-rw-r--r-- | lib/BLua.cc | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/lib/BLua.cc b/lib/BLua.cc index 99c02d8..fab7a2f 100644 --- a/lib/BLua.cc +++ b/lib/BLua.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: BLua.cc,v 1.52 2007-07-12 11:31:30 pixel Exp $ */ +/* $Id: BLua.cc,v 1.53 2007-07-27 10:05:52 pixel Exp $ */ #include <stdlib.h> #include "BLua.h" @@ -463,7 +463,7 @@ Lua * Lua::spawn_from_thread(lua_State * __L) { Lua::~Lua() { if (!_is_thread) { - lua_setgcthreshold(L, 0); +// lua_setgcthreshold(L, 0); lua_close(L); } else { push(); // -1 = nil @@ -584,8 +584,10 @@ void Lua::call(int nargs, int nresults) throw(GeneralException) { throw LuaException("Memory allocation error while running LUA code."); case LUA_ERRERR: throw LuaException("Error in Error function."); + case LUA_ERRSYNTAX: + throw LuaException("Syntax error in Lua code."); default: - throw LuaException("Unknow error while running LUA code."); + throw LuaException("Unknow error while running LUA code (err code: " + String(r) + ")"); } } @@ -829,8 +831,8 @@ struct DumpF { int LuaStatics::putF(lua_State * L, const void * p, size_t size, void * ud) { DumpF *lf = (DumpF *)ud; (void)L; - - return lf->f->write(p, size) == size; + + return (lf->f->write(p, size) != size) && (size != 0); } String Lua::escape_string(const String & s) { @@ -901,14 +903,14 @@ void Lua::load(const String & s, bool docall) throw (GeneralException) { } } -extern "C" void luacmain(lua_State * L, int stripping, lua_Chunkwriter w, void * uD); +extern "C" void luacmain(lua_State * L, int stripping, lua_Chunkwriter w, void * uD, int listing); -void Lua::dump(Handle * h, bool strip) { +void Lua::dump(Handle * h, bool strip, int listing) { DumpF lf; lf.f = h; - luacmain(L, strip, LuaStatics::putF, &lf); + luacmain(L, strip, LuaStatics::putF, &lf, listing); } void Lua::dumpvars(Handle * h, const String & prefix, int i) { @@ -1067,7 +1069,7 @@ int Lua::yield(int nresults) { return lua_yield(L, nresults); } -void Lua::resume(int nargs) throw (GeneralException) { +bool Lua::resume(int nargs) throw (GeneralException) { int r; lock(); @@ -1075,7 +1077,7 @@ void Lua::resume(int nargs) throw (GeneralException) { r = lua_resume(L, nargs); _protected = false; - if (r != 0) { + if ((r != 0) && (r != LUA_YIELD)) { push_lua_context(); showerror(); } @@ -1084,30 +1086,42 @@ void Lua::resume(int nargs) throw (GeneralException) { switch(r) { case 0: - return; + return false; + case LUA_YIELD: + return true; case LUA_ERRRUN: throw LuaException("Runtime error while running LUA code."); case LUA_ERRMEM: throw LuaException("Memory allocation error while running LUA code."); case LUA_ERRERR: throw LuaException("Error in Error function."); + case LUA_ERRSYNTAX: + throw LuaException("Syntax error in Lua code."); default: - throw LuaException("Unknow error while running LUA code."); + throw LuaException("Unknow error while running LUA code (err code: " + String(r) + ")"); } } -void Lua::resume(Handle * h, int nargs) { +bool Lua::resume(Handle * h, int nargs) { + bool r; + lock(); load(h, false); - resume(nargs); + r = resume(nargs); unlock(); + + return r; } -void Lua::resume(const String & s, int nargs) { +bool Lua::resume(const String & s, int nargs) { + bool r; + lock(); load(s, false); - resume(nargs); + r = resume(nargs); unlock(); + + return r; } Lua * Lua::find(lua_State * __L) throw (GeneralException) { @@ -1194,11 +1208,11 @@ void Lua::openlib(const String & libname, const luaL_reg *l, int nup) { } void Lua::setgcthreshold(int newthreshold) { - lua_setgcthreshold(L, newthreshold); +// lua_setgcthreshold(L, newthreshold); } int Lua::getgcthreshold() { - return lua_getgcthreshold(L); +// return lua_getgcthreshold(L); } int Lua::getgccount() { |