summaryrefslogtreecommitdiff
path: root/src
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 /src
parentdb14b825494057145788becf712a6451749a474a (diff)
elua: do not link to cffi, load the module instead
Diffstat (limited to 'src')
-rw-r--r--src/lib/elua/elua.c52
-rw-r--r--src/lib/elua/meson.build4
2 files changed, 44 insertions, 12 deletions
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