summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpixel <pixel>2006-02-09 16:59:55 +0000
committerpixel <pixel>2006-02-09 16:59:55 +0000
commitffaee8f1a04b5c3616f27118b426ce727294868c (patch)
treec568807d05a14ed91fd7036a6943dc6054e29626
parent16c41f2f9f1d86d861254ef54becbd2bd728f848 (diff)
Adding thread creation/destruction hooks.
-rw-r--r--lib/lua/include/lua.h5
-rw-r--r--lib/lua/includes/lstate.h3
-rw-r--r--lib/lua/src/ldebug.c22
-rw-r--r--lib/lua/src/lstate.c8
4 files changed, 34 insertions, 4 deletions
diff --git a/lib/lua/include/lua.h b/lib/lua/include/lua.h
index 10496ec..9a28d9e 100644
--- a/lib/lua/include/lua.h
+++ b/lib/lua/include/lua.h
@@ -1,5 +1,5 @@
/*
-** $Id: lua.h,v 1.8 2004-12-27 22:18:52 pixel Exp $
+** $Id: lua.h,v 1.9 2006-02-09 16:59:55 pixel Exp $
** Lua - An Extensible Extension Language
** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
** http://www.lua.org mailto:info@lua.org
@@ -336,6 +336,7 @@ typedef struct lua_Debug lua_Debug; /* activation record */
typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
typedef int (*lua_CallWrap) (lua_State *L, lua_CFunction func);
+typedef void (*lua_ThreadHook) (lua_State *L, lua_State *L1);
LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar);
@@ -351,6 +352,8 @@ LUA_API int lua_gethookmask (lua_State *L);
LUA_API int lua_gethookcount (lua_State *L);
LUA_API lua_CallWrap lua_setcallwrap (lua_State *L, lua_CallWrap func);
+LUA_API lua_ThreadHook lua_setcreatehook (lua_State *L, lua_ThreadHook func);
+LUA_API lua_ThreadHook lua_setdestroyhook (lua_State *L, lua_ThreadHook func);
#define LUA_IDSIZE 60
diff --git a/lib/lua/includes/lstate.h b/lib/lua/includes/lstate.h
index 8df9844..bd5c1d9 100644
--- a/lib/lua/includes/lstate.h
+++ b/lib/lua/includes/lstate.h
@@ -1,5 +1,5 @@
/*
-** $Id: lstate.h,v 1.6 2004-12-27 22:18:53 pixel Exp $
+** $Id: lstate.h,v 1.7 2006-02-09 16:59:55 pixel Exp $
** Global State
** See Copyright Notice in lua.h
*/
@@ -158,6 +158,7 @@ struct lua_State {
struct lua_longjmp *errorJmp; /* current error recover point */
ptrdiff_t errfunc; /* current error handling function (stack index) */
lua_CallWrap callwrap;
+ lua_ThreadHook createhook, destroyhook;
};
diff --git a/lib/lua/src/ldebug.c b/lib/lua/src/ldebug.c
index b154c1b..4f69bad 100644
--- a/lib/lua/src/ldebug.c
+++ b/lib/lua/src/ldebug.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldebug.c,v 1.5 2004-12-27 22:18:53 pixel Exp $
+** $Id: ldebug.c,v 1.6 2006-02-09 16:59:55 pixel Exp $
** Debug Interface
** See Copyright Notice in lua.h
*/
@@ -101,6 +101,26 @@ LUA_API lua_CallWrap lua_setcallwrap (lua_State *L, lua_CallWrap func) {
}
+LUA_API lua_ThreadHook lua_setcreatehook (lua_State *L, lua_ThreadHook func) {
+ lua_ThreadHook old_func;
+ lua_lock(L);
+ old_func = L->createhook;
+ L->createhook = func;
+ lua_unlock(L);
+ return old_func;
+}
+
+
+LUA_API lua_ThreadHook lua_setdestroyhook (lua_State *L, lua_ThreadHook func) {
+ lua_ThreadHook old_func;
+ lua_lock(L);
+ old_func = L->destroyhook;
+ L->destroyhook = func;
+ lua_unlock(L);
+ return old_func;
+}
+
+
LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {
int status;
CallInfo *ci;
diff --git a/lib/lua/src/lstate.c b/lib/lua/src/lstate.c
index 113a69b..a2618a5 100644
--- a/lib/lua/src/lstate.c
+++ b/lib/lua/src/lstate.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstate.c,v 1.5 2004-12-27 22:18:53 pixel Exp $
+** $Id: lstate.c,v 1.6 2006-02-09 16:59:55 pixel Exp $
** Global State
** See Copyright Notice in lua.h
*/
@@ -138,6 +138,8 @@ static void preinit_state (lua_State *L) {
L->base_ci = L->ci = NULL;
L->errfunc = 0;
L->callwrap = 0;
+ L->createhook = 0;
+ L->destroyhook = 0;
setnilvalue(gt(L));
}
@@ -167,11 +169,15 @@ lua_State *luaE_newthread (lua_State *L) {
L1->l_G = L->l_G;
stack_init(L1, L); /* init stack */
setobj2n(gt(L1), gt(L)); /* share table of globals */
+ if (L->createhook)
+ L->createhook(L, L1);
return L1;
}
void luaE_freethread (lua_State *L, lua_State *L1) {
+ if (L->destroyhook)
+ L->destroyhook(L, L1);
luaF_close(L1, L1->stack); /* close all upvalues for this thread */
lua_assert(L1->openupval == NULL);
freestack(L, L1);