diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-10-06 12:51:32 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-10-06 12:51:32 -0200 |
| commit | a3235ad2702628dc3c1e4a6a90f69608cefc12e9 (patch) | |
| tree | a0ae96601a4ae0a7dafc2523bf70ccedee42649a /lua.c | |
| parent | f6a9cc9a673298dc7ee7a416fec08848e464b227 (diff) | |
| download | lua-a3235ad2702628dc3c1e4a6a90f69608cefc12e9.tar.gz lua-a3235ad2702628dc3c1e4a6a90f69608cefc12e9.tar.bz2 lua-a3235ad2702628dc3c1e4a6a90f69608cefc12e9.zip | |
prompt for interactive mode
Diffstat (limited to 'lua.c')
| -rw-r--r-- | lua.c | 19 |
1 files changed, 13 insertions, 6 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: $ | 2 | ** $Id: lua.c,v 1.1 1997/09/16 19:25:59 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 | */ |
| @@ -30,11 +30,15 @@ static void manual_input (void) | |||
| 30 | { | 30 | { |
| 31 | if (isatty(0)) { | 31 | if (isatty(0)) { |
| 32 | char buffer[250]; | 32 | char buffer[250]; |
| 33 | while (fgets(buffer, sizeof(buffer), stdin) != 0) { | 33 | while (1) { |
| 34 | lua_beginblock(); | 34 | lua_beginblock(); |
| 35 | printf("%s", lua_getstring(lua_getglobal("_PROMPT"))); | ||
| 36 | if (fgets(buffer, sizeof(buffer), stdin) == 0) | ||
| 37 | break; | ||
| 35 | lua_dostring(buffer); | 38 | lua_dostring(buffer); |
| 36 | lua_endblock(); | 39 | lua_endblock(); |
| 37 | } | 40 | } |
| 41 | printf("\n"); | ||
| 38 | } | 42 | } |
| 39 | else | 43 | else |
| 40 | lua_dofile(NULL); /* executes stdin as a file */ | 44 | lua_dofile(NULL); /* executes stdin as a file */ |
| @@ -45,11 +49,14 @@ int main (int argc, char *argv[]) | |||
| 45 | { | 49 | { |
| 46 | int i; | 50 | int i; |
| 47 | setlocale(LC_ALL, ""); | 51 | setlocale(LC_ALL, ""); |
| 48 | lua_iolibopen (); | 52 | lua_iolibopen(); |
| 49 | lua_strlibopen (); | 53 | lua_strlibopen(); |
| 50 | lua_mathlibopen (); | 54 | lua_mathlibopen(); |
| 51 | if (argc < 2) | 55 | lua_pushstring("Lua> "); lua_setglobal("_PROMPT"); |
| 56 | if (argc < 2) { | ||
| 57 | printf("%s %s\n", LUA_VERSION, LUA_COPYRIGHT); | ||
| 52 | manual_input(); | 58 | manual_input(); |
| 59 | } | ||
| 53 | else for (i=1; i<argc; i++) { | 60 | else for (i=1; i<argc; i++) { |
| 54 | if (strcmp(argv[i], "-") == 0) | 61 | if (strcmp(argv[i], "-") == 0) |
| 55 | manual_input(); | 62 | manual_input(); |
