Implement fatal error message box
Used when lite-xl fails at startup
This commit is contained in:
parent
636bc7ec95
commit
a4bc8986ff
|
@ -406,7 +406,7 @@ function core.init()
|
|||
end
|
||||
project_dir_abs = system.absolute_path(".")
|
||||
if not core.set_project_dir(project_dir_abs) then
|
||||
print("internal error: cannot set project directory to cwd")
|
||||
system.show_fatal_error("Lite XL internal error", "cannot set project directory to cwd")
|
||||
os.exit(1)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -258,6 +258,30 @@ static int f_show_confirm_dialog(lua_State *L) {
|
|||
}
|
||||
|
||||
|
||||
static int f_show_fatal_error(lua_State *L) {
|
||||
const char *title = luaL_checkstring(L, 1);
|
||||
const char *msg = luaL_checkstring(L, 2);
|
||||
|
||||
#ifdef _WIN32
|
||||
MessageBox(0, msg, title, MB_OK | MB_ICONERROR);
|
||||
|
||||
#else
|
||||
SDL_MessageBoxButtonData buttons[] = {
|
||||
{ SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 0, "Ok" },
|
||||
};
|
||||
SDL_MessageBoxData data = {
|
||||
.title = title,
|
||||
.message = msg,
|
||||
.numbuttons = 1,
|
||||
.buttons = buttons,
|
||||
};
|
||||
int buttonid;
|
||||
SDL_ShowMessageBox(&data, &buttonid);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int f_chdir(lua_State *L) {
|
||||
const char *path = luaL_checkstring(L, 1);
|
||||
int err = chdir(path);
|
||||
|
@ -441,6 +465,7 @@ static const luaL_Reg lib[] = {
|
|||
{ "set_window_size", f_set_window_size },
|
||||
{ "window_has_focus", f_window_has_focus },
|
||||
{ "show_confirm_dialog", f_show_confirm_dialog },
|
||||
{ "show_fatal_error", f_show_fatal_error },
|
||||
{ "chdir", f_chdir },
|
||||
{ "mkdir", f_mkdir },
|
||||
{ "list_dir", f_list_dir },
|
||||
|
|
|
@ -134,8 +134,13 @@ init_lua:
|
|||
" core.init()\n"
|
||||
" core.run()\n"
|
||||
"end, function(err)\n"
|
||||
" print('Error: ' .. tostring(err))\n"
|
||||
" print(debug.traceback(nil, 2))\n"
|
||||
" system.show_fatal_error('Lite XL start error', '"
|
||||
"Fatal error: cannot locate the data directory.\\n"
|
||||
"Please verify that the data folder is available.')\n"
|
||||
" local fp = io.open((exedir and exedir .. '/' or '') .. 'error.txt', 'wb')\n"
|
||||
" fp:write('Error: ' .. tostring(err) .. '\\n')\n"
|
||||
" fp:write(debug.traceback(nil, 2) .. '\\n')\n"
|
||||
" fp:close()\n"
|
||||
" if core and core.on_error then\n"
|
||||
" pcall(core.on_error, err)\n"
|
||||
" end\n"
|
||||
|
|
Loading…
Reference in New Issue