aboutsummaryrefslogtreecommitdiff
path: root/lua.c
diff options
context:
space:
mode:
Diffstat (limited to 'lua.c')
-rw-r--r--lua.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/lua.c b/lua.c
index 37fd1cb8..3f4fc9f7 100644
--- a/lua.c
+++ b/lua.c
@@ -30,6 +30,12 @@
30#define LUA_INIT_VAR "LUA_INIT" 30#define LUA_INIT_VAR "LUA_INIT"
31#endif 31#endif
32 32
33/* Name of the environment variable with the name of the readline library */
34#if !defined(LUA_RLLIB_VAR)
35#define LUA_RLLIB_VAR "LUA_READLINELIB"
36#endif
37
38
33#define LUA_INITVARVERSION LUA_INIT_VAR LUA_VERSUFFIX 39#define LUA_INITVARVERSION LUA_INIT_VAR LUA_VERSUFFIX
34 40
35 41
@@ -507,18 +513,24 @@ static void lua_freeline (char *line) {
507#include <dlfcn.h> 513#include <dlfcn.h>
508 514
509static void lua_initreadline (lua_State *L) { 515static void lua_initreadline (lua_State *L) {
510 void *lib = dlopen(LUA_READLINELIB, RTLD_NOW | RTLD_LOCAL); 516 const char *rllib = l_getenv(LUA_RLLIB_VAR); /* name of readline library */
511 if (lib == NULL) 517 void *lib; /* library handle */
512 lua_warning(L, "library '" LUA_READLINELIB "' not found", 0); 518 if (rllib == NULL) /* no environment variable? */
513 else { 519 rllib = LUA_READLINELIB; /* use default name */
520 lib = dlopen(rllib, RTLD_NOW | RTLD_LOCAL);
521 if (lib != NULL) {
514 const char **name = cast(const char**, dlsym(lib, "rl_readline_name")); 522 const char **name = cast(const char**, dlsym(lib, "rl_readline_name"));
515 if (name != NULL) 523 if (name != NULL)
516 *name = "lua"; 524 *name = "lua";
517 l_readline = cast(l_readlineT, cast_func(dlsym(lib, "readline"))); 525 l_readline = cast(l_readlineT, cast_func(dlsym(lib, "readline")));
518 l_addhist = cast(l_addhistT, cast_func(dlsym(lib, "add_history"))); 526 l_addhist = cast(l_addhistT, cast_func(dlsym(lib, "add_history")));
519 if (l_readline == NULL) 527 if (l_readline != NULL) /* could load readline function? */
520 lua_warning(L, "unable to load 'readline'", 0); 528 return; /* everything ok */
529 /* else emit a warning */
521 } 530 }
531 lua_warning(L, "unable to load readline library '", 1);
532 lua_warning(L, rllib, 1);
533 lua_warning(L, "'", 0);
522} 534}
523 535
524#else /* }{ */ 536#else /* }{ */