summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2020-07-31 18:21:15 +0200
committerDaniel Kolesa <d.kolesa@samsung.com>2020-07-31 19:01:53 +0200
commit86ee71ce4d792c7e73bf8dd07d89add1d00e93bb (patch)
tree12a1fb603eb36a43042910ab0d6aff137a089225
parentdb14b825494057145788becf712a6451749a474a (diff)
downloadefl-86ee71ce4d792c7e73bf8dd07d89add1d00e93bb.tar.gz
elua: do not link to cffi, load the module instead
-rw-r--r--meson.build10
-rw-r--r--src/lib/elua/elua.c52
-rw-r--r--src/lib/elua/meson.build4
3 files changed, 45 insertions, 21 deletions
diff --git a/meson.build b/meson.build
index 90116b67d3..c5078100f4 100644
--- a/meson.build
+++ b/meson.build
@@ -285,15 +285,7 @@ if get_option('lua-interpreter') == 'lua'
error('Lua not found')
endif
if have_elua
- luaver_min = cc.compute_int('LUA_VERSION_NUM - 500',
- prefix: '#include <lua.h>', dependencies: lua
- )
- lua_ffi = dependency('cffi-lua-5.@0@'.format(luaver_min), required: false)
- if not lua_ffi.found()
- error('Elua with interpreter is experimental, disable it or install cffi-lua...')
- else
- message('Using experimental Elua with interpreter support...')
- endif
+ message('Using experimental Elua with interpreter support...')
endif
else
lua = dependency(get_option('lua-interpreter'))
diff --git a/src/lib/elua/elua.c b/src/lib/elua/elua.c
index b691ff524d..3834df1504 100644
--- a/src/lib/elua/elua.c
+++ b/src/lib/elua/elua.c
@@ -2,10 +2,6 @@
#include <Ecore_File.h>
#include "elua_private.h"
-#ifdef ENABLE_LUA_OLD
-# include <cffi-lua.h>
-#endif
-
static Eina_Prefix *_elua_pfx = NULL;
static int _elua_init_counter = 0;
@@ -70,6 +66,18 @@ elua_shutdown(void)
return _elua_init_counter;
}
+#ifdef ENABLE_LUA_OLD
+static int
+_ffi_loader(lua_State *L)
+{
+ lua_pushvalue(L, lua_upvalueindex(1));
+ lua_pushliteral(L, "cffi");
+ lua_pushvalue(L, lua_upvalueindex(2));
+ lua_call(L, 2, 1);
+ return 1;
+}
+#endif
+
EAPI Elua_State *
elua_state_new(const char *progname)
{
@@ -82,12 +90,35 @@ elua_state_new(const char *progname)
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 */
+ /* search for cffi-lua early, and pass it through as ffi */
lua_getglobal(L, "package");
lua_getfield(L, -1, "preload");
- lua_pushcfunction(L, luaopen_cffi);
- lua_setfield(L, -2, "ffi");
- lua_pop(L, 2);
+ lua_getfield(L, -2, "searchers");
+ if (lua_isnil(L, -1))
+ {
+ lua_pop(L, 1);
+ lua_getfield(L, -2, "loaders");
+ }
+ if (lua_isnil(L, -1))
+ {
+ ERR("could not find a module searcher");
+ goto err;
+ }
+ lua_rawgeti(L, -1, 3);
+ lua_pushliteral(L, "cffi");
+ if (lua_pcall(L, 1, 2, 0))
+ {
+ ERR("could not find the cffi module");
+ goto err;
+ }
+ if (!lua_isfunction(L, -2))
+ {
+ ERR("could not find the cffi module: %s", lua_tostring(L, -2));
+ goto err;
+ }
+ lua_pushcclosure(L, _ffi_loader, 2);
+ lua_setfield(L, -3, "ffi");
+ lua_pop(L, 3);
#endif
/* on 64-bit, split the state pointer into two and reconstruct later */
size_t retn = (size_t)ret;
@@ -105,6 +136,11 @@ elua_state_new(const char *progname)
lua_setfield(L, LUA_REGISTRYINDEX, "elua_ptr1");
lua_setfield(L, LUA_REGISTRYINDEX, "elua_ptr2");
return ret;
+err:
+ lua_close(L);
+ eina_stringshare_del(ret->progname);
+ free(ret);
+ return NULL;
}
EAPI void
diff --git a/src/lib/elua/meson.build b/src/lib/elua/meson.build
index 66bd9454b9..227d211584 100644
--- a/src/lib/elua/meson.build
+++ b/src/lib/elua/meson.build
@@ -1,10 +1,6 @@
elua_deps = [eina, eo, efl, ecore, ecore_file, intl]
elua_pub_deps = [lua]
-if get_option('lua-interpreter') == 'lua'
- elua_deps += lua_ffi
-endif
-
elua_src = ['elua.c', 'io.c', 'cache.c']
elua_header_src = ['Elua.h']