From 8cb93bada561977eb370819e39d7d644e5fd0a3f Mon Sep 17 00:00:00 2001 From: Roberto I Date: Fri, 16 Oct 2026 11:16:12 -0300 Subject: [PATCH] Cast in 'rl_readline_name' In Mac OS, 'rl_readline_name' is declared as 'char*', instead of 'const char*', so we cannot assign to it a string literal such as "lua". --- lua.c | 3 ++- testes/main.lua | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lua.c b/lua.c index 858a04c0..f07bb95e 100644 --- a/lua.c +++ b/lua.c @@ -465,7 +465,8 @@ static int handle_luainit (lua_State *L) { #include #include -#define lua_initreadline(L) ((void)L, rl_readline_name="lua") +#define lua_initreadline(L) \ + ((void)L, *cast(const char **, &rl_readline_name)="lua") #define lua_readline(buff,prompt) ((void)buff, readline(prompt)) #define lua_saveline(line) add_history(line) #define lua_freeline(line) free(line) diff --git a/testes/main.lua b/testes/main.lua index 98d36951..6425faf0 100644 --- a/testes/main.lua +++ b/testes/main.lua @@ -199,14 +199,16 @@ assert(not string.find(defaultpath, "xxx") and -- (LUA_READLINELIB was introduced in 5.5.1) if release >= "5.5.1" then + -- OBS: this test is not valid when Lua is compiled with LUA_USE_READLINE print"testing readline library name" -- should generate a warning when trying to load inexistent library "xuxu" local env = [[LUA_READLINELIB=xuxu LUA_INIT="warn('@allow')"]] local code = 'echo " " | env %s lua %s -W -i >%s 2>&1' RUN(code, env, "", out) -- run code with no extra options - assert(string.find(getoutput(), - "warning: unable to load readline library 'xuxu'")) - + if(not string.find(getoutput(), + "warning: unable to load readline library 'xuxu'")) then + error("Is Lua compiled with option LUA_USE_READLINE?") + end RUN(code, env, "-E", out) -- run again with option -E -- no warning when LUA_READLINELIB is to be ignored assert(not string.find(getoutput(), "warning"))