1993-07-28 06:18:00 -07:00
|
|
|
/*
|
|
|
|
** lua.c
|
|
|
|
** Linguagem para Usuarios de Aplicacao
|
|
|
|
*/
|
|
|
|
|
1995-02-07 08:04:15 -08:00
|
|
|
char *rcs_lua="$Id: lua.c,v 1.3 1994/12/14 19:58:20 celes Exp $";
|
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
|
|
|
static int lua_argc;
|
|
|
|
static char **lua_argv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
%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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1993-07-28 06:18:00 -07:00
|
|
|
|
1994-11-28 09:12:49 -08:00
|
|
|
int main (int argc, char *argv[])
|
1993-07-28 06:18:00 -07:00
|
|
|
{
|
|
|
|
int i;
|
1994-11-28 09:12:49 -08:00
|
|
|
int result = 0;
|
1993-07-28 06:18:00 -07:00
|
|
|
iolib_open ();
|
|
|
|
strlib_open ();
|
|
|
|
mathlib_open ();
|
1994-12-14 11:58:20 -08:00
|
|
|
|
|
|
|
lua_register("argv", lua_getargv);
|
|
|
|
|
1993-12-17 10:41:19 -08:00
|
|
|
if (argc < 2)
|
1993-07-28 06:18:00 -07:00
|
|
|
{
|
1993-12-17 10:41:19 -08:00
|
|
|
char buffer[250];
|
|
|
|
while (gets(buffer) != 0)
|
1994-11-28 09:12:49 -08:00
|
|
|
result = lua_dostring(buffer);
|
1993-07-28 06:18:00 -07:00
|
|
|
}
|
1993-12-17 10:41:19 -08:00
|
|
|
else
|
1994-12-14 11:58:20 -08:00
|
|
|
{
|
|
|
|
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
|
1994-11-28 09:12:49 -08:00
|
|
|
result = lua_dofile (argv[i]);
|
1994-12-14 11:58:20 -08:00
|
|
|
}
|
|
|
|
}
|
1994-11-28 09:12:49 -08:00
|
|
|
return result;
|
1993-07-28 06:18:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|