3 ** Linguagem para Usuarios de Aplicacao
6 char *rcs_lua
="$Id: lua.c,v 1.10 1996/05/03 19:20:17 roberto Exp $";
15 static char **lua_argv
;
19 ** although this function is POSIX, there is no standard header file that
24 #define isatty(x) (x==0) /* assume stdin is a tty */
28 %F Allow Lua code to access argv strings.
29 %i Receive from Lua the argument number (starting with 1).
30 %o Return to Lua the argument, or nil if it does not exist.
32 static void lua_getargv (void)
34 lua_Object lo
= lua_getparam(1);
35 if (!lua_isnumber(lo
))
39 int n
= (int)lua_getnumber(lo
);
40 if (n
< 1 || n
> lua_argc
) lua_pushnil();
41 else lua_pushstring(lua_argv
[n
]);
46 static void manual_input (void)
51 while (fgets(buffer
, sizeof(buffer
), stdin
) != 0)
55 lua_dofile(NULL
); /* executes stdin as a file */
59 int main (int argc
, char *argv
[])
67 lua_register("argv", lua_getargv
);
73 for (i
=1; i
<argc
; i
++)
74 if (strcmp(argv
[i
], "--") == 0)
80 for (i
=1; i
<argc
; i
++)
82 if (strcmp(argv
[i
], "--") == 0)
84 else if (strcmp(argv
[i
], "-") == 0)
86 else if (strcmp(argv
[i
], "-v") == 0)
87 printf("%s %s\n(written by %s)\n\n",
88 LUA_VERSION
, LUA_COPYRIGHT
, LUA_AUTHORS
);
91 result
= lua_dofile (argv
[i
]);
93 fprintf(stderr
, "lua: error trying to run file %s\n", argv
[i
]);