summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/BLua.cc41
-rw-r--r--lib/lua/include/lua.h4
-rw-r--r--lib/lua/includes/lstate.h11
-rw-r--r--lib/lua/src/ldo.c9
-rw-r--r--lib/lua/src/lvm.c6
5 files changed, 62 insertions, 9 deletions
diff --git a/lib/BLua.cc b/lib/BLua.cc
index cf0caa4..1c125a2 100644
--- a/lib/BLua.cc
+++ b/lib/BLua.cc
@@ -17,16 +17,39 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: BLua.cc,v 1.19 2004-07-22 23:38:32 pixel Exp $ */
-
-#include <lualib.h>
+/* $Id: BLua.cc,v 1.20 2004-07-23 13:08:23 pixel Exp $ */
#include "BLua.h"
+#include <lualib.h>
#ifndef BUFFERSIZE
#define BUFFERSIZE 2048
#endif
+
+
+extern "C" {
+ void do_lua_lock(lua_State * _L) {
+ Lua * L;
+ try {
+ L = Lua::find(_L);
+ } catch (GeneralException e) {
+ return;
+ }
+ L->lock();
+ }
+
+ void do_lua_unlock(lua_State * _L) {
+ Lua * L;
+ try {
+ L = Lua::find(_L);
+ } catch (GeneralException e) {
+ return;
+ }
+ L->unlock();
+ }
+}
+
class LuaStatics : public Base {
public:
static const char * getF(lua_State *, void *, size_t *);
@@ -450,6 +473,14 @@ Lua * Lua::thread() {
return new Lua(lua_newthread(L));
}
+int Lua::yield(int nargs) {
+ return lua_yield(L, nargs);
+}
+
+int Lua::resume(int nresults) {
+ return lua_resume(L, nresults);
+}
+
Lua * Lua::find(lua_State * _L) throw (GeneralException) {
std::map<lua_State *, Lua *>::iterator i;
@@ -516,6 +547,10 @@ int Lua::sethook(lua_Hook func, int mask, int count) {
return lua_sethook(L, func, mask, count);
}
+void Lua::do_break() {
+ lua_break(L);
+}
+
void LuaObject::push(Lua * L) throw (GeneralException) {
if (pushed && wantdestruct) {
throw GeneralException("Error: object is owned by the LUA script and can not be pushed.");
diff --git a/lib/lua/include/lua.h b/lib/lua/include/lua.h
index f525a30..109b16e 100644
--- a/lib/lua/include/lua.h
+++ b/lib/lua/include/lua.h
@@ -1,5 +1,5 @@
/*
-** $Id: lua.h,v 1.3 2003-12-11 16:53:28 pixel Exp $
+** $Id: lua.h,v 1.4 2004-07-23 13:08:23 pixel Exp $
** Lua - An Extensible Extension Language
** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
** http://www.lua.org mailto:info@lua.org
@@ -222,6 +222,8 @@ LUA_API int lua_next (lua_State *L, int idx);
LUA_API void lua_concat (lua_State *L, int n);
+LUA_API void lua_break (lua_State *L);
+
/*
diff --git a/lib/lua/includes/lstate.h b/lib/lua/includes/lstate.h
index 6cebdfb..191cb45 100644
--- a/lib/lua/includes/lstate.h
+++ b/lib/lua/includes/lstate.h
@@ -1,5 +1,5 @@
/*
-** $Id: lstate.h,v 1.2 2003-12-11 16:53:29 pixel Exp $
+** $Id: lstate.h,v 1.3 2004-07-23 13:08:23 pixel Exp $
** Global State
** See Copyright Notice in lua.h
*/
@@ -24,12 +24,16 @@
** or when reading immutable fields from global objects
** (such as string values and udata values).
*/
+
+void do_lua_lock(lua_State *);
+void do_lua_unlock(lua_State *);
+
#ifndef lua_lock
-#define lua_lock(L) ((void) 0)
+#define lua_lock(L) do_lua_lock(L)
#endif
#ifndef lua_unlock
-#define lua_unlock(L) ((void) 0)
+#define lua_unlock(L) do_lua_unlock(L)
#endif
@@ -100,6 +104,7 @@ typedef struct CallInfo {
#define CI_CALLING (1<<2)
#define CI_SAVEDPC (1<<3) /* 1 if `savedpc' is updated */
#define CI_YIELD (1<<4) /* 1 if thread is suspended */
+#define CI_BREAK (1<<5) /* 1 if user break */
#define ci_func(ci) (clvalue((ci)->base - 1))
diff --git a/lib/lua/src/ldo.c b/lib/lua/src/ldo.c
index 2198c58..44bba83 100644
--- a/lib/lua/src/ldo.c
+++ b/lib/lua/src/ldo.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldo.c,v 1.2 2003-12-11 16:53:30 pixel Exp $
+** $Id: ldo.c,v 1.3 2004-07-23 13:08:23 pixel Exp $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@@ -391,6 +391,13 @@ LUA_API int lua_yield (lua_State *L, int nresults) {
return -1;
}
+LUA_API void lua_break (lua_State *L) {
+ CallInfo * ci;
+ lua_lock(L);
+ ci = L->ci;
+ ci->state |= CI_BREAK;
+ lua_unlock(L);
+}
int luaD_pcall (lua_State *L, Pfunc func, void *u,
ptrdiff_t old_top, ptrdiff_t ef) {
diff --git a/lib/lua/src/lvm.c b/lib/lua/src/lvm.c
index bc40f5c..3a8a974 100644
--- a/lib/lua/src/lvm.c
+++ b/lib/lua/src/lvm.c
@@ -1,5 +1,5 @@
/*
-** $Id: lvm.c,v 1.2 2003-12-11 16:53:30 pixel Exp $
+** $Id: lvm.c,v 1.3 2004-07-23 13:08:23 pixel Exp $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -421,6 +421,10 @@ StkId luaV_execute (lua_State *L) {
L->ci->state = CI_YIELD | CI_SAVEDPC;
return NULL;
}
+ if (L->ci->state & CI_BREAK) { /* did hook break? */
+ luaG_runerror(L, "breaking");
+ L->ci->state &= ~CI_BREAK;
+ }
}
/* warning!! several calls may realloc the stack and invalidate `ra' */
base = L->base;