diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-12-17 10:26:09 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-12-17 10:26:09 -0200 |
commit | de6fc75d630b393d8b577ba03353abe527523d0f (patch) | |
tree | 385cb83b63b2ec409cde308c776e7c4c2073ff84 /lua.c | |
parent | 2af0d3b4598060b1086884cfb879d39fa4e0c89a (diff) | |
download | lua-de6fc75d630b393d8b577ba03353abe527523d0f.tar.gz lua-de6fc75d630b393d8b577ba03353abe527523d0f.tar.bz2 lua-de6fc75d630b393d8b577ba03353abe527523d0f.zip |
several configuration options that do not change often moved out of
luaconf.h and into more internal files
Diffstat (limited to 'lua.c')
-rw-r--r-- | lua.c | 65 |
1 files changed, 64 insertions, 1 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.c,v 1.176 2009/11/24 18:05:12 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.177 2009/12/11 13:40:44 roberto Exp roberto $ |
3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -18,6 +18,69 @@ | |||
18 | #include "lualib.h" | 18 | #include "lualib.h" |
19 | 19 | ||
20 | 20 | ||
21 | #if !defined(LUA_PROMPT) | ||
22 | #define LUA_PROMPT "> " | ||
23 | #define LUA_PROMPT2 ">> " | ||
24 | #endif | ||
25 | |||
26 | #if !defined(LUA_PROGNAME) | ||
27 | #define LUA_PROGNAME "lua" | ||
28 | #endif | ||
29 | |||
30 | #if !defined(LUA_MAXINPUT) | ||
31 | #define LUA_MAXINPUT 512 | ||
32 | #endif | ||
33 | |||
34 | #if !defined(LUA_INIT) | ||
35 | #define LUA_INIT "LUA_INIT" | ||
36 | #endif | ||
37 | |||
38 | |||
39 | /* | ||
40 | ** lua_stdin_is_tty detects whether the standard input is a 'tty' (that | ||
41 | ** is, whether we're running lua interactively). | ||
42 | */ | ||
43 | #if defined(LUA_USE_ISATTY) | ||
44 | #include <unistd.h> | ||
45 | #define lua_stdin_is_tty() isatty(0) | ||
46 | #elif defined(LUA_WIN) | ||
47 | #include <io.h> | ||
48 | #include <stdio.h> | ||
49 | #define lua_stdin_is_tty() _isatty(_fileno(stdin)) | ||
50 | #else | ||
51 | #define lua_stdin_is_tty() 1 /* assume stdin is a tty */ | ||
52 | #endif | ||
53 | |||
54 | |||
55 | /* | ||
56 | ** lua_readline defines how to show a prompt and then read a line from | ||
57 | ** the standard input. | ||
58 | ** lua_saveline defines how to "save" a read line in a "history". | ||
59 | ** lua_freeline defines how to free a line read by lua_readline. | ||
60 | */ | ||
61 | #if defined(LUA_USE_READLINE) | ||
62 | |||
63 | #include <stdio.h> | ||
64 | #include <readline/readline.h> | ||
65 | #include <readline/history.h> | ||
66 | #define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL) | ||
67 | #define lua_saveline(L,idx) \ | ||
68 | if (lua_objlen(L,idx) > 0) /* non-empty line? */ \ | ||
69 | add_history(lua_tostring(L, idx)); /* add it to history */ | ||
70 | #define lua_freeline(L,b) ((void)L, free(b)) | ||
71 | |||
72 | #elif !defined(lua_readline) | ||
73 | |||
74 | #define lua_readline(L,b,p) \ | ||
75 | ((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \ | ||
76 | fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */ | ||
77 | #define lua_saveline(L,idx) { (void)L; (void)idx; } | ||
78 | #define lua_freeline(L,b) { (void)L; (void)b; } | ||
79 | |||
80 | #endif | ||
81 | |||
82 | |||
83 | |||
21 | 84 | ||
22 | static lua_State *globalL = NULL; | 85 | static lua_State *globalL = NULL; |
23 | 86 | ||