lua.c loads 'readline' dynamically · lua/lua@366c855 · GitHub
Skip to content

Commit 366c855

Browse files
committed
lua.c loads 'readline' dynamically
(See comments in luaconf.h.) This change allows easier compilation, as Lua compiles and works even if the package 'readline' is absent from the system. Moreover, non-interactive uses don't load the library, making the stand-alone slightly faster for small loads.
1 parent 781219d commit 366c855

4 files changed

Lines changed: 90 additions & 29 deletions

File tree

‎lua.c‎

Lines changed: 70 additions & 18 deletions

‎luaconf.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,26 @@
5858
#endif
5959

6060

61+
/*
62+
** When Posix DLL ('LUA_USE_DLOPEN') is enabled, the Lua stand-alone
63+
** application will try to dynamically link a 'readline' facility
64+
** for its REPL. In that case, LUA_READLINELIB is the name of the
65+
** library it will look for those facilities. If lua.c cannot open
66+
** the specified library, it will generate a warning and then run
67+
** without 'readline'. If that macro is not defined, lua.c will not
68+
** use 'readline'.
69+
*/
6170
#if defined(LUA_USE_LINUX)
6271
#define LUA_USE_POSIX
6372
#define LUA_USE_DLOPEN /* needs an extra library: -ldl */
73+
#define LUA_READLINELIB "libreadline.so"
6474
#endif
6575

6676

6777
#if defined(LUA_USE_MACOSX)
6878
#define LUA_USE_POSIX
6979
#define LUA_USE_DLOPEN /* MacOS does not need -ldl */
80+
#define LUA_READLINELIB "libedit.dylib"
7081
#endif
7182

7283

‎makefile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ LOCAL = $(TESTS) $(CWARNS)
7070

7171

7272
# enable Linux goodies
73-
MYCFLAGS= $(LOCAL) -std=c99 -DLUA_USE_LINUX -DLUA_USE_READLINE
73+
MYCFLAGS= $(LOCAL) -std=c99 -DLUA_USE_LINUX
7474
MYLDFLAGS= $(LOCAL) -Wl,-E
75-
MYLIBS= -ldl -lreadline
75+
MYLIBS= -ldl
7676

7777

7878
CC= gcc

‎testes/main.lua‎

Lines changed: 7 additions & 9 deletions

0 commit comments

Comments
 (0)