exit(c);
}
+#if LUA_VERSION_NUM < 502
+# define elua_cpcall(L, f, u) lua_cpcall(L, f, u)
+#else
+# define elua_cpcall(L, f, u) \
+ (lua_pushcfunction(L, f), lua_pushlightuserdata(L, u), lua_pcall(L, 1, 0, 0))
+#endif
+
int
main(int argc, char **argv)
{
m.argv = argv;
m.status = 0;
- elua_bin_shutdown(es, !!(lua_cpcall(elua_state_lua_state_get(es), elua_main, &m) || m.status));
+ elua_bin_shutdown(es, !!(elua_cpcall(elua_state_lua_state_get(es), elua_main, &m) || m.status));
return 0; /* never gets here */
}
/* bytecode caching */
+#if LUA_VERSION_NUM > 501
+# define elua_load(L, reader, data, chunkname) lua_load(L, reader, data, chunkname, NULL)
+#else
+# define elua_load(L, reader, data, chunkname) lua_load(L, reader, data, chunkname)
+#endif
+
static Eina_File *
check_bc(Eina_File *of, const char *fname, Eina_Bool *bc)
{
elua_loadstdin(lua_State *L)
{
char buff[LUAL_BUFFERSIZE];
- int status = lua_load(L, getf, &buff, "=stdin");
+ int status = elua_load(L, getf, &buff, "=stdin");
if (ferror(stdin))
{
lua_pop(L, 1);
lua_remove(L, -2);
return LUA_ERRFILE;
}
- status = lua_load(L, getf_map, &s, chname);
+ status = elua_load(L, getf_map, &s, chname);
eina_file_map_free(f, s.fmap);
eina_file_close(f);
if (status)
}
/* loaded original file, pop old error and load again */
lua_pop(L, 1);
- status = lua_load(L, getf_map, &s, chname);
+ status = elua_load(L, getf_map, &s, chname);
eina_file_map_free(f, s.fmap);
eina_file_close(f);
/* force write new bytecode */
if (hasenv)
{
lua_pushvalue(L, 3);
+#if LUA_VERSION_NUM < 502
lua_setfenv(L, -2);
+#else
+ if (!lua_setupvalue(L, -2, 1))
+ lua_pop(L, 1);
+#endif
}
return 1;
}
return _elua_init_counter;
}
+#ifdef ENABLE_LUA_OLD
+int luaopen_cffi(lua_State *L);
+#endif
+
EAPI Elua_State *
elua_state_new(const char *progname)
{
ret->luastate = L;
if (progname) ret->progname = eina_stringshare_add(progname);
luaL_openlibs(L);
+#ifdef ENABLE_LUA_OLD
+ /* make sure to inject cffi-lua to preload so that the system gets it */
+ lua_getglobal(L, "package");
+ lua_getfield(L, -1, "preload");
+ lua_pushcfunction(L, luaopen_cffi);
+ lua_setfield(L, -2, "ffi");
+ lua_pop(L, 2);
+#endif
/* on 64-bit, split the state pointer into two and reconstruct later */
size_t retn = (size_t)ret;
if (sizeof(void *) < sizeof(lua_Number))
if (elua_util_error_report(es, elua_io_loadfile(es, buf)))
return EINA_FALSE;
lua_createtable(es->luastate, 0, 0);
- luaL_register(es->luastate, NULL, gettextlib);
+ elua_register(es->luastate, gettextlib);
lua_call(es->luastate, 1, 0);
return EINA_TRUE;
}
return EINA_FALSE;
lua_pushcfunction(es->luastate, _elua_module_system_init);
lua_createtable(es->luastate, 0, 0);
- luaL_register(es->luastate, NULL, _elua_cutillib);
+ elua_register(es->luastate, _elua_cutillib);
lua_call(es->luastate, 2, 0);
return EINA_TRUE;
}
int _elua_io_popen(lua_State *L);
Eina_Bool _elua_state_io_setup(const Elua_State *es);
+#if LUA_VERSION_NUM < 502
+
+#define elua_register(L, lib) luaL_register(L, NULL, 0)
+#define elua_rawlen(L, i) lua_rawlen(L, i)
+
+#else
+
+#define elua_register(L, lib) luaL_setfuncs(L, lib, 0)
+#define elua_rawlen(L, i) lua_rawlen(L, i)
+
+#endif
+
#endif
if (fgets(p, LUAL_BUFFERSIZE, f) == NULL)
{
luaL_pushresult(&b);
- return (lua_strlen(L, -1) > 0);
+ return (elua_rawlen(L, -1) > 0);
}
l = strlen(p);
if (!l || p[l - 1] != '\n')
n -= nr;
} while (n > 0 && nr == rlen);
luaL_pushresult(&b);
- return (n == 0 || lua_strlen(L, -1) > 0);
+ return (n == 0 || elua_rawlen(L, -1) > 0);
}
static int
{
lua_pushvalue(L, -1);
lua_setfield (L, -2, "__index");
- luaL_register(L, NULL, elua_popenlib);
+ elua_register(L, elua_popenlib);
}
lua_setmetatable(L, -2);
return f;
elua_deps = [eina, eo, efl, ecore, ecore_file, intl]
elua_pub_deps = [lua]
+if get_option('lua-interpreter') == 'lua'
+ luaver_min = cc.compute_int('LUA_VERSION_NUM - 500',
+ prefix: '#include <lua.h>', dependencies: lua
+ )
+ elua_deps += dependency('cffi-lua-5.@0@'.format(luaver_min))
+endif
+
elua_src = ['elua.c', 'io.c', 'cache.c']
elua_header_src = ['Elua.h']