aboutsummaryrefslogtreecommitdiff
path: root/src/lua_interface.c
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2008-09-21 22:16:18 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2008-09-21 22:16:18 -0400
commitf093965dfc07935323b8a9244a591d84788b497c (patch)
tree37e9be66f26d79f95f286566fc3ceb7b6b398620 /src/lua_interface.c
parentfdb720e8d0b5adf4fd9269ee9e4381dc0aebdb39 (diff)
downloadtextadept-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/lua_interface.c')
-rw-r--r--src/lua_interface.c21
1 files changed, 17 insertions, 4 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;
}
/**