1 /* sa-config.c -- configuration for stand-alone Lua interpreter
3 * #define LUA_USERCONFIG to this file
5 * Here are the features that can be customized using #define:
7 *** Line edit and history:
8 * #define USE_READLINE to use the GNU readline library.
10 * To use another library for this, use the code below as a start.
11 * Make sure you #define lua_readline and lua_saveline accordingly.
12 * If you do not #define lua_readline, you'll get a version based on fgets
13 * that uses a static buffer of size MAXINPUT.
16 *** Static Lua libraries to be loaded at startup:
17 * #define lua_userinit(L) to a Lua function that loads libraries; typically
18 * #define lua_userinit(L) openstdlibs(L);myinit(L)
20 * #define lua_userinit(L) myinit(L)
22 * Another way is to add the prototypes of the init functions here and
23 * #define LUA_EXTRALIBS accordingly. For example,
24 * #define LUA_EXTRALIBS {"mylib","luaopen_mylib"},
25 * Note the ending comma!
29 * The stand-alone Lua interpreter uses two prompts: PROMPT and PROMPT2.
30 * PROMPT is the primary prompt, shown when the intepreter is ready to receive
31 * a new statement. PROMPT2 is the secondary prompt, shown while a statement
32 * is being entered but is still incomplete.
36 * Error messages usually show argv[0] as a program name. In systems that do
37 * not give a valid string as argv[0], error messages show PROGNAME instead.
44 * This section implements of lua_readline and lua_saveline for lua.c using
45 * the GNU readline and history libraries. It should also work with drop-in
46 * replacements such as editline and libedit (you may have to include
47 * different headers, though).
51 #define lua_readline myreadline
52 #define lua_saveline mysaveline
55 #include <readline/readline.h>
56 #include <readline/history.h>
58 static int myreadline (lua_State
*L
, const char *prompt
) {
59 char *s
=readline(prompt
);
64 lua_pushliteral(L
,"\n");
71 static void mysaveline (lua_State
*L
, const char *s
) {
73 for (p
=s
; isspace(*p
); p
++)
80 lua_pushlstring(L
,s
,n
);