summaryrefslogtreecommitdiff
path: root/clients/lua
diff options
context:
space:
mode:
authorLua Team <team@lua.org>1996-11-19 12:00:00 +0000
committerrepogen <>1996-11-19 12:00:00 +0000
commit47a298a24ad3a8202440051de5938618502302a0 (patch)
tree9be43568f1e90c9219d5e3860b58c8ac1db5f062 /clients/lua
parent721542976ebc89f2f8d17d19be7e4426570b69be (diff)
downloadlua-github-2.5.tar.gz
Lua 2.52.5
Diffstat (limited to 'clients/lua')
-rw-r--r--clients/lua/Makefile2
-rw-r--r--clients/lua/lua.c107
2 files changed, 40 insertions, 69 deletions
diff --git a/clients/lua/Makefile b/clients/lua/Makefile
index 7bfde7fe..7ce90fa6 100644
--- a/clients/lua/Makefile
+++ b/clients/lua/Makefile
@@ -13,7 +13,7 @@ T=$(BIN)/lua
all: $T
-$T: $(OBJS)
+$T: $(OBJS) $(LIB)/liblua.a $(LIB)/liblualib.a
$(CC) -o $@ $(OBJS) -L$(LIB) -llua -llualib -lm
dynamic:
diff --git a/clients/lua/lua.c b/clients/lua/lua.c
index bae09e25..a6d558a2 100644
--- a/clients/lua/lua.c
+++ b/clients/lua/lua.c
@@ -3,7 +3,7 @@
** Linguagem para Usuarios de Aplicacao
*/
-char *rcs_lua="$Id: lua.c,v 1.10 1996/05/03 19:20:17 roberto Exp $";
+char *rcs_lua="$Id: lua.c,v 1.14 1996/09/24 17:30:28 roberto Exp $";
#include <stdio.h>
#include <string.h>
@@ -11,45 +11,23 @@ char *rcs_lua="$Id: lua.c,v 1.10 1996/05/03 19:20:17 roberto Exp $";
#include "lua.h"
#include "lualib.h"
-static int lua_argc;
-static char **lua_argv;
-#ifdef POSIX
-/*
-** although this function is POSIX, there is no standard header file that
-** defines it
-*/
-int isatty (int fd);
+#ifdef _POSIX_SOURCE
+#include <unistd.h>
#else
#define isatty(x) (x==0) /* assume stdin is a tty */
#endif
-/*
-%F Allow Lua code to access argv strings.
-%i Receive from Lua the argument number (starting with 1).
-%o Return to Lua the argument, or nil if it does not exist.
-*/
-static void lua_getargv (void)
-{
- lua_Object lo = lua_getparam(1);
- if (!lua_isnumber(lo))
- lua_pushnil();
- else
- {
- int n = (int)lua_getnumber(lo);
- if (n < 1 || n > lua_argc) lua_pushnil();
- else lua_pushstring(lua_argv[n]);
- }
-}
-
static void manual_input (void)
{
- if (isatty(0))
- {
- char buffer[250];
- while (fgets(buffer, sizeof(buffer), stdin) != 0)
- lua_dostring(buffer);
+ if (isatty(0)) {
+ char buffer[250];
+ while (fgets(buffer, sizeof(buffer), stdin) != 0) {
+ lua_beginblock();
+ lua_dostring(buffer);
+ lua_endblock();
+ }
}
else
lua_dofile(NULL); /* executes stdin as a file */
@@ -58,43 +36,36 @@ static void manual_input (void)
int main (int argc, char *argv[])
{
- int i;
- int result = 0;
- iolib_open ();
- strlib_open ();
- mathlib_open ();
-
- lua_register("argv", lua_getargv);
-
- if (argc < 2)
- manual_input();
- else
- {
- for (i=1; i<argc; i++)
- if (strcmp(argv[i], "--") == 0)
- {
- lua_argc = argc-i-1;
- lua_argv = argv+i;
- break;
- }
- for (i=1; i<argc; i++)
- {
- if (strcmp(argv[i], "--") == 0)
- break;
- else if (strcmp(argv[i], "-") == 0)
+ int i;
+ int result = 0;
+ iolib_open ();
+ strlib_open ();
+ mathlib_open ();
+ if (argc < 2)
manual_input();
- else if (strcmp(argv[i], "-v") == 0)
- printf("%s %s\n(written by %s)\n\n",
- LUA_VERSION, LUA_COPYRIGHT, LUA_AUTHORS);
- else
- {
- result = lua_dofile (argv[i]);
- if (result)
- fprintf(stderr, "lua: error trying to run file %s\n", argv[i]);
- }
+ else for (i=1; i<argc; i++) {
+ if (strcmp(argv[i], "-") == 0)
+ manual_input();
+ else if (strcmp(argv[i], "-v") == 0)
+ printf("%s %s\n(written by %s)\n\n",
+ LUA_VERSION, LUA_COPYRIGHT, LUA_AUTHORS);
+ else if ((strcmp(argv[i], "-e") == 0 && i++) || strchr(argv[i], '=')) {
+ if (lua_dostring(argv[i]) != 0) {
+ fprintf(stderr, "lua: error running argument `%s'\n", argv[i]);
+ return 1;
+ }
+ }
+ else {
+ result = lua_dofile (argv[i]);
+ if (result) {
+ if (result == 2) {
+ fprintf(stderr, "lua: cannot execute file `%s' - ", argv[i]);
+ perror(NULL);
+ }
+ return 1;
+ }
+ }
}
- }
- return result;
+ return result;
}
-