aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lua.c24
-rw-r--r--testes/main.lua23
2 files changed, 40 insertions, 7 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 /* }{ */
diff --git a/testes/main.lua b/testes/main.lua
index dc48dc48..98d36951 100644
--- a/testes/main.lua
+++ b/testes/main.lua
@@ -78,6 +78,9 @@ end
78 78
79RUN('lua -v') 79RUN('lua -v')
80 80
81RUN('lua -v > %s', out)
82local release = string.match(getoutput(), "Lua (%d+%.%d+%.%d+)")
83
81print(string.format("(temporary program file used in these tests: %s)", prog)) 84print(string.format("(temporary program file used in these tests: %s)", prog))
82 85
83-- running stdin as a file 86-- running stdin as a file
@@ -167,7 +170,9 @@ checkout("10\n11\n")
167-- test errors in LUA_INIT 170-- test errors in LUA_INIT
168NoRun('LUA_INIT:1: msg', 'env LUA_INIT="error(\'msg\')" lua') 171NoRun('LUA_INIT:1: msg', 'env LUA_INIT="error(\'msg\')" lua')
169 172
170-- test option '-E' 173
174print("testing option '-E'")
175
171local defaultpath, defaultCpath 176local defaultpath, defaultCpath
172 177
173do 178do
@@ -192,6 +197,22 @@ assert(not string.find(defaultpath, "xxx") and
192 string.find(defaultCpath, "lua")) 197 string.find(defaultCpath, "lua"))
193 198
194 199
200-- (LUA_READLINELIB was introduced in 5.5.1)
201if release >= "5.5.1" then
202 print"testing readline library name"
203 -- should generate a warning when trying to load inexistent library "xuxu"
204 local env = [[LUA_READLINELIB=xuxu LUA_INIT="warn('@allow')"]]
205 local code = 'echo " " | env %s lua %s -W -i >%s 2>&1'
206 RUN(code, env, "", out) -- run code with no extra options
207 assert(string.find(getoutput(),
208 "warning: unable to load readline library 'xuxu'"))
209
210 RUN(code, env, "-E", out) -- run again with option -E
211 -- no warning when LUA_READLINELIB is to be ignored
212 assert(not string.find(getoutput(), "warning"))
213end
214
215
195-- test replacement of ';;' to default path 216-- test replacement of ';;' to default path
196local function convert (p) 217local function convert (p)
197 prepfile("print(package.path)") 218 prepfile("print(package.path)")