3 ** Linguagem para Usuarios de Aplicacao
6 char *rcs_lua
="$Id: lua.c,v 1.18 1997/06/19 18:55:40 roberto Exp $";
19 #define isatty(x) (x==0) /* assume stdin is a tty */
25 static void testC (void)
28 #define getnum(s) ((*s++) - '0')
29 #define getname(s) (nome[0] = *s++, nome)
34 char *s
= luaL_check_string(1);
38 case '0': case '1': case '2': case '3': case '4':
39 case '5': case '6': case '7': case '8': case '9':
40 lua_pushnumber(*(s
-1) - '0');
43 case 'c': reg
[getnum(s
)] = lua_createtable(); break;
45 case 'P': reg
[getnum(s
)] = lua_pop(); break;
47 case 'g': { int n
= getnum(s
); reg
[n
] = lua_getglobal(getname(s
)); break; }
49 case 'G': { int n
= getnum(s
);
50 reg
[n
] = lua_rawgetglobal(getname(s
));
54 case 'l': locks
[getnum(s
)] = lua_ref(1); break;
55 case 'L': locks
[getnum(s
)] = lua_ref(0); break;
57 case 'r': { int n
= getnum(s
); reg
[n
] = lua_getref(locks
[getnum(s
)]); break; }
59 case 'u': lua_unref(locks
[getnum(s
)]); break;
61 case 'p': { int n
= getnum(s
); reg
[n
] = lua_getparam(getnum(s
)); break; }
63 case '=': lua_setglobal(getname(s
)); break;
65 case 's': lua_pushstring(getname(s
)); break;
67 case 'o': lua_pushobject(reg
[getnum(s
)]); break;
69 case 'f': lua_call(getname(s
)); break;
71 case 'i': reg
[getnum(s
)] = lua_gettable(); break;
73 case 'I': reg
[getnum(s
)] = lua_rawgettable(); break;
75 case 't': lua_settable(); break;
77 case 'T': lua_rawsettable(); break;
79 default: luaL_verror("unknown command in `testC': %c", *(s
-1));
83 if (*s
++ != ' ') lua_error("missing ` ' between commands in `testC'");
86 lua_error("`testC' not active");
91 static void manual_input (void)
95 while (fgets(buffer
, sizeof(buffer
), stdin
) != 0) {
102 lua_dofile(NULL
); /* executes stdin as a file */
106 int main (int argc
, char *argv
[])
113 lua_register("testC", testC
);
116 else for (i
=1; i
<argc
; i
++) {
117 if (strcmp(argv
[i
], "-") == 0)
119 else if (strcmp(argv
[i
], "-v") == 0)
120 printf("%s %s\n(written by %s)\n\n",
121 LUA_VERSION
, LUA_COPYRIGHT
, LUA_AUTHORS
);
122 else if ((strcmp(argv
[i
], "-e") == 0 && i
++) || strchr(argv
[i
], '=')) {
123 if (lua_dostring(argv
[i
]) != 0) {
124 fprintf(stderr
, "lua: error running argument `%s'\n", argv
[i
]);
129 result
= lua_dofile (argv
[i
]);
132 fprintf(stderr
, "lua: cannot execute file ");