diff options
author | Daniel Kolesa <d.kolesa@samsung.com> | 2020-07-31 18:21:15 +0200 |
---|---|---|
committer | Daniel Kolesa <d.kolesa@samsung.com> | 2020-07-31 19:01:53 +0200 |
commit | 86ee71ce4d792c7e73bf8dd07d89add1d00e93bb (patch) | |
tree | 12a1fb603eb36a43042910ab0d6aff137a089225 | |
parent | db14b825494057145788becf712a6451749a474a (diff) |
elua: do not link to cffi, load the module instead
-rw-r--r-- | meson.build | 10 | ||||
-rw-r--r-- | src/lib/elua/elua.c | 52 | ||||
-rw-r--r-- | src/lib/elua/meson.build | 4 |
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' | |||
285 | error('Lua not found') | 285 | error('Lua not found') |
286 | endif | 286 | endif |
287 | if have_elua | 287 | if have_elua |
288 | luaver_min = cc.compute_int('LUA_VERSION_NUM - 500', | 288 | message('Using experimental Elua with interpreter support...') |
289 | prefix: '#include <lua.h>', dependencies: lua | ||
290 | ) | ||
291 | lua_ffi = dependency('cffi-lua-5.@0@'.format(luaver_min), required: false) | ||
292 | if not lua_ffi.found() | ||
293 | error('Elua with interpreter is experimental, disable it or install cffi-lua...') | ||
294 | else | ||
295 | message('Using experimental Elua with interpreter support...') | ||
296 | endif | ||
297 | endif | 289 | endif |
298 | else | 290 | else |
299 | lua = dependency(get_option('lua-interpreter')) | 291 | 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 @@ | |||
2 | #include <Ecore_File.h> | 2 | #include <Ecore_File.h> |
3 | #include "elua_private.h" | 3 | #include "elua_private.h" |
4 | 4 | ||
5 | #ifdef ENABLE_LUA_OLD | ||
6 | # include <cffi-lua.h> | ||
7 | #endif | ||
8 | |||
9 | static Eina_Prefix *_elua_pfx = NULL; | 5 | static Eina_Prefix *_elua_pfx = NULL; |
10 | 6 | ||
11 | static int _elua_init_counter = 0; | 7 | static int _elua_init_counter = 0; |
@@ -70,6 +66,18 @@ elua_shutdown(void) | |||
70 | return _elua_init_counter; | 66 | return _elua_init_counter; |
71 | } | 67 | } |
72 | 68 | ||
69 | #ifdef ENABLE_LUA_OLD | ||
70 | static int | ||
71 | _ffi_loader(lua_State *L) | ||
72 | { | ||
73 | lua_pushvalue(L, lua_upvalueindex(1)); | ||
74 | lua_pushliteral(L, "cffi"); | ||
75 | lua_pushvalue(L, lua_upvalueindex(2)); | ||
76 | lua_call(L, 2, 1); | ||
77 | return 1; | ||
78 | } | ||
79 | #endif | ||
80 | |||
73 | EAPI Elua_State * | 81 | EAPI Elua_State * |
74 | elua_state_new(const char *progname) | 82 | elua_state_new(const char *progname) |
75 | { | 83 | { |
@@ -82,12 +90,35 @@ elua_state_new(const char *progname) | |||
82 | if (progname) ret->progname = eina_stringshare_add(progname); | 90 | if (progname) ret->progname = eina_stringshare_add(progname); |
83 | luaL_openlibs(L); | 91 | luaL_openlibs(L); |
84 | #ifdef ENABLE_LUA_OLD | 92 | #ifdef ENABLE_LUA_OLD |
85 | /* make sure to inject cffi-lua to preload so that the system gets it */ | 93 | /* search for cffi-lua early, and pass it through as ffi */ |
86 | lua_getglobal(L, "package"); | 94 | lua_getglobal(L, "package"); |
87 | lua_getfield(L, -1, "preload"); | 95 | lua_getfield(L, -1, "preload"); |
88 | lua_pushcfunction(L, luaopen_cffi); | 96 | lua_getfield(L, -2, "searchers"); |
89 | lua_setfield(L, -2, "ffi"); | 97 | if (lua_isnil(L, -1)) |
90 | lua_pop(L, 2); | 98 | { |
99 | lua_pop(L, 1); | ||
100 | lua_getfield(L, -2, "loaders"); | ||
101 | } | ||
102 | if (lua_isnil(L, -1)) | ||
103 | { | ||
104 | ERR("could not find a module searcher"); | ||
105 | goto err; | ||
106 | } | ||
107 | lua_rawgeti(L, -1, 3); | ||
108 | lua_pushliteral(L, "cffi"); | ||
109 | if (lua_pcall(L, 1, 2, 0)) | ||
110 | { | ||
111 | ERR("could not find the cffi module"); | ||
112 | goto err; | ||
113 | } | ||
114 | if (!lua_isfunction(L, -2)) | ||
115 | { | ||
116 | ERR("could not find the cffi module: %s", lua_tostring(L, -2)); | ||
117 | goto err; | ||
118 | } | ||
119 | lua_pushcclosure(L, _ffi_loader, 2); | ||
120 | lua_setfield(L, -3, "ffi"); | ||
121 | lua_pop(L, 3); | ||
91 | #endif | 122 | #endif |
92 | /* on 64-bit, split the state pointer into two and reconstruct later */ | 123 | /* on 64-bit, split the state pointer into two and reconstruct later */ |
93 | size_t retn = (size_t)ret; | 124 | size_t retn = (size_t)ret; |
@@ -105,6 +136,11 @@ elua_state_new(const char *progname) | |||
105 | lua_setfield(L, LUA_REGISTRYINDEX, "elua_ptr1"); | 136 | lua_setfield(L, LUA_REGISTRYINDEX, "elua_ptr1"); |
106 | lua_setfield(L, LUA_REGISTRYINDEX, "elua_ptr2"); | 137 | lua_setfield(L, LUA_REGISTRYINDEX, "elua_ptr2"); |
107 | return ret; | 138 | return ret; |
139 | err: | ||
140 | lua_close(L); | ||
141 | eina_stringshare_del(ret->progname); | ||
142 | free(ret); | ||
143 | return NULL; | ||
108 | } | 144 | } |
109 | 145 | ||
110 | EAPI void | 146 | 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 @@ | |||
1 | elua_deps = [eina, eo, efl, ecore, ecore_file, intl] | 1 | elua_deps = [eina, eo, efl, ecore, ecore_file, intl] |
2 | elua_pub_deps = [lua] | 2 | elua_pub_deps = [lua] |
3 | 3 | ||
4 | if get_option('lua-interpreter') == 'lua' | ||
5 | elua_deps += lua_ffi | ||
6 | endif | ||
7 | |||
8 | elua_src = ['elua.c', 'io.c', 'cache.c'] | 4 | elua_src = ['elua.c', 'io.c', 'cache.c'] |
9 | elua_header_src = ['Elua.h'] | 5 | elua_header_src = ['Elua.h'] |
10 | 6 | ||