| 5131 | } |
| 5132 | |
| 5133 | void RequestAbortLuaScript(int uid, const char* message) |
| 5134 | { |
| 5135 | if(luaContextInfo.find(uid) == luaContextInfo.end()) |
| 5136 | return; |
| 5137 | LuaContextInfo& info = *luaContextInfo[uid]; |
| 5138 | lua_State* L = info.L; |
| 5139 | if(L) |
| 5140 | { |
| 5141 | // this probably isn't the right way to do it |
| 5142 | // but calling luaL_error here is positively unsafe |
| 5143 | // (it seemingly works fine but sometimes corrupts the emulation state in colorful ways) |
| 5144 | // and this works pretty well and is definitely safe, so screw it |
| 5145 | info.L->hookcount = 1; // run hook function as soon as possible |
| 5146 | info.panic = true; // and call luaL_error once we're inside the hook function |
| 5147 | if(message) |
| 5148 | { |
| 5149 | strncpy(info.panicMessage, message, sizeof(info.panicMessage)); |
| 5150 | info.panicMessage[sizeof(info.panicMessage)-1] = 0; |
| 5151 | } |
| 5152 | else |
| 5153 | { |
| 5154 | // attach file/line info because this is the case where it's most necessary to see that, |
| 5155 | // and often it won't be possible for the later luaL_error call to retrieve it otherwise. |
| 5156 | // this means sometimes printing multiple file/line numbers if luaL_error does find something, |
| 5157 | // but that's fine since more information is probably better anyway. |
| 5158 | luaL_where(L,0); // should be 0 and not 1 here to get useful (on force stop) messages |
| 5159 | const char* whereString = lua_tostring(L,-1); |
| 5160 | snprintf(info.panicMessage, sizeof(info.panicMessage), "%sscript terminated", whereString); |
| 5161 | lua_pop(L,1); |
| 5162 | } |
| 5163 | } |
| 5164 | } |
| 5165 | |
| 5166 | void SetSaveKey(LuaContextInfo& info, const char* key) |
| 5167 | { |