From f093965dfc07935323b8a9244a591d84788b497c Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Sun, 21 Sep 2008 22:16:18 -0400 Subject: 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. --- src/lua_interface.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/lua_interface.c') 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(errmsg), "Error", 0); +#endif + retval = false; + } g_free(script); + return retval; } /** -- cgit v1.2.3