summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2010-07-22 21:32:16 +0200
committerBram Moolenaar <Bram@vim.org>2010-07-22 21:32:16 +0200
commit2334b6d59446dfa09680d4971b5fdb05c396ee79 (patch)
treef16c0149bad87220b8d096d323183ff765b88b4a /src
parent766fb0d2b24c48545fa9fc9134b0843802223d64 (diff)
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Diffstat (limited to 'src')
-rw-r--r--src/Makefile10
-rwxr-xr-xsrc/auto/configure10
-rw-r--r--src/config.h.in3
-rw-r--r--src/configure.in9
-rw-r--r--src/if_lua.c27
-rw-r--r--src/proto/if_lua.pro1
6 files changed, 46 insertions, 14 deletions
diff --git a/src/Makefile b/src/Makefile
index 59aca22da6..f0c2316f62 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -370,8 +370,10 @@ CClink = $(CC)
#CONF_OPT_DARWIN = --with-mac-arch=both
# LUA
-# Uncomment this when you want to include the Lua interface.
+# Uncomment one of these when you want to include the Lua interface.
+# First one is for static linking, second one for dynamic loading.
#CONF_OPT_LUA = --enable-luainterp
+#CONF_OPT_LUA = --enable-luainterp=dynamic
# Lua installation dir (when not set uses $LUA_PREFIX or defaults to /usr)
#CONF_OPT_LUA_PREFIX = --with-lua-prefix=/usr/local
@@ -1314,7 +1316,7 @@ SHELL = /bin/sh
.SUFFIXES: .c .o .pro
PRE_DEFS = -Iproto $(DEFS) $(GUI_DEFS) $(GUI_IPATH) $(CPPFLAGS) $(EXTRA_IPATHS)
-POST_DEFS = $(X_CFLAGS) $(LUA_CFLAGS) $(MZSCHEME_CFLAGS) $(TCL_CFLAGS) $(RUBY_CFLAGS) $(EXTRA_DEFS)
+POST_DEFS = $(X_CFLAGS) $(MZSCHEME_CFLAGS) $(TCL_CFLAGS) $(RUBY_CFLAGS) $(EXTRA_DEFS)
ALL_CFLAGS = $(PRE_DEFS) $(CFLAGS) $(PROFILE_CFLAGS) $(POST_DEFS)
@@ -1322,7 +1324,7 @@ ALL_CFLAGS = $(PRE_DEFS) $(CFLAGS) $(PROFILE_CFLAGS) $(POST_DEFS)
# with "-E".
OSDEF_CFLAGS = $(PRE_DEFS) $(POST_DEFS)
-LINT_CFLAGS = -DLINT -I. $(PRE_DEFS) $(POST_DEFS) $(PYTHON_CFLAGS) -Dinline= -D__extension__= -Dalloca=alloca
+LINT_CFLAGS = -DLINT -I. $(PRE_DEFS) $(POST_DEFS) $(LUA_CFLAGS) $(PERL_CFLAGS) $(PYTHON_CFLAGS) -Dinline= -D__extension__= -Dalloca=alloca
LINT_EXTRA = -DUSE_SNIFF -DHANGUL_INPUT -D"__attribute__(x)="
@@ -2488,7 +2490,7 @@ objects/if_xcmdsrv.o: if_xcmdsrv.c
$(CCC) -o $@ if_xcmdsrv.c
objects/if_lua.o: if_lua.c
- $(CCC) -o $@ if_lua.c
+ $(CCC) $(LUA_CFLAGS) -o $@ if_lua.c
objects/if_mzsch.o: if_mzsch.c $(MZSCHEME_EXTRA)
$(CCC) -o $@ $(MZSCHEME_CFLAGS_EXTRA) if_mzsch.c
diff --git a/src/auto/configure b/src/auto/configure
index 12ec72124f..4ab3ae649f 100755
--- a/src/auto/configure
+++ b/src/auto/configure
@@ -1421,7 +1421,7 @@ Optional Features:
--disable-selinux Don't check for SELinux support.
--disable-xsmp Disable XSMP session management
--disable-xsmp-interact Disable XSMP interaction
- --enable-luainterp Include Lua interpreter.
+ --enable-luainterp=OPTS Include Lua interpreter. default=no OPTS=no/yes/dynamic
--enable-mzschemeinterp Include MzScheme interpreter.
--enable-perlinterp=OPTS Include Perl interpreter. default=no OPTS=no/yes/dynamic
--enable-pythoninterp Include Python interpreter.
@@ -4594,7 +4594,7 @@ fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_luainterp" >&5
$as_echo "$enable_luainterp" >&6; }
-if test "$enable_luainterp" = "yes"; then
+if test "$enable_luainterp" = "yes" -o "$enable_luainterp" = "dynamic"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking --with-lua-prefix argument" >&5
@@ -4713,6 +4713,12 @@ $as_echo "no" >&6; }
LUA_PRO="if_lua.pro"
$as_echo "#define FEAT_LUA 1" >>confdefs.h
+ if test "$enable_luainterp" = "dynamic"; then
+ $as_echo "#define DYNAMIC_LUA 1" >>confdefs.h
+
+ LUA_LIBS=""
+ LUA_CFLAGS="-DDYNAMIC_LUA_DLL=\\\"liblua${vi_cv_version_lua}.so\\\" $LUA_CFLAGS"
+ fi
fi
diff --git a/src/config.h.in b/src/config.h.in
index 3e86b847c0..2a28e0eb4e 100644
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -319,6 +319,9 @@
/* Define if you want to include the Lua interpreter. */
#undef FEAT_LUA
+/* Define for linking via dlopen() or LoadLibrary() */
+#undef DYNAMIC_LUA
+
/* Define if you want to include the MzScheme interpreter. */
#undef FEAT_MZSCHEME
diff --git a/src/configure.in b/src/configure.in
index b10d5c9da9..0492eb08dd 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -413,11 +413,11 @@ fi
dnl Check for Lua feature.
AC_MSG_CHECKING(--enable-luainterp argument)
AC_ARG_ENABLE(luainterp,
- [ --enable-luainterp Include Lua interpreter.], ,
+ [ --enable-luainterp[=OPTS] Include Lua interpreter. [default=no] [OPTS=no/yes/dynamic]], ,
[enable_luainterp="no"])
AC_MSG_RESULT($enable_luainterp)
-if test "$enable_luainterp" = "yes"; then
+if test "$enable_luainterp" = "yes" -o "$enable_luainterp" = "dynamic"; then
dnl -- find the lua executable
AC_SUBST(vi_cv_path_lua)
@@ -477,6 +477,11 @@ if test "$enable_luainterp" = "yes"; then
LUA_OBJ="objects/if_lua.o"
LUA_PRO="if_lua.pro"
AC_DEFINE(FEAT_LUA)
+ if test "$enable_luainterp" = "dynamic"; then
+ AC_DEFINE(DYNAMIC_LUA)
+ LUA_LIBS=""
+ LUA_CFLAGS="-DDYNAMIC_LUA_DLL=\\\"liblua${vi_cv_version_lua}.so\\\" $LUA_CFLAGS"
+ fi
fi
AC_SUBST(LUA_SRC)
AC_SUBST(LUA_OBJ)
diff --git a/src/if_lua.c b/src/if_lua.c
index 133f2fc5fa..4c3f9b715f 100644
--- a/src/if_lua.c
+++ b/src/if_lua.c
@@ -41,6 +41,19 @@ static const char LUAVIM_FREE[] = "luaV_free";
#ifdef DYNAMIC_LUA
+
+#ifndef WIN3264
+# include <dlfcn.h>
+# define HANDLE void*
+# define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL)
+# define symbol_from_dll dlsym
+# define close_dll dlclose
+#else
+# define load_dll LoadLibrary
+# define symbol_from_dll GetProcAddress
+# define close_dll FreeLibrary
+#endif
+
/* lauxlib */
#define luaL_register dll_luaL_register
#define luaL_typerror dll_luaL_typerror
@@ -227,14 +240,14 @@ static const luaV_Reg luaV_dll[] = {
{NULL, NULL}
};
-static HINSTANCE hinstLua = 0;
+static HANDLE hinstLua = NULL;
static void
end_dynamic_lua(void)
{
if (hinstLua)
{
- FreeLibrary(hinstLua);
+ close_dll(hinstLua);
hinstLua = 0;
}
}
@@ -244,7 +257,7 @@ lua_link_init(char *libname, int verbose)
{
const luaV_Reg *reg;
if (hinstLua) return OK;
- hinstLua = LoadLibrary(libname);
+ hinstLua = load_dll(libname);
if (!hinstLua)
{
if (verbose)
@@ -253,8 +266,9 @@ lua_link_init(char *libname, int verbose)
}
for (reg = luaV_dll; reg->func; reg++)
{
- if ((*reg->func = GetProcAddress(hinstLua, reg->name)) == NULL) {
- FreeLibrary(hinstLua);
+ if ((*reg->func = symbol_from_dll(hinstLua, reg->name)) == NULL)
+ {
+ close_dll(hinstLua);
hinstLua = 0;
if (verbose)
EMSG2(_(e_loadfunc), reg->name);
@@ -364,7 +378,8 @@ luaV_pushtypval(lua_State *L, typval_T *tv)
/* check cache */
lua_pushlightuserdata(L, (void *) d);
lua_rawget(L, LUA_ENVIRONINDEX);
- if (lua_isnil(L, -1)) { /* not interned? */
+ if (lua_isnil(L, -1)) /* not interned? */
+ {
hashtab_T *ht = &d->dv_hashtab;
hashitem_T *hi;
int n = ht->ht_used; /* remaining items */
diff --git a/src/proto/if_lua.pro b/src/proto/if_lua.pro
index fb80ae02d0..3bac4cce8a 100644
--- a/src/proto/if_lua.pro
+++ b/src/proto/if_lua.pro
@@ -1,4 +1,5 @@
/* if_lua.c */
+int lua_enabled __ARGS((int verbose));
void lua_end __ARGS((void));
void ex_lua __ARGS((exarg_T *eap));
void ex_luado __ARGS((exarg_T *eap));