1993-07-28 06:18:00 -07:00
|
|
|
/*
|
|
|
|
** lua.c
|
|
|
|
** Linguagem para Usuarios de Aplicacao
|
|
|
|
*/
|
|
|
|
|
1996-07-06 13:20:35 -07:00
|
|
|
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"
|
|
|
|
|
1994-12-14 11:58:20 -08:00
|
|
|
|
1996-07-06 13:20:35 -07:00
|
|
|
#ifdef _POSIX_SOURCE
|
1996-06-10 12:35:46 -07:00
|
|
|
#include <unistd.h>
|
1996-05-03 13:10:59 -07:00
|
|
|
#else
|
|
|
|
#define isatty(x) (x==0) /* assume stdin is a tty */
|
|
|
|
#endif
|
1995-10-23 06:54:11 -07:00
|
|
|
|
1993-07-28 06:18:00 -07:00
|
|
|
|
1995-10-06 07:11:40 -07:00
|
|
|
static void manual_input (void)
|
|
|
|
{
|
1996-04-23 05:43:07 -07:00
|
|
|
if (isatty(0))
|
1995-10-23 06:54:11 -07:00
|
|
|
{
|
1995-10-06 07:11:40 -07:00
|
|
|
char buffer[250];
|
1996-03-12 07:56:03 -08:00
|
|
|
while (fgets(buffer, sizeof(buffer), stdin) != 0)
|
1995-10-06 07:11:40 -07:00
|
|
|
lua_dostring(buffer);
|
1995-10-23 06:54:11 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
lua_dofile(NULL); /* executes stdin as a file */
|
1995-10-06 07:11:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-11-28 09:12:49 -08:00
|
|
|
int main (int argc, char *argv[])
|
1993-07-28 06:18:00 -07:00
|
|
|
{
|
1996-06-10 12:35:46 -07:00
|
|
|
int i;
|
|
|
|
int result = 0;
|
|
|
|
iolib_open ();
|
|
|
|
strlib_open ();
|
|
|
|
mathlib_open ();
|
|
|
|
if (argc < 2)
|
1995-10-06 07:11:40 -07:00
|
|
|
manual_input();
|
1996-06-10 12:35:46 -07:00
|
|
|
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);
|
1996-07-05 13:55:43 -07:00
|
|
|
else if ((strcmp(argv[i], "-e") == 0 && i++) || strchr(argv[i], '=')) {
|
|
|
|
if (lua_dostring(argv[i]) != 0) {
|
1996-06-10 12:35:46 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
1994-12-14 11:58:20 -08:00
|
|
|
}
|
1996-06-10 12:35:46 -07:00
|
|
|
return result;
|
1993-07-28 06:18:00 -07:00
|
|
|
}
|
|
|
|
|