lua/lua.c

70 lines
1.4 KiB
C
Raw Normal View History

1993-07-28 06:18:00 -07:00
/*
** lua.c
** Linguagem para Usuarios de Aplicacao
*/
char *rcs_lua="$Id: lua.c,v 1.12 1996/07/05 20:55:43 roberto Exp roberto $";
1993-12-17 10:41:19 -08:00
1993-07-28 06:18:00 -07:00
#include <stdio.h>
1995-02-07 08:04:15 -08:00
#include <string.h>
1993-07-28 06:18:00 -07:00
#include "lua.h"
#include "lualib.h"
#ifdef _POSIX_SOURCE
#include <unistd.h>
1996-05-03 13:10:59 -07:00
#else
#define isatty(x) (x==0) /* assume stdin is a tty */
#endif
1993-07-28 06:18:00 -07:00
static void manual_input (void)
{
1996-04-23 05:43:07 -07:00
if (isatty(0))
{
char buffer[250];
1996-03-12 07:56:03 -08:00
while (fgets(buffer, sizeof(buffer), stdin) != 0)
lua_dostring(buffer);
}
else
lua_dofile(NULL); /* executes stdin as a file */
}
1994-11-28 09:12:49 -08:00
int main (int argc, char *argv[])
1993-07-28 06:18:00 -07:00
{
int i;
int result = 0;
iolib_open ();
strlib_open ();
mathlib_open ();
if (argc < 2)
manual_input();
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;
1993-07-28 06:18:00 -07:00
}