diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-06-09 14:29:16 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-06-09 14:29:16 -0300 |
commit | 085181a08a78244d20177a40cbe223d6ad0a2ff6 (patch) | |
tree | 0855abcba0876ca67cc10c9d87d32c63d4b4769d | |
parent | dd22ea4da550c3a158e0f11b928c349336184f85 (diff) | |
download | lua-085181a08a78244d20177a40cbe223d6ad0a2ff6.tar.gz lua-085181a08a78244d20177a40cbe223d6ad0a2ff6.tar.bz2 lua-085181a08a78244d20177a40cbe223d6ad0a2ff6.zip |
new function "testC", to help debug the API.
-rw-r--r-- | lua.c | 72 |
1 files changed, 71 insertions, 1 deletions
@@ -3,12 +3,13 @@ | |||
3 | ** Linguagem para Usuarios de Aplicacao | 3 | ** Linguagem para Usuarios de Aplicacao |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_lua="$Id: lua.c,v 1.14 1996/09/24 17:30:28 roberto Exp roberto $"; | 6 | char *rcs_lua="$Id: lua.c,v 1.15 1997/04/04 22:24:51 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <string.h> | 9 | #include <string.h> |
10 | 10 | ||
11 | #include "lua.h" | 11 | #include "lua.h" |
12 | #include "auxlib.h" | ||
12 | #include "lualib.h" | 13 | #include "lualib.h" |
13 | 14 | ||
14 | 15 | ||
@@ -19,6 +20,74 @@ char *rcs_lua="$Id: lua.c,v 1.14 1996/09/24 17:30:28 roberto Exp roberto $"; | |||
19 | #endif | 20 | #endif |
20 | 21 | ||
21 | 22 | ||
23 | #define DEBUG 1 | ||
24 | |||
25 | static void testC (void) | ||
26 | { | ||
27 | #if DEBUG | ||
28 | #define getnum(s) ((*s++) - '0') | ||
29 | #define getname(s) (nome[0] = *s++, nome) | ||
30 | |||
31 | static int locks[10]; | ||
32 | lua_Object reg[10]; | ||
33 | char nome[2]; | ||
34 | char *s = luaL_check_string(1); | ||
35 | nome[1] = 0; | ||
36 | while (1) { | ||
37 | switch (*s++) { | ||
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'); | ||
41 | break; | ||
42 | |||
43 | case 'c': reg[getnum(s)] = lua_createtable(); break; | ||
44 | |||
45 | case 'P': reg[getnum(s)] = lua_pop(); break; | ||
46 | |||
47 | case 'g': { int n = getnum(s); reg[n] = lua_getglobal(getname(s)); break; } | ||
48 | |||
49 | case 'G': { int n = getnum(s); | ||
50 | reg[n] = lua_rawgetglobal(getname(s)); | ||
51 | break; | ||
52 | } | ||
53 | |||
54 | case 'l': locks[getnum(s)] = lua_ref(1); break; | ||
55 | case 'L': locks[getnum(s)] = lua_ref(0); break; | ||
56 | |||
57 | case 'r': { int n = getnum(s); reg[n] = lua_getref(locks[getnum(s)]); break; } | ||
58 | |||
59 | case 'u': lua_unlock(locks[getnum(s)]); break; | ||
60 | |||
61 | case 'p': { int n = getnum(s); reg[n] = lua_getparam(getnum(s)); break; } | ||
62 | |||
63 | case '=': lua_setglobal(getname(s)); break; | ||
64 | |||
65 | case 's': lua_pushstring(getname(s)); break; | ||
66 | |||
67 | case 'o': lua_pushobject(reg[getnum(s)]); break; | ||
68 | |||
69 | case 'f': lua_call(getname(s)); break; | ||
70 | |||
71 | case 'i': reg[getnum(s)] = lua_gettable(); break; | ||
72 | |||
73 | case 'I': reg[getnum(s)] = lua_rawgettable(); break; | ||
74 | |||
75 | case 't': lua_settable(); break; | ||
76 | |||
77 | case 'T': lua_rawsettable(); break; | ||
78 | |||
79 | default: luaL_verror("unknown command in `testC': %c", *(s-1)); | ||
80 | |||
81 | } | ||
82 | if (*s == 0) return; | ||
83 | if (*s++ != ' ') lua_error("missing ` ' between commands in `testC'"); | ||
84 | } | ||
85 | #else | ||
86 | lua_error("`testC' not active"); | ||
87 | #endif | ||
88 | } | ||
89 | |||
90 | |||
22 | static void manual_input (void) | 91 | static void manual_input (void) |
23 | { | 92 | { |
24 | if (isatty(0)) { | 93 | if (isatty(0)) { |
@@ -41,6 +110,7 @@ int main (int argc, char *argv[]) | |||
41 | iolib_open (); | 110 | iolib_open (); |
42 | strlib_open (); | 111 | strlib_open (); |
43 | mathlib_open (); | 112 | mathlib_open (); |
113 | lua_register("testC", testC); | ||
44 | if (argc < 2) | 114 | if (argc < 2) |
45 | manual_input(); | 115 | manual_input(); |
46 | else for (i=1; i<argc; i++) { | 116 | else for (i=1; i<argc; i++) { |