summaryrefslogtreecommitdiff
path: root/src/if_lua.c
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/if_lua.c
parent766fb0d2b24c48545fa9fc9134b0843802223d64 (diff)
downloadvim-git-2334b6d59446dfa09680d4971b5fdb05c396ee79.tar.gz
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Diffstat (limited to 'src/if_lua.c')
-rw-r--r--src/if_lua.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/if_lua.c b/src/if_lua.c
index 133f2fc5f..4c3f9b715 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 */