| 1253 | } |
| 1254 | |
| 1255 | static int checkpanic (lua_State *L) { |
| 1256 | struct Aux b; |
| 1257 | void *ud; |
| 1258 | lua_State *L1; |
| 1259 | const char *code = luaL_checkstring(L, 1); |
| 1260 | lua_Alloc f = lua_getallocf(L, &ud); |
| 1261 | b.paniccode = luaL_optstring(L, 2, ""); |
| 1262 | b.L = L; |
| 1263 | L1 = lua_newstate(f, ud); /* create new state */ |
| 1264 | if (L1 == NULL) { /* error? */ |
| 1265 | lua_pushnil(L); |
| 1266 | return 1; |
| 1267 | } |
| 1268 | lua_atpanic(L1, panicback); /* set its panic function */ |
| 1269 | lua_pushlightuserdata(L1, &b); |
| 1270 | lua_setfield(L1, LUA_REGISTRYINDEX, "_jmpbuf"); /* store 'Aux' struct */ |
| 1271 | if (setjmp(b.jb) == 0) { /* set jump buffer */ |
| 1272 | runC(L, L1, code); /* run code unprotected */ |
| 1273 | lua_pushliteral(L, "no errors"); |
| 1274 | } |
| 1275 | else { /* error handling */ |
| 1276 | /* move error message to original state */ |
| 1277 | lua_pushstring(L, lua_tostring(L1, -1)); |
| 1278 | } |
| 1279 | lua_close(L1); |
| 1280 | return 1; |
| 1281 | } |
| 1282 | |
| 1283 | |
| 1284 |
nothing calls this directly
no test coverage detected