3 ** Linguagem para Usuarios de Aplicacao
6 char *rcs_lua
="$Id: lua.c,v 1.7 1995/10/31 17:05:35 roberto Exp $";
15 static char **lua_argv
;
18 ** although this function is POSIX, there is no standard header file that
24 %F Allow Lua code to access argv strings.
25 %i Receive from Lua the argument number (starting with 1).
26 %o Return to Lua the argument, or nil if it does not exist.
28 static void lua_getargv (void)
30 lua_Object lo
= lua_getparam(1);
31 if (!lua_isnumber(lo
))
35 int n
= (int)lua_getnumber(lo
);
36 if (n
< 1 || n
> lua_argc
) lua_pushnil();
37 else lua_pushstring(lua_argv
[n
]);
42 static void manual_input (void)
44 if (isatty(fileno(stdin
)))
47 while (gets(buffer
) != 0)
51 lua_dofile(NULL
); /* executes stdin as a file */
55 int main (int argc
, char *argv
[])
63 lua_register("argv", lua_getargv
);
69 for (i
=1; i
<argc
; i
++)
70 if (strcmp(argv
[i
], "--") == 0)
76 for (i
=1; i
<argc
; i
++)
78 if (strcmp(argv
[i
], "--") == 0)
80 else if (strcmp(argv
[i
], "-") == 0)
82 else if (strcmp(argv
[i
], "-v") == 0)
83 printf("%s %s\n(written by %s)\n\n",
84 LUA_VERSION
, LUA_COPYRIGHT
, LUA_AUTHORS
);
86 result
= lua_dofile (argv
[i
]);