diff options
author | 2008-09-21 22:16:18 -0400 | |
---|---|---|
committer | 2008-09-21 22:16:18 -0400 | |
commit | f093965dfc07935323b8a9244a591d84788b497c (patch) | |
tree | 37e9be66f26d79f95f286566fc3ceb7b6b398620 /src | |
parent | fdb720e8d0b5adf4fd9269ee9e4381dc0aebdb39 (diff) | |
download | textadept-f093965dfc07935323b8a9244a591d84788b497c.tar.gz textadept-f093965dfc07935323b8a9244a591d84788b497c.zip |
Textadept gracefully exits when errors occur in core/init.lua.
Originally the error message was displayed in Textadept, but any attempts to
close the program would fail because core/init.lua wasn't properly loaded.
Errors from 'l_load_script' are displayed in a dialog box now.
Diffstat (limited to 'src')
-rw-r--r-- | src/lua_interface.c | 21 | ||||
-rw-r--r-- | src/textadept.c | 17 | ||||
-rw-r--r-- | src/textadept.h | 9 |
3 files changed, 31 insertions, 16 deletions
diff --git a/src/lua_interface.c b/src/lua_interface.c index 2e6a26bc..1d793df9 100644 --- a/src/lua_interface.c +++ b/src/lua_interface.c @@ -62,7 +62,7 @@ const char * @param argv The array of command line parameters. * @param reinit Flag indicating whether or not to reinitialize the Lua State. */ -void l_init(int argc, char **argv, bool reinit) { +bool l_init(int argc, char **argv, bool reinit) { if (!reinit) { lua = lua_open(); lua_newtable(lua); @@ -115,17 +115,30 @@ void l_init(int argc, char **argv, bool reinit) { lua_pushboolean(lua, 1); lua_setglobal(lua, "WIN32"); #endif - l_load_script("core/init.lua"); + return l_load_script("core/init.lua"); } /** * Loads and runs a given Lua script. * @param script_file The path of the Lua script relative to textadept_home. */ -void l_load_script(const char *script_file) { +bool l_load_script(const char *script_file) { + bool retval = true; char *script = g_strconcat(textadept_home, "/", script_file, NULL); - if (luaL_dofile(lua, script) != 0) l_handle_error(lua, NULL); + if (luaL_dofile(lua, script) != 0) { + const char *errmsg = lua_tostring(lua, -1); + lua_settop(lua, 0); +#ifndef WIN32 + GtkWidget *dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, + GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s\n", errmsg); + gtk_dialog_run(GTK_DIALOG(dialog)); +#else + MessageBox(0, static_cast<LPCSTR>(errmsg), "Error", 0); +#endif + retval = false; + } g_free(script); + return retval; } /** diff --git a/src/textadept.c b/src/textadept.c index 4d639ab6..9aaeccd6 100644 --- a/src/textadept.c +++ b/src/textadept.c @@ -2,11 +2,6 @@ #include "textadept.h" -#ifdef WIN32 -#include "Windows.h" -#define strcasecmp _stricmp -#endif - #define gbool gboolean #define signal(o, s, c) g_signal_connect(G_OBJECT(o), s, G_CALLBACK(c), 0) @@ -71,11 +66,13 @@ static void button_clicked(GtkWidget *button, gpointer); */ int main(int argc, char **argv) { gtk_init(&argc, &argv); - l_init(argc, argv, false); - create_ui(); - l_load_script("init.lua"); - gtk_main(); - return 0; + if (l_init(argc, argv, false)) { + create_ui(); + l_load_script("init.lua"); + gtk_main(); + return 0; + } else if (lua) lua_close(lua); + return 1; } #ifdef WIN32 diff --git a/src/textadept.h b/src/textadept.h index 504dae05..05258ba5 100644 --- a/src/textadept.h +++ b/src/textadept.h @@ -12,6 +12,11 @@ #include <SciLexer.h> #include <ScintillaWidget.h> +#ifdef WIN32 +#include "Windows.h" +#define strcasecmp _stricmp +#endif + extern "C" { #include <lua.h> #include <lualib.h> @@ -63,9 +68,9 @@ GtkWidget *find_create_ui(); void find_toggle_focus(); // lua_interface.c -void l_init(int argc, char **argv, bool reinit); +bool l_init(int argc, char **argv, bool reinit); void l_close(); -void l_load_script(const char *script_file); +bool l_load_script(const char *script_file); void l_add_scintilla_window(GtkWidget *editor); void l_remove_scintilla_window(GtkWidget *editor); void l_goto_scintilla_window(GtkWidget *editor, int n, bool absolute); |