aboutsummaryrefslogtreecommitdiff
path: root/lib/lua/src
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lua/src')
-rw-r--r--lib/lua/src/lapi.c12
-rw-r--r--lib/lua/src/ldo.c6
-rw-r--r--lib/lua/src/lstate.c1
-rw-r--r--lib/lua/src/lstate.h1
-rw-r--r--lib/lua/src/lua.h5
5 files changed, 24 insertions, 1 deletions
diff --git a/lib/lua/src/lapi.c b/lib/lua/src/lapi.c
index 5d5145d2e..383e65d60 100644
--- a/lib/lua/src/lapi.c
+++ b/lib/lua/src/lapi.c
@@ -137,6 +137,18 @@ LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) {
}
+/* MINETEST-SPECIFIC CHANGE */
+LUA_API lua_CFunctionwrapper lua_atccall (lua_State *L,
+ lua_CFunctionwrapper wrapf) {
+ lua_CFunctionwrapper old;
+ lua_lock(L);
+ old = G(L)->wrapcf;
+ G(L)->wrapcf = wrapf;
+ lua_unlock(L);
+ return old;
+}
+
+
LUA_API lua_State *lua_newthread (lua_State *L) {
lua_State *L1;
lua_lock(L);
diff --git a/lib/lua/src/ldo.c b/lib/lua/src/ldo.c
index d1bf786cb..57d2ac7c2 100644
--- a/lib/lua/src/ldo.c
+++ b/lib/lua/src/ldo.c
@@ -317,7 +317,11 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
if (L->hookmask & LUA_MASKCALL)
luaD_callhook(L, LUA_HOOKCALL, -1);
lua_unlock(L);
- n = (*curr_func(L)->c.f)(L); /* do the actual call */
+ /* MINETEST-SPECIFIC CHANGE: Let custom code wrap C function calls. */
+ if (G(L)->wrapcf)
+ n = G(L)->wrapcf(L, *curr_func(L)->c.f);
+ else
+ n = (*curr_func(L)->c.f)(L);
lua_lock(L);
if (n < 0) /* yielding? */
return PCRYIELD;
diff --git a/lib/lua/src/lstate.c b/lib/lua/src/lstate.c
index 4313b83a0..eced4a585 100644
--- a/lib/lua/src/lstate.c
+++ b/lib/lua/src/lstate.c
@@ -166,6 +166,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
setnilvalue(registry(L));
luaZ_initbuffer(L, &g->buff);
g->panic = NULL;
+ g->wrapcf = NULL; /* MINETEST-SPECIFIC CHANGE */
g->gcstate = GCSpause;
g->rootgc = obj2gco(L);
g->sweepstrgc = 0;
diff --git a/lib/lua/src/lstate.h b/lib/lua/src/lstate.h
index 3bc575b6b..c4364ea3f 100644
--- a/lib/lua/src/lstate.h
+++ b/lib/lua/src/lstate.h
@@ -86,6 +86,7 @@ typedef struct global_State {
int gcpause; /* size of pause between successive GCs */
int gcstepmul; /* GC `granularity' */
lua_CFunction panic; /* to be called in unprotected errors */
+ lua_CFunctionwrapper wrapcf; /* MINETEST-SPECIFIC CHANGE */
TValue l_registry;
struct lua_State *mainthread;
UpVal uvhead; /* head of double-linked list of all open upvalues */
diff --git a/lib/lua/src/lua.h b/lib/lua/src/lua.h
index a4b73e743..1d7fe927f 100644
--- a/lib/lua/src/lua.h
+++ b/lib/lua/src/lua.h
@@ -113,6 +113,11 @@ LUA_API lua_State *(lua_newthread) (lua_State *L);
LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
+/* MINETEST-SPECIFIC CHANGE: Let custom code wrap C function calls. */
+typedef int (*lua_CFunctionwrapper)(lua_State *L, lua_CFunction f);
+LUA_API lua_CFunctionwrapper (lua_atccall) (lua_State *L,
+ lua_CFunctionwrapper wrapf);
+
/*
** basic stack manipulation