forked from enlightenment/efl
elua: do not link to cffi, load the module instead
This commit is contained in:
parent
db14b82549
commit
86ee71ce4d
10
meson.build
10
meson.build
|
@ -285,15 +285,7 @@ if get_option('lua-interpreter') == 'lua'
|
||||||
error('Lua not found')
|
error('Lua not found')
|
||||||
endif
|
endif
|
||||||
if have_elua
|
if have_elua
|
||||||
luaver_min = cc.compute_int('LUA_VERSION_NUM - 500',
|
message('Using experimental Elua with interpreter support...')
|
||||||
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
|
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
lua = dependency(get_option('lua-interpreter'))
|
lua = dependency(get_option('lua-interpreter'))
|
||||||
|
|
|
@ -2,10 +2,6 @@
|
||||||
#include <Ecore_File.h>
|
#include <Ecore_File.h>
|
||||||
#include "elua_private.h"
|
#include "elua_private.h"
|
||||||
|
|
||||||
#ifdef ENABLE_LUA_OLD
|
|
||||||
# include <cffi-lua.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static Eina_Prefix *_elua_pfx = NULL;
|
static Eina_Prefix *_elua_pfx = NULL;
|
||||||
|
|
||||||
static int _elua_init_counter = 0;
|
static int _elua_init_counter = 0;
|
||||||
|
@ -70,6 +66,18 @@ elua_shutdown(void)
|
||||||
return _elua_init_counter;
|
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 *
|
EAPI Elua_State *
|
||||||
elua_state_new(const char *progname)
|
elua_state_new(const char *progname)
|
||||||
{
|
{
|
||||||
|
@ -82,12 +90,35 @@ elua_state_new(const char *progname)
|
||||||
if (progname) ret->progname = eina_stringshare_add(progname);
|
if (progname) ret->progname = eina_stringshare_add(progname);
|
||||||
luaL_openlibs(L);
|
luaL_openlibs(L);
|
||||||
#ifdef ENABLE_LUA_OLD
|
#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_getglobal(L, "package");
|
||||||
lua_getfield(L, -1, "preload");
|
lua_getfield(L, -1, "preload");
|
||||||
lua_pushcfunction(L, luaopen_cffi);
|
lua_getfield(L, -2, "searchers");
|
||||||
lua_setfield(L, -2, "ffi");
|
if (lua_isnil(L, -1))
|
||||||
lua_pop(L, 2);
|
{
|
||||||
|
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
|
#endif
|
||||||
/* on 64-bit, split the state pointer into two and reconstruct later */
|
/* on 64-bit, split the state pointer into two and reconstruct later */
|
||||||
size_t retn = (size_t)ret;
|
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_ptr1");
|
||||||
lua_setfield(L, LUA_REGISTRYINDEX, "elua_ptr2");
|
lua_setfield(L, LUA_REGISTRYINDEX, "elua_ptr2");
|
||||||
return ret;
|
return ret;
|
||||||
|
err:
|
||||||
|
lua_close(L);
|
||||||
|
eina_stringshare_del(ret->progname);
|
||||||
|
free(ret);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
elua_deps = [eina, eo, efl, ecore, ecore_file, intl]
|
elua_deps = [eina, eo, efl, ecore, ecore_file, intl]
|
||||||
elua_pub_deps = [lua]
|
elua_pub_deps = [lua]
|
||||||
|
|
||||||
if get_option('lua-interpreter') == 'lua'
|
|
||||||
elua_deps += lua_ffi
|
|
||||||
endif
|
|
||||||
|
|
||||||
elua_src = ['elua.c', 'io.c', 'cache.c']
|
elua_src = ['elua.c', 'io.c', 'cache.c']
|
||||||
elua_header_src = ['Elua.h']
|
elua_header_src = ['Elua.h']
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue