diff options
| -rw-r--r-- | lua.c | 41 |
1 files changed, 9 insertions, 32 deletions
| @@ -1,54 +1,31 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** lua.c | 2 | ** lua.c |
| 3 | ** Linguagem para Usuarios de Aplicacao | 3 | ** Linguagem para Usuarios de Aplicacao |
| 4 | ** TeCGraf - PUC-Rio | ||
| 5 | ** 28 Apr 93 | ||
| 6 | */ | 4 | */ |
| 7 | 5 | ||
| 6 | char *rcs_lua="$Id: $"; | ||
| 7 | |||
| 8 | #include <stdio.h> | 8 | #include <stdio.h> |
| 9 | 9 | ||
| 10 | #include "lua.h" | 10 | #include "lua.h" |
| 11 | #include "lualib.h" | 11 | #include "lualib.h" |
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | void test (void) | ||
| 15 | { | ||
| 16 | lua_pushobject(lua_getparam(1)); | ||
| 17 | lua_call ("c", 1); | ||
| 18 | } | ||
| 19 | |||
| 20 | |||
| 21 | static void callfunc (void) | ||
| 22 | { | ||
| 23 | lua_Object obj = lua_getparam (1); | ||
| 24 | if (lua_isstring(obj)) lua_call(lua_getstring(obj),0); | ||
| 25 | } | ||
| 26 | |||
| 27 | static void execstr (void) | ||
| 28 | { | ||
| 29 | lua_Object obj = lua_getparam (1); | ||
| 30 | if (lua_isstring(obj)) lua_dostring(lua_getstring(obj)); | ||
| 31 | } | ||
| 32 | |||
| 33 | void main (int argc, char *argv[]) | 14 | void main (int argc, char *argv[]) |
| 34 | { | 15 | { |
| 35 | int i; | 16 | int i; |
| 36 | if (argc < 2) | ||
| 37 | { | ||
| 38 | puts ("usage: lua filename [functionnames]"); | ||
| 39 | return; | ||
| 40 | } | ||
| 41 | lua_register ("callfunc", callfunc); | ||
| 42 | lua_register ("execstr", execstr); | ||
| 43 | lua_register ("test", test); | ||
| 44 | iolib_open (); | 17 | iolib_open (); |
| 45 | strlib_open (); | 18 | strlib_open (); |
| 46 | mathlib_open (); | 19 | mathlib_open (); |
| 47 | lua_dofile (argv[1]); | 20 | if (argc < 2) |
| 48 | for (i=2; i<argc; i++) | ||
| 49 | { | 21 | { |
| 50 | lua_call (argv[i],0); | 22 | char buffer[250]; |
| 23 | while (gets(buffer) != 0) | ||
| 24 | lua_dostring(buffer); | ||
| 51 | } | 25 | } |
| 26 | else | ||
| 27 | for (i=1; i<argc; i++) | ||
| 28 | lua_dofile (argv[i]); | ||
| 52 | } | 29 | } |
| 53 | 30 | ||
| 54 | 31 | ||
