Skip to content
Permalink
Browse files
hack lua to support signal
  • Loading branch information
cloudwu committed Jun 17, 2015
1 parent f36b173 commit 2086e13
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
@@ -458,6 +458,11 @@ struct lua_Debug {

/* }====================================================================== */

/* Add by skynet */

LUA_API lua_State * skynet_sig_L;
LUA_API void (lua_checksig_)(lua_State *L);
#define lua_checksig(L) if (skynet_sig_L) { lua_checksig_(L); }

/******************************************************************************
* Copyright (C) 1994-2015 Lua.org, PUC-Rio.
@@ -63,7 +63,17 @@

#endif


/* Add by skynet */
lua_State * skynet_sig_L = NULL;

LUA_API void
lua_checksig_(lua_State *L) {
if (skynet_sig_L == G(L)->mainthread) {
skynet_sig_L = NULL;
lua_pushnil(L);
lua_error(L);
}
}

/*
** Try to convert a value to a float. The float case is already handled
@@ -1028,6 +1038,7 @@ void luaV_execute (lua_State *L) {
vmbreak;
}
vmcase(OP_JMP) {
lua_checksig(L);
dojump(ci, i, 0);
vmbreak;
}
@@ -1080,6 +1091,7 @@ void luaV_execute (lua_State *L) {
vmcase(OP_CALL) {
int b = GETARG_B(i);
int nresults = GETARG_C(i) - 1;
lua_checksig(L);
if (b != 0) L->top = ra+b; /* else previous instruction set top */
if (luaD_precall(L, ra, nresults)) { /* C function? */
if (nresults >= 0) L->top = ci->top; /* adjust results */
@@ -1094,6 +1106,7 @@ void luaV_execute (lua_State *L) {
}
vmcase(OP_TAILCALL) {
int b = GETARG_B(i);
lua_checksig(L);
if (b != 0) L->top = ra+b; /* else previous instruction set top */
lua_assert(GETARG_C(i) - 1 == LUA_MULTRET);
if (luaD_precall(L, ra, LUA_MULTRET)) /* C function? */
@@ -1203,6 +1216,7 @@ void luaV_execute (lua_State *L) {
}
vmcase(OP_TFORLOOP) {
l_tforloop:
lua_checksig(L);
if (!ttisnil(ra + 1)) { /* continue loop? */
setobjs2s(L, ra, ra + 1); /* save control variable */
ci->u.l.savedpc += GETARG_sBx(i); /* jump back */

0 comments on commit 2086e13

Please sign in to comment.