From 756db853add57a776383af2152cee3423f247720 Mon Sep 17 00:00:00 2001 From: xiota Date: Sun, 5 Mar 2023 12:52:56 -0800 Subject: [PATCH 1/4] GeanyLua: Don't ignore with-lua-pkg configure option --- build/geanylua.m4 | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/build/geanylua.m4 b/build/geanylua.m4 index 1f1eaf67a..d5fc7db78 100644 --- a/build/geanylua.m4 +++ b/build/geanylua.m4 @@ -4,17 +4,35 @@ AC_DEFUN([GP_CHECK_GEANYLUA], AC_ARG_WITH([lua-pkg], AC_HELP_STRING([--with-lua-pkg=ARG], - [name of Lua pkg-config script [[default=lua5.1]]]), + [name of Lua pkg-config script [[default=lua]]]), [LUA_PKG_NAME=${withval%.pc}], - [LUA_PKG_NAME=lua5.1 + [LUA_PKG_NAME=lua - for L in lua5.1 lua51 lua-5.1 lua; do + for L in "$LUA_PKG_NAME" lua lua53 lua54 lua52 luajit lua51; do PKG_CHECK_EXISTS([$L], [LUA_PKG_NAME=$L]; break,[]) done]) - LUA_VERSION=5.1 - LUA_VERSION_BOUNDARY=5.2 + if [[ "x$LUA_PKG_NAME" = "xluajit" ]] ; then + LUA_VERSION=2.0 + LUA_VERSION_BOUNDARY=3.0 + elif [[ "x$LUA_PKG_NAME" = "xlua51" ]] ; then + LUA_VERSION=5.1 + LUA_VERSION_BOUNDARY=5.2 + elif [[ "x$LUA_PKG_NAME" = "xlua52" ]] ; then + LUA_VERSION=5.2 + LUA_VERSION_BOUNDARY=5.3 + elif [[ "x$LUA_PKG_NAME" = "xlua53" ]] ; then + LUA_VERSION=5.3 + LUA_VERSION_BOUNDARY=5.4 + elif [[ "x$LUA_PKG_NAME" = "xlua54" ]] ; then + LUA_VERSION=5.4 + LUA_VERSION_BOUNDARY=5.5 + else + LUA_VERSION=5.1 + LUA_VERSION_BOUNDARY=5.5 + fi + GP_CHECK_PLUGIN_DEPS([GeanyLua], [LUA], [${LUA_PKG_NAME} >= ${LUA_VERSION} ${LUA_PKG_NAME} < ${LUA_VERSION_BOUNDARY}]) From 599766dae8fce6e9e4604f5946497248c4343ebc Mon Sep 17 00:00:00 2001 From: xiota Date: Sun, 5 Mar 2023 13:58:13 -0800 Subject: [PATCH 2/4] GeanyLua: Add support for Lua 5.2+ --- geanylua/glspi_app.c | 2 +- geanylua/glspi_dlg.c | 4 ++-- geanylua/glspi_doc.c | 2 +- geanylua/glspi_init.c | 2 +- geanylua/glspi_kfile.c | 6 ++++-- geanylua/glspi_run.c | 28 +++++++++++++--------------- geanylua/glspi_sci.c | 4 ++-- geanylua/gsdlg_lua.c | 8 +++++--- 8 files changed, 29 insertions(+), 27 deletions(-) diff --git a/geanylua/glspi_app.c b/geanylua/glspi_app.c index 5cc409efc..988df945a 100644 --- a/geanylua/glspi_app.c +++ b/geanylua/glspi_app.c @@ -549,5 +549,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 a6a4c7a23..449e18ca7 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)) { @@ -556,5 +556,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..ca469cd8c 100644 --- a/geanylua/glspi_kfile.c +++ b/geanylua/glspi_kfile.c @@ -395,8 +395,10 @@ 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_register(L, LUA_MODULE_NAME, kfile_funcs); + luaL_setfuncs(L, &kfile_funcs[1], 0); + 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..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 */ } /* @@ -393,12 +389,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/glspi_sci.c b/geanylua/glspi_sci.c index f07fa3521..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)) { @@ -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..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)) { @@ -425,8 +425,10 @@ gint luaopen_dialog(lua_State *L) lua_pushcfunction(L,gsdl_done); lua_rawset(L,-3); - luaL_register(L, NULL, &gsdl_funcs[1]); - luaL_register(L, LUA_MODULE_NAME, gsdl_funcs); + luaL_setfuncs(L, &gsdl_funcs[1], 0); + lua_newtable(L); + luaL_setfuncs(L, gsdl_funcs, 0); + lua_setglobal(L, LUA_MODULE_NAME); return 0; } From e93bacb506b5f8d911d6d8773856ec105c15726f Mon Sep 17 00:00:00 2001 From: xiota Date: Mon, 6 Mar 2023 15:09:13 -0800 Subject: [PATCH 3/4] GeanyLua: Add compatibility for Lua 5.1 and LuaJIT --- geanylua/Makefile.am | 2 ++ geanylua/glspi.h | 2 ++ geanylua/glspi_compat.c | 55 +++++++++++++++++++++++++++++++++++++++++ geanylua/glspi_compat.h | 28 +++++++++++++++++++++ geanylua/glspi_kfile.c | 2 ++ geanylua/gsdlg_lua.c | 1 + 6 files changed, 90 insertions(+) create mode 100644 geanylua/glspi_compat.c create mode 100644 geanylua/glspi_compat.h diff --git a/geanylua/Makefile.am b/geanylua/Makefile.am index 6a8b055a2..4d49e0029 100644 --- a/geanylua/Makefile.am +++ b/geanylua/Makefile.am @@ -24,6 +24,8 @@ libgeanylua_la_SOURCES = \ glspi_keycmd.h \ glspi_sci.h \ glspi_ver.h \ + glspi_compat.c \ + glspi_compat.h \ gsdlg.h geanylua_la_CFLAGS = \ diff --git a/geanylua/glspi.h b/geanylua/glspi.h index 9f172b8e2..bd32139ce 100644 --- a/geanylua/glspi.h +++ b/geanylua/glspi.h @@ -16,6 +16,8 @@ #include #include +#include "glspi_compat.h" + #include #define main_widgets geany->main_widgets diff --git a/geanylua/glspi_compat.c b/geanylua/glspi_compat.c new file mode 100644 index 000000000..79fc0a459 --- /dev/null +++ b/geanylua/glspi_compat.c @@ -0,0 +1,55 @@ +/* Lua compatibility functions */ + +#include +#include +#include + + +/* + * Compatibility functions for Lua 5.1 and LuaJIT + */ +#if LUA_VERSION_NUM==501 + +/* Adapted from Lua 5.2.0 */ +void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { + luaL_checkstack(L, nup+1, "too many upvalues"); + for (; l->name != NULL; l++) { /* fill the table with given functions */ + int i; + lua_pushstring(L, l->name); + for (i = 0; i < nup; i++) /* copy upvalues to the top */ + lua_pushvalue(L, -(nup+1)); + lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ + lua_settable(L, -(nup + 3)); + } + lua_pop(L, nup); /* remove upvalues */ +} + +#endif /* LUAJIT_VERSION_NUM */ + + +/* + * Compatibility functions for Lua 5.1 only + */ +#if LUA_VERSION_NUM==501 && !defined LUAJIT_VERSION_NUM + +void luaL_traceback (lua_State *L, lua_State *L1, const char *msg, + int level) +{ + 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; + } + lua_pushvalue(L, 1); + lua_pushinteger(L, 2); + lua_call(L, 2, 1); + + return 1; +} + +#endif /* LUA_VERSION_NUM */ diff --git a/geanylua/glspi_compat.h b/geanylua/glspi_compat.h new file mode 100644 index 000000000..81c5fd6f8 --- /dev/null +++ b/geanylua/glspi_compat.h @@ -0,0 +1,28 @@ +/* Lua compatibility functions */ + +#ifndef GLSPI_COMPAT +#define GLSPI_COMPAT 1 + +/* + * Compatibility functions for Lua 5.1 and LuaJIT + */ +#if LUA_VERSION_NUM==501 + +#define lua_rawlen(L,i) lua_objlen(L, (i)) + +void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup); + +#endif /* LUAJIT_VERSION_NUM */ + + +/* + * Compatibility functions for Lua 5.1 only + */ +#if LUA_VERSION_NUM==501 && !defined LUAJIT_VERSION_NUM + +void luaL_traceback (lua_State *L, lua_State *L1, const char *msg, int level); + +#endif /* LUA_VERSION_NUM */ + + +#endif /* GLSPI_COMPAT */ diff --git a/geanylua/glspi_kfile.c b/geanylua/glspi_kfile.c index ca469cd8c..e20161f88 100644 --- a/geanylua/glspi_kfile.c +++ b/geanylua/glspi_kfile.c @@ -12,6 +12,8 @@ #include #include +#include "glspi_compat.h" + #define LUA_MODULE_NAME "keyfile" #define MetaName "_g_key_file_metatable" diff --git a/geanylua/gsdlg_lua.c b/geanylua/gsdlg_lua.c index 34df24365..397ef27c2 100644 --- a/geanylua/gsdlg_lua.c +++ b/geanylua/gsdlg_lua.c @@ -35,6 +35,7 @@ #include #include +#include "glspi_compat.h" #define GSDLG_ALL_IN_ONE #include "gsdlg.h" From ddd7ea509c6ef5bc651b5e4f88c9039875bc35df Mon Sep 17 00:00:00 2001 From: xiota Date: Sun, 13 Oct 2024 08:24:12 +0000 Subject: [PATCH 4/4] GeanyLua: Fix Lua 5.1 compat function --- geanylua/glspi_compat.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/geanylua/glspi_compat.c b/geanylua/glspi_compat.c index 79fc0a459..d40158072 100644 --- a/geanylua/glspi_compat.c +++ b/geanylua/glspi_compat.c @@ -38,18 +38,18 @@ void luaL_traceback (lua_State *L, lua_State *L1, const char *msg, lua_getfield(L, LUA_GLOBALSINDEX, "debug"); if (!lua_istable(L, -1)) { lua_pop(L, 1); - return 1; + return; } lua_getfield(L, -1, "traceback"); if (!lua_isfunction(L, -1)) { lua_pop(L, 2); - return 1; + return; } lua_pushvalue(L, 1); lua_pushinteger(L, 2); lua_call(L, 2, 1); - return 1; + return; } #endif /* LUA_VERSION_NUM */