1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index c747aef6c..e7ef9aa5e 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -20,7 +20,7 @@ concurrency:
env:
CFLAGS: -g -O2 -Werror=pointer-arith -Werror=implicit-function-declaration
- CONFIGURE_FLAGS: --disable-silent-rules
+ CONFIGURE_FLAGS: --disable-silent-rules --with-lua-pkg=lua5.4
CPPCHECKFLAGS: --check-level=exhaustive
CCACHE_DIR: ${{ github.workspace }}/.ccache
CCACHE_COMPRESS: true
@@ -119,7 +119,7 @@ jobs:
# geanygendoc
libctpl-dev
# geanylua
- liblua5.1-0-dev
+ liblua5.4-dev
# geanypg
libgpgme-dev
# geanyvc
diff --git a/.github/workflows/windows-msys2-build.yml b/.github/workflows/windows-msys2-build.yml
index e3c5165b4..7dffa32f1 100644
--- a/.github/workflows/windows-msys2-build.yml
+++ b/.github/workflows/windows-msys2-build.yml
@@ -33,7 +33,7 @@ jobs:
mingw-w64-x86_64-gtkspell3
mingw-w64-x86_64-libgit2
mingw-w64-x86_64-libsoup3
- mingw-w64-x86_64-lua51
+ mingw-w64-x86_64-lua54
patch
rsync
unzip
@@ -71,7 +71,7 @@ jobs:
export lt_cv_deplibs_check_method=${lt_cv_deplibs_check_method='pass_all'}
mkdir -p _build
cd _build
- ../configure --prefix=${DESTINATON}/build/geany --with-geany-libdir=${DESTINATON}/build/geany/lib --disable-silent-rules
+ ../configure --prefix=${DESTINATON}/build/geany --with-geany-libdir=${DESTINATON}/build/geany/lib --disable-silent-rules --with-lua-pkg=lua54
make -j
make DESTDIR=${DESTINATON}/build/geany-plugins install
rm -rf ${DESTINATON}/release/geany-plugins-orig
diff --git a/build/geanylua.m4 b/build/geanylua.m4
index f642371b6..fec189f2f 100644
--- a/build/geanylua.m4
+++ b/build/geanylua.m4
@@ -4,20 +4,18 @@ AC_DEFUN([GP_CHECK_GEANYLUA],
AC_ARG_WITH([lua-pkg],
AS_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
- PKG_CHECK_EXISTS([$L],
- [LUA_PKG_NAME=$L]; break,[])
- done])
+ AS_CASE([$LUA_PKG_NAME],
+ [luajit], [LUA_VERSION_MIN=2.0; LUA_VERSION_LIMIT=3.0],
+ [*], [LUA_VERSION_MIN=5.1; LUA_VERSION_LIMIT=5.6]
+ )
- LUA_VERSION=5.1
- LUA_VERSION_BOUNDARY=5.2
GP_CHECK_PLUGIN_DEPS([GeanyLua], [LUA],
- [${LUA_PKG_NAME} >= ${LUA_VERSION}
- ${LUA_PKG_NAME} < ${LUA_VERSION_BOUNDARY}])
+ [${LUA_PKG_NAME} >= ${LUA_VERSION_MIN}
+ ${LUA_PKG_NAME} < ${LUA_VERSION_LIMIT}])
GP_CHECK_PLUGIN_DEPS([GeanyLua], [GMODULE], [gmodule-2.0])
GP_COMMIT_PLUGIN_STATUS([GeanyLua])
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 <string.h>
#include <ctype.h>
+#include "glspi_compat.h"
+
#include <geanyplugin.h>
#define main_widgets geany->main_widgets
diff --git a/geanylua/glspi_app.c b/geanylua/glspi_app.c
index b9a770267..e59215a34 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_compat.c b/geanylua/glspi_compat.c
new file mode 100644
index 000000000..d40158072
--- /dev/null
+++ b/geanylua/glspi_compat.c
@@ -0,0 +1,55 @@
+/* Lua compatibility functions */
+
+#include <lua.h>
+#include <lualib.h>
+#include <lauxlib.h>
+
+
+/*
+ * 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;
+ }
+ lua_getfield(L, -1, "traceback");
+ if (!lua_isfunction(L, -1)) {
+ lua_pop(L, 2);
+ return;
+ }
+ lua_pushvalue(L, 1);
+ lua_pushinteger(L, 2);
+ lua_call(L, 2, 1);
+
+ return;
+}
+
+#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_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 02543eab1..731cce18c 100644
--- a/geanylua/glspi_doc.c
+++ b/geanylua/glspi_doc.c
@@ -380,5 +380,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..e20161f88 100644
--- a/geanylua/glspi_kfile.c
+++ b/geanylua/glspi_kfile.c
@@ -12,6 +12,8 @@
#include <lualib.h>
#include <lauxlib.h>
+#include "glspi_compat.h"
+
#define LUA_MODULE_NAME "keyfile"
#define MetaName "_g_key_file_metatable"
@@ -395,8 +397,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..397ef27c2 100644
--- a/geanylua/gsdlg_lua.c
+++ b/geanylua/gsdlg_lua.c
@@ -35,6 +35,7 @@
#include <lualib.h>
#include <lauxlib.h>
+#include "glspi_compat.h"
#define GSDLG_ALL_IN_ONE
#include "gsdlg.h"
@@ -323,7 +324,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 +426,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;
}
|