Skip to content
This repository
Browse code

Fix Lua 5.2 incompatibilities

  • Loading branch information...
commit 987123f4d875fd2bbf05f16e0eef39db0f4ebbe5 1 parent 07bbe77
Pavel Holejsovsky authored
4 lgi/callable.c
@@ -801,7 +801,11 @@ closure_callback (ffi_cif *cif, void *ret, void **args, void *closure_arg)
801 801 }
802 802 else
803 803 {
  804 +#if LUA_VERSION_NUM >= 502
  805 + res = lua_resume (L, NULL, npos);
  806 +#else
804 807 res = lua_resume (L, npos);
  808 +#endif
805 809
806 810 if (res == LUA_YIELD)
807 811 /* For our purposes is YIELD the same as if the coro really
14 lgi/lgi.h
@@ -11,16 +11,20 @@
11 11 #include <lua.h>
12 12 #include <lauxlib.h>
13 13
  14 +/* Lua 5.2 compatibility stuff. */
  15 +#if LUA_VERSION_NUM >= 502
  16 +#define luaL_register(L, null, regs) luaL_setfuncs (L, regs, 0)
  17 +#define lua_equal(L, p1, p2) lua_compare (L, p1, p2, LUA_OPEQ)
  18 +#define lua_objlen(L, p) lua_rawlen (L, p)
  19 +#define lua_setfenv(L, p) lua_setuservalue (L, p)
  20 +#define lua_getfenv(L, p) lua_getuservalue (L, p)
  21 +#endif
  22 +
14 23 #include <glib.h>
15 24 #include <glib-object.h>
16 25 #include <glib/gprintf.h>
17 26 #include <girepository.h>
18 27
19   -/* Lua stack dump for debugging purposes. */
20   -#ifndef NDEBUG
21   -const char *lgi_sd (lua_State* L);
22   -#endif
23   -
24 28 /* Makes sure that Lua stack offset is absolute one, not relative. */
25 29 #define lgi_makeabs(L, x) do { if (x < 0) x += lua_gettop (L) + 1; } while (0)
26 30
2  lgi/marshal.c
@@ -761,7 +761,7 @@ lgi_marshal_2c (lua_State *L, GITypeInfo *ti, GIArgInfo *ai,
761 761 {
762 762 gboolean result;
763 763 if (!optional && lua_isnoneornil (L, narg))
764   - luaL_typerror (L, narg, lua_typename (L, LUA_TBOOLEAN));
  764 + luaL_argerror (L, narg, "boolean expected");
765 765 result = lua_toboolean (L, narg) ? TRUE : FALSE;
766 766 if (parent == PARENT_FORCE_POINTER)
767 767 arg->v_pointer = GINT_TO_POINTER (result);
2  samples/console.lua
@@ -221,7 +221,7 @@ local function Console()
221 221 append_output(text:gsub('\n*$', '\n', 1), 'command')
222 222
223 223 -- Try to execute the command.
224   - local chunk, answer = loadstring(text, '=stdin')
  224 + local chunk, answer = (loadstring or load)(text, '=stdin')
225 225 local tag = 'error'
226 226 if not chunk then
227 227 answer = answer:gsub('\n*$', '\n', 1)
2  samples/gtkterminal.lua
@@ -193,7 +193,7 @@ end
193 193 function readline.commit(line)
194 194 -- Try to execute input line.
195 195 line = line:gsub('^%s?(=)%s*', 'return ')
196   - local chunk, answer = loadstring(line, '=stdin')
  196 + local chunk, answer = (loadstring or load)(line, '=stdin')
197 197 if chunk then
198 198 (function(ok, ...)
199 199 if not ok then

0 comments on commit 987123f

Please sign in to comment.
Something went wrong with that request. Please try again.