From a9ba3482179c254bcf8c4d46106f540aa64f2279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Sun, 5 Mar 2023 09:48:56 +0100 Subject: [PATCH 1/6] Require lua 5.3 --- build/geanylua.m4 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build/geanylua.m4 b/build/geanylua.m4 index 1f1eaf67a..8d6acc983 100644 --- a/build/geanylua.m4 +++ b/build/geanylua.m4 @@ -6,15 +6,15 @@ AC_DEFUN([GP_CHECK_GEANYLUA], AC_HELP_STRING([--with-lua-pkg=ARG], [name of Lua pkg-config script [[default=lua5.1]]]), [LUA_PKG_NAME=${withval%.pc}], - [LUA_PKG_NAME=lua5.1 + [LUA_PKG_NAME=lua5.3 - for L in lua5.1 lua51 lua-5.1 lua; do + for L in lua5.3 lua53 lua-5.3 lua; do PKG_CHECK_EXISTS([$L], [LUA_PKG_NAME=$L]; break,[]) done]) - LUA_VERSION=5.1 - LUA_VERSION_BOUNDARY=5.2 + LUA_VERSION=5.3 + LUA_VERSION_BOUNDARY=5.4 GP_CHECK_PLUGIN_DEPS([GeanyLua], [LUA], [${LUA_PKG_NAME} >= ${LUA_VERSION} ${LUA_PKG_NAME} < ${LUA_VERSION_BOUNDARY}]) From 299c35fdceff9ec6107d9c07b993a4258d98a555 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Sun, 5 Mar 2023 09:49:21 +0100 Subject: [PATCH 2/6] Rename luaL_reg to luaL_Reg --- geanylua/glspi_app.c | 2 +- geanylua/glspi_dlg.c | 2 +- geanylua/glspi_doc.c | 2 +- geanylua/glspi_init.c | 2 +- geanylua/glspi_kfile.c | 2 +- geanylua/glspi_run.c | 2 +- geanylua/glspi_sci.c | 2 +- geanylua/gsdlg_lua.c | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/geanylua/glspi_app.c b/geanylua/glspi_app.c index 14d2e780b..89997e5de 100644 --- a/geanylua/glspi_app.c +++ b/geanylua/glspi_app.c @@ -615,7 +615,7 @@ static gint glspi_reloadconf(lua_State* L) -static const struct luaL_reg glspi_app_funcs[] = { +static const struct luaL_Reg glspi_app_funcs[] = { {"pluginver", glspi_pluginver}, {"appinfo", glspi_appinfo}, {"xsel", glspi_xsel}, diff --git a/geanylua/glspi_dlg.c b/geanylua/glspi_dlg.c index f0553853c..2c5395746 100644 --- a/geanylua/glspi_dlg.c +++ b/geanylua/glspi_dlg.c @@ -540,7 +540,7 @@ static gint glspi_pickfile(lua_State* L) -static const struct luaL_reg glspi_dlg_funcs[] = { +static const struct luaL_Reg glspi_dlg_funcs[] = { {"choose", glspi_choose}, {"confirm", glspi_confirm}, {"input", glspi_input}, diff --git a/geanylua/glspi_doc.c b/geanylua/glspi_doc.c index 41dd1cbce..cc1e4fe77 100644 --- a/geanylua/glspi_doc.c +++ b/geanylua/glspi_doc.c @@ -359,7 +359,7 @@ static gint glspi_setfiletype(lua_State* L) -static const struct luaL_reg glspi_doc_funcs[] = { +static const struct luaL_Reg glspi_doc_funcs[] = { {"filename", glspi_filename}, {"fileinfo", glspi_fileinfo}, {"settype", glspi_setfiletype}, diff --git a/geanylua/glspi_init.c b/geanylua/glspi_init.c index f48b86788..b0f95c7e8 100644 --- a/geanylua/glspi_init.c +++ b/geanylua/glspi_init.c @@ -539,7 +539,7 @@ static gint glspi_rescan(lua_State* L) { return 0; } -static const struct luaL_reg glspi_mnu_funcs[] = { +static const struct luaL_Reg glspi_mnu_funcs[] = { {"rescan", glspi_rescan}, {NULL,NULL} }; diff --git a/geanylua/glspi_kfile.c b/geanylua/glspi_kfile.c index 393ec85df..dead8c1fc 100644 --- a/geanylua/glspi_kfile.c +++ b/geanylua/glspi_kfile.c @@ -370,7 +370,7 @@ static gint kfile_remove(lua_State* L) -static const struct luaL_reg kfile_funcs[] = { +static const struct luaL_Reg kfile_funcs[] = { {"new", kfile_new}, {"data", kfile_data}, {"groups", kfile_groups}, diff --git a/geanylua/glspi_run.c b/geanylua/glspi_run.c index 95e0e05ea..17155a441 100644 --- a/geanylua/glspi_run.c +++ b/geanylua/glspi_run.c @@ -279,7 +279,7 @@ static void glspi_state_done(lua_State *L) -static const struct luaL_reg glspi_timer_funcs[] = { +static const struct luaL_Reg glspi_timer_funcs[] = { {"timeout", glspi_timeout}, {"yield", glspi_yield}, {"optimize", glspi_optimize}, diff --git a/geanylua/glspi_sci.c b/geanylua/glspi_sci.c index 83bff4f47..f07fa3521 100644 --- a/geanylua/glspi_sci.c +++ b/geanylua/glspi_sci.c @@ -972,7 +972,7 @@ struct Sci_TextToFind { -static const struct luaL_reg glspi_sci_funcs[] = { +static const struct luaL_Reg glspi_sci_funcs[] = { {"text", glspi_text}, {"selection", glspi_selection}, {"select", glspi_select}, diff --git a/geanylua/gsdlg_lua.c b/geanylua/gsdlg_lua.c index b866583ed..eca163dcb 100644 --- a/geanylua/gsdlg_lua.c +++ b/geanylua/gsdlg_lua.c @@ -387,7 +387,7 @@ static gint gsdl_done(lua_State *L) -static const struct luaL_reg gsdl_funcs[] = { +static const struct luaL_Reg gsdl_funcs[] = { {"new", gsdl_new}, {"run", gsdl_run}, {"label", gsdl_label}, From 460da9ffeaa895a779832c26127e4712e5cda340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Sun, 5 Mar 2023 23:06:55 +0100 Subject: [PATCH 3/6] Replace luaL_register(L, NULL, funcs) with luaL_setfuncs(L, funcs, 0) With the NULL second parameter luaL_register() is equivalent to luaL_setfuncs() as described e.g. here https://wiki.gentoo.org/wiki/Lua/Porting_notes --- geanylua/glspi_app.c | 2 +- geanylua/glspi_dlg.c | 2 +- geanylua/glspi_doc.c | 2 +- geanylua/glspi_init.c | 2 +- geanylua/glspi_kfile.c | 2 +- geanylua/glspi_sci.c | 2 +- geanylua/gsdlg_lua.c | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/geanylua/glspi_app.c b/geanylua/glspi_app.c index 89997e5de..f641cf955 100644 --- a/geanylua/glspi_app.c +++ b/geanylua/glspi_app.c @@ -636,5 +636,5 @@ static const struct luaL_Reg glspi_app_funcs[] = { void glspi_init_app_funcs(lua_State *L, const gchar*script_dir) { glspi_script_dir = script_dir; - luaL_register(L, NULL,glspi_app_funcs); + luaL_setfuncs(L, glspi_app_funcs, 0); } diff --git a/geanylua/glspi_dlg.c b/geanylua/glspi_dlg.c index 2c5395746..e0a87b3dd 100644 --- a/geanylua/glspi_dlg.c +++ b/geanylua/glspi_dlg.c @@ -554,5 +554,5 @@ static const struct luaL_Reg glspi_dlg_funcs[] = { void glspi_init_dlg_funcs(lua_State *L, GsDlgRunHook hook) { glspi_pause_timer = hook; - luaL_register(L, NULL,glspi_dlg_funcs); + luaL_setfuncs(L, glspi_dlg_funcs, 0); } diff --git a/geanylua/glspi_doc.c b/geanylua/glspi_doc.c index cc1e4fe77..e65d5897e 100644 --- a/geanylua/glspi_doc.c +++ b/geanylua/glspi_doc.c @@ -374,5 +374,5 @@ static const struct luaL_Reg glspi_doc_funcs[] = { }; void glspi_init_doc_funcs(lua_State *L) { - luaL_register(L, NULL,glspi_doc_funcs); + luaL_setfuncs(L, glspi_doc_funcs, 0); } diff --git a/geanylua/glspi_init.c b/geanylua/glspi_init.c index b0f95c7e8..3bc5bb1c7 100644 --- a/geanylua/glspi_init.c +++ b/geanylua/glspi_init.c @@ -546,5 +546,5 @@ static const struct luaL_Reg glspi_mnu_funcs[] = { void glspi_init_mnu_funcs(lua_State *L) { - luaL_register(L, NULL,glspi_mnu_funcs); + luaL_setfuncs(L, glspi_mnu_funcs, 0); } diff --git a/geanylua/glspi_kfile.c b/geanylua/glspi_kfile.c index dead8c1fc..21db063c6 100644 --- a/geanylua/glspi_kfile.c +++ b/geanylua/glspi_kfile.c @@ -395,7 +395,7 @@ static gint luaopen_keyfile(lua_State *L) lua_pushstring(L,"__gc"); lua_pushcfunction(L,kfile_done); lua_rawset(L,-3); - luaL_register(L, NULL, &kfile_funcs[1]); + luaL_setfuncs(L, &kfile_funcs[1], 0); luaL_register(L, LUA_MODULE_NAME, kfile_funcs); return 0; } diff --git a/geanylua/glspi_sci.c b/geanylua/glspi_sci.c index f07fa3521..ac0b2be82 100644 --- a/geanylua/glspi_sci.c +++ b/geanylua/glspi_sci.c @@ -995,5 +995,5 @@ static const struct luaL_Reg glspi_sci_funcs[] = { }; void glspi_init_sci_funcs(lua_State *L) { - luaL_register(L, NULL,glspi_sci_funcs); + luaL_setfuncs(L, glspi_sci_funcs, 0); } diff --git a/geanylua/gsdlg_lua.c b/geanylua/gsdlg_lua.c index eca163dcb..96d8f3bd9 100644 --- a/geanylua/gsdlg_lua.c +++ b/geanylua/gsdlg_lua.c @@ -425,7 +425,7 @@ gint luaopen_dialog(lua_State *L) lua_pushcfunction(L,gsdl_done); lua_rawset(L,-3); - luaL_register(L, NULL, &gsdl_funcs[1]); + luaL_setfuncs(L, &gsdl_funcs[1], 0); luaL_register(L, LUA_MODULE_NAME, gsdl_funcs); return 0; } From f535137f62802b6f35de3a579a758758a84759bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Sun, 5 Mar 2023 23:13:08 +0100 Subject: [PATCH 4/6] Replace luaL_register() luaL_register() can be replaced by: 1. creating a new table 2. adding the functions to it using luaL_setfuncs() 3. publishing this table globally by lua_setglobal() Since these tables are registered just once, we don't care about the special cases described below and the "merging" problem. https://stackoverflow.com/questions/19041215/lual-openlib-replacement-for-lua-5-2 --- geanylua/glspi_kfile.c | 4 +++- geanylua/glspi_run.c | 4 +++- geanylua/gsdlg_lua.c | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/geanylua/glspi_kfile.c b/geanylua/glspi_kfile.c index 21db063c6..ca469cd8c 100644 --- a/geanylua/glspi_kfile.c +++ b/geanylua/glspi_kfile.c @@ -396,7 +396,9 @@ static gint luaopen_keyfile(lua_State *L) lua_pushcfunction(L,kfile_done); lua_rawset(L,-3); luaL_setfuncs(L, &kfile_funcs[1], 0); - luaL_register(L, LUA_MODULE_NAME, kfile_funcs); + lua_newtable(L); + luaL_setfuncs(L, kfile_funcs, 0); + lua_setglobal(L, LUA_MODULE_NAME); return 0; } diff --git a/geanylua/glspi_run.c b/geanylua/glspi_run.c index 17155a441..6c3a2356d 100644 --- a/geanylua/glspi_run.c +++ b/geanylua/glspi_run.c @@ -393,12 +393,14 @@ static void show_error(lua_State *L, const gchar *script_file) static gint glspi_init_module(lua_State *L, const gchar *script_file, gint caller, GKeyFile*proj, const gchar*script_dir) { - luaL_register(L, LUA_MODULE_NAME, glspi_timer_funcs); + lua_newtable(L); + luaL_setfuncs(L, glspi_timer_funcs, 0); glspi_init_sci_funcs(L); glspi_init_doc_funcs(L); glspi_init_mnu_funcs(L); glspi_init_dlg_funcs(L, glspi_pause_timer); glspi_init_app_funcs(L,script_dir); + lua_setglobal(L, LUA_MODULE_NAME); set_string_token(L,tokenWordChars,GEANY_WORDCHARS); set_string_token(L,tokenBanner,DEFAULT_BANNER); set_string_token(L,tokenDirSep, G_DIR_SEPARATOR_S); diff --git a/geanylua/gsdlg_lua.c b/geanylua/gsdlg_lua.c index 96d8f3bd9..a67a583e6 100644 --- a/geanylua/gsdlg_lua.c +++ b/geanylua/gsdlg_lua.c @@ -426,7 +426,9 @@ gint luaopen_dialog(lua_State *L) lua_rawset(L,-3); luaL_setfuncs(L, &gsdl_funcs[1], 0); - luaL_register(L, LUA_MODULE_NAME, gsdl_funcs); + lua_newtable(L); + luaL_setfuncs(L, gsdl_funcs, 0); + lua_setglobal(L, LUA_MODULE_NAME); return 0; } From c6f72e7bb59bcbec37cb48ffa4de6d4d40a3897e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Sun, 5 Mar 2023 23:14:03 +0100 Subject: [PATCH 5/6] Rename lua_objlen() to lua_rawlen() The documentation says these are identical. --- geanylua/glspi_dlg.c | 2 +- geanylua/glspi_sci.c | 2 +- geanylua/gsdlg_lua.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/geanylua/glspi_dlg.c b/geanylua/glspi_dlg.c index e0a87b3dd..4e546cbe4 100644 --- a/geanylua/glspi_dlg.c +++ b/geanylua/glspi_dlg.c @@ -128,7 +128,7 @@ static gint glspi_choose(lua_State* L) arg1=lua_tostring(L, 1); } - n=lua_objlen(L,2); + n=lua_rawlen(L,2); for (i=1;i<=n; i++) { lua_rawgeti(L,2,i); if (!lua_isstring(L, -1)) { diff --git a/geanylua/glspi_sci.c b/geanylua/glspi_sci.c index ac0b2be82..e95342606 100644 --- a/geanylua/glspi_sci.c +++ b/geanylua/glspi_sci.c @@ -905,7 +905,7 @@ static gint glspi_find(lua_State* L) ttf.chrg.cpMin=lua_tonumber(L,2); ttf.chrg.cpMax=lua_tonumber(L,3); - n=lua_objlen(L,4); + n=lua_rawlen(L,4); for (i=1;i<=n; i++) { lua_rawgeti(L,4,i); if (lua_isstring(L, -1)) { diff --git a/geanylua/gsdlg_lua.c b/geanylua/gsdlg_lua.c index a67a583e6..34df24365 100644 --- a/geanylua/gsdlg_lua.c +++ b/geanylua/gsdlg_lua.c @@ -323,7 +323,7 @@ static gint gsdl_new(lua_State *L) { if (argc>=2) { if (!lua_istable(L,2)) { return FAIL_TABLE_ARG(2); } } - n=lua_objlen(L,2); + n=lua_rawlen(L,2); for (i=1;i<=n; i++) { lua_rawgeti(L,2,i); if (!lua_isstring(L, -1)) { From ed4ee2297453d8bd30789aa34a45636a21ee1b4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Sun, 5 Mar 2023 23:17:04 +0100 Subject: [PATCH 6/6] Replace the stack traceback code with the code taken from the LUA binary LUA_GLOBALSINDEX is gone now but we can use the whole code below (the original traceback reporting code was also stolen from here): https://github.com/lua/lua/blob/cf08915d62e338c987b71c078b148490510e9fe7/lua.c#L248 --- geanylua/glspi_run.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/geanylua/glspi_run.c b/geanylua/glspi_run.c index 6c3a2356d..e034ede1d 100644 --- a/geanylua/glspi_run.c +++ b/geanylua/glspi_run.c @@ -293,21 +293,17 @@ static const struct luaL_Reg glspi_timer_funcs[] = { /* Catch and report script errors */ static gint glspi_traceback(lua_State *L) { - lua_getfield(L, LUA_GLOBALSINDEX, "debug"); - if (!lua_istable(L, -1)) { - lua_pop(L, 1); - return 1; - } - lua_getfield(L, -1, "traceback"); - if (!lua_isfunction(L, -1)) { - lua_pop(L, 2); - return 1; + const char *msg = lua_tostring(L, 1); + if (msg == NULL) { /* is error object not a string? */ + if (luaL_callmeta(L, 1, "__tostring") && /* does it have a metamethod */ + lua_type(L, -1) == LUA_TSTRING) /* that produces a string? */ + return 1; /* that is the message */ + else + msg = lua_pushfstring(L, "(error object is a %s value)", + luaL_typename(L, 1)); } - lua_pushvalue(L, 1); - lua_pushinteger(L, 2); - lua_call(L, 2, 1); - - return 1; + luaL_traceback(L, L, msg, 1); /* append a standard traceback */ + return 1; /* return the traceback */ } /*