int tm_checked_call(lua_State *L, int nargs) { int err_func = lua_gettop(L) - nargs; // Load error handler for colony, or default Lua reporter // if an internal error has occurred early in the load. lua_getglobal(L, "_colony_unhandled_exception"); if (lua_isnil(L, -1)) { lua_remove(L, -1); lua_pushcfunction(L, lua_report); } // Run checked call. lua_insert(L, err_func); int r = lua_pcall(L, nargs, 0, err_func); if (r != 0) { if (r == LUA_ERRMEM) { tm_logf(SYS_ERR, "Error: Out of memory\n"); } else { tm_logf(SYS_ERR, "lua_pcall error %i\n", r); } tm_runtime_exit_longjmp(255); } lua_remove(L, err_func); return r; }
static int lua_report(lua_State *L) { traceback(L); report(L, -1); tm_runtime_exit_longjmp(255); return 0; }
static int l_tm_exit(lua_State* L) { const char code = lua_tonumber(L, 1); tm_runtime_exit_longjmp(code); return 0; }