summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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'
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
298else 290else
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
9static Eina_Prefix *_elua_pfx = NULL; 5static Eina_Prefix *_elua_pfx = NULL;
10 6
11static int _elua_init_counter = 0; 7static 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
70static 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
73EAPI Elua_State * 81EAPI Elua_State *
74elua_state_new(const char *progname) 82elua_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;
139err:
140 lua_close(L);
141 eina_stringshare_del(ret->progname);
142 free(ret);
143 return NULL;
108} 144}
109 145
110EAPI void 146EAPI 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 @@
1elua_deps = [eina, eo, efl, ecore, ecore_file, intl] 1elua_deps = [eina, eo, efl, ecore, ecore_file, intl]
2elua_pub_deps = [lua] 2elua_pub_deps = [lua]
3 3
4if get_option('lua-interpreter') == 'lua'
5 elua_deps += lua_ffi
6endif
7
8elua_src = ['elua.c', 'io.c', 'cache.c'] 4elua_src = ['elua.c', 'io.c', 'cache.c']
9elua_header_src = ['Elua.h'] 5elua_header_src = ['Elua.h']
10 6