Skip to content

Commit 2086e13

Browse files
committed
hack lua to support signal
1 parent f36b173 commit 2086e13

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Diff for: 3rd/lua/lua.h

+5
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,11 @@ struct lua_Debug {
458458

459459
/* }====================================================================== */
460460

461+
/* Add by skynet */
462+
463+
LUA_API lua_State * skynet_sig_L;
464+
LUA_API void (lua_checksig_)(lua_State *L);
465+
#define lua_checksig(L) if (skynet_sig_L) { lua_checksig_(L); }
461466

462467
/******************************************************************************
463468
* Copyright (C) 1994-2015 Lua.org, PUC-Rio.

Diff for: 3rd/lua/lvm.c

+15-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,17 @@
6363

6464
#endif
6565

66-
66+
/* Add by skynet */
67+
lua_State * skynet_sig_L = NULL;
68+
69+
LUA_API void
70+
lua_checksig_(lua_State *L) {
71+
if (skynet_sig_L == G(L)->mainthread) {
72+
skynet_sig_L = NULL;
73+
lua_pushnil(L);
74+
lua_error(L);
75+
}
76+
}
6777

6878
/*
6979
** Try to convert a value to a float. The float case is already handled
@@ -1028,6 +1038,7 @@ void luaV_execute (lua_State *L) {
10281038
vmbreak;
10291039
}
10301040
vmcase(OP_JMP) {
1041+
lua_checksig(L);
10311042
dojump(ci, i, 0);
10321043
vmbreak;
10331044
}
@@ -1080,6 +1091,7 @@ void luaV_execute (lua_State *L) {
10801091
vmcase(OP_CALL) {
10811092
int b = GETARG_B(i);
10821093
int nresults = GETARG_C(i) - 1;
1094+
lua_checksig(L);
10831095
if (b != 0) L->top = ra+b; /* else previous instruction set top */
10841096
if (luaD_precall(L, ra, nresults)) { /* C function? */
10851097
if (nresults >= 0) L->top = ci->top; /* adjust results */
@@ -1094,6 +1106,7 @@ void luaV_execute (lua_State *L) {
10941106
}
10951107
vmcase(OP_TAILCALL) {
10961108
int b = GETARG_B(i);
1109+
lua_checksig(L);
10971110
if (b != 0) L->top = ra+b; /* else previous instruction set top */
10981111
lua_assert(GETARG_C(i) - 1 == LUA_MULTRET);
10991112
if (luaD_precall(L, ra, LUA_MULTRET)) /* C function? */
@@ -1203,6 +1216,7 @@ void luaV_execute (lua_State *L) {
12031216
}
12041217
vmcase(OP_TFORLOOP) {
12051218
l_tforloop:
1219+
lua_checksig(L);
12061220
if (!ttisnil(ra + 1)) { /* continue loop? */
12071221
setobjs2s(L, ra, ra + 1); /* save control variable */
12081222
ci->u.l.savedpc += GETARG_sBx(i); /* jump back */

0 commit comments

Comments
 (0)