diff -Nur lua-5.1.3/src/lauxlib.h lua-5.1.3-manual-patch/src/lauxlib.h --- lua-5.1.3/src/lauxlib.h 2007年12月27日 08:02:25.000000000 -0500 +++ lua-5.1.3-manual-patch/src/lauxlib.h 2008年07月16日 14:30:30.000000000 -0400 @@ -81,6 +81,8 @@ LUALIB_API lua_State *(luaL_newstate) (void); +LUALIB_API void (luaL_setbailout) (lua_State* L, int bailout); +LUALIB_API int (luaL_getbailout) (lua_State* L); LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, const char *r); diff -Nur lua-5.1.3/src/lstate.c lua-5.1.3-manual-patch/src/lstate.c --- lua-5.1.3/src/lstate.c 2008年01月03日 10:20:39.000000000 -0500 +++ lua-5.1.3-manual-patch/src/lstate.c 2008年07月16日 14:28:43.000000000 -0400 @@ -148,6 +148,7 @@ if (l == NULL) return NULL; L = tostate(l); g = &((LG *)L)->g; + L->bailout=0; L->next = NULL; L->tt = LUA_TTHREAD; g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT); @@ -212,3 +213,11 @@ close_state(L); } +LUALIB_API void luaL_setbailout(lua_State* L, int bailout) { + L->bailout=bailout; +} + +LUALIB_API int luaL_getbailout(lua_State* L) { + return L->bailout; +} + diff -Nur lua-5.1.3/src/lvm.c lua-5.1.3-manual-patch/src/lvm.c --- lua-5.1.3/src/lvm.c 2007年12月28日 10:32:23.000000000 -0500 +++ lua-5.1.3-manual-patch/src/lvm.c 2008年07月16日 14:26:06.000000000 -0400 @@ -375,6 +375,7 @@ StkId base; TValue *k; const Instruction *pc; + int opcode; reentry: /* entry point */ lua_assert(isLua(L->ci)); pc = L->savedpc; @@ -399,7 +400,11 @@ lua_assert(base == L->base && L->base == L->ci->base); lua_assert(base <= L->top && L->top <= L->stack + L->stacksize); lua_assert(L->top == L->ci->top || luaG_checkopenop(i)); - switch (GET_OPCODE(i)) { + opcode=GET_OPCODE(i); + if(L->bailout) { + opcode=OP_RETURN; + } + switch (opcode) { case OP_MOVE: { setobjs2s(L, ra, RB(i)); continue; @@ -634,6 +639,10 @@ } case OP_RETURN: { int b = GETARG_B(i); + // if we're bailing out, just teardown as fast as possible + if(L->bailout) { + b=0; + } if (b != 0) L->top = ra+b-1; if (L->openupval) luaF_close(L, base); L->savedpc = pc;

AltStyle によって変換されたページ (->オリジナル) /