diff options
Diffstat (limited to 'table.c')
| -rw-r--r-- | table.c | 48 |
1 files changed, 25 insertions, 23 deletions
| @@ -3,7 +3,7 @@ | |||
| 3 | ** Module to control static tables | 3 | ** Module to control static tables |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_table="$Id: table.c,v 2.15 1994/11/10 20:41:37 roberto Exp roberto $"; | 6 | char *rcs_table="$Id: table.c,v 2.16 1994/11/11 14:00:08 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
| 9 | #include <string.h> | 9 | #include <string.h> |
| @@ -51,23 +51,23 @@ static void lua_initsymbol (void) | |||
| 51 | lua_table = (Symbol *) calloc(lua_maxsymbol, sizeof(Symbol)); | 51 | lua_table = (Symbol *) calloc(lua_maxsymbol, sizeof(Symbol)); |
| 52 | if (lua_table == NULL) | 52 | if (lua_table == NULL) |
| 53 | lua_error ("symbol table: not enough memory"); | 53 | lua_error ("symbol table: not enough memory"); |
| 54 | n = lua_findsymbol("next"); | 54 | n = luaI_findsymbolbyname("next"); |
| 55 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_next; | 55 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_next; |
| 56 | n = lua_findsymbol("nextvar"); | 56 | n = luaI_findsymbolbyname("nextvar"); |
| 57 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_nextvar; | 57 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_nextvar; |
| 58 | n = lua_findsymbol("type"); | 58 | n = luaI_findsymbolbyname("type"); |
| 59 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_type; | 59 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_type; |
| 60 | n = lua_findsymbol("tonumber"); | 60 | n = luaI_findsymbolbyname("tonumber"); |
| 61 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_obj2number; | 61 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_obj2number; |
| 62 | n = lua_findsymbol("print"); | 62 | n = luaI_findsymbolbyname("print"); |
| 63 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_print; | 63 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_print; |
| 64 | n = lua_findsymbol("dofile"); | 64 | n = luaI_findsymbolbyname("dofile"); |
| 65 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_internaldofile; | 65 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_internaldofile; |
| 66 | n = lua_findsymbol("dostring"); | 66 | n = luaI_findsymbolbyname("dostring"); |
| 67 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_internaldostring; | 67 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_internaldostring; |
| 68 | n = lua_findsymbol("setfallback"); | 68 | n = luaI_findsymbolbyname("setfallback"); |
| 69 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_setfallback; | 69 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_setfallback; |
| 70 | n = lua_findsymbol("error"); | 70 | n = luaI_findsymbolbyname("error"); |
| 71 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_error; | 71 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_error; |
| 72 | } | 72 | } |
| 73 | 73 | ||
| @@ -89,13 +89,11 @@ void lua_initconstant (void) | |||
| 89 | ** found, allocate it. | 89 | ** found, allocate it. |
| 90 | ** On error, return -1. | 90 | ** On error, return -1. |
| 91 | */ | 91 | */ |
| 92 | int lua_findsymbol (char *s) | 92 | int luaI_findsymbol (TreeNode *t) |
| 93 | { | 93 | { |
| 94 | char *n; | ||
| 95 | if (lua_table == NULL) | 94 | if (lua_table == NULL) |
| 96 | lua_initsymbol(); | 95 | lua_initsymbol(); |
| 97 | n = lua_varcreate(s); | 96 | if (t->varindex == UNMARKED_STRING) |
| 98 | if (indexstring(n) == UNMARKED_STRING) | ||
| 99 | { | 97 | { |
| 100 | if (lua_ntable == lua_maxsymbol) | 98 | if (lua_ntable == lua_maxsymbol) |
| 101 | { | 99 | { |
| @@ -106,11 +104,17 @@ int lua_findsymbol (char *s) | |||
| 106 | if (lua_table == NULL) | 104 | if (lua_table == NULL) |
| 107 | lua_error ("symbol table: not enough memory"); | 105 | lua_error ("symbol table: not enough memory"); |
| 108 | } | 106 | } |
| 109 | indexstring(n) = lua_ntable; | 107 | t->varindex = lua_ntable; |
| 110 | s_tag(lua_ntable) = LUA_T_NIL; | 108 | s_tag(lua_ntable) = LUA_T_NIL; |
| 111 | lua_ntable++; | 109 | lua_ntable++; |
| 112 | } | 110 | } |
| 113 | return indexstring(n); | 111 | return t->varindex; |
| 112 | } | ||
| 113 | |||
| 114 | |||
| 115 | int luaI_findsymbolbyname (char *name) | ||
| 116 | { | ||
| 117 | return luaI_findsymbol(lua_constcreate(name)); | ||
| 114 | } | 118 | } |
| 115 | 119 | ||
| 116 | 120 | ||
| @@ -119,13 +123,11 @@ int lua_findsymbol (char *s) | |||
| 119 | ** found, allocate it. | 123 | ** found, allocate it. |
| 120 | ** On error, return -1. | 124 | ** On error, return -1. |
| 121 | */ | 125 | */ |
| 122 | int lua_findconstant (char *s) | 126 | int luaI_findconstant (TreeNode *t) |
| 123 | { | 127 | { |
| 124 | char *n; | ||
| 125 | if (lua_constant == NULL) | 128 | if (lua_constant == NULL) |
| 126 | lua_initconstant(); | 129 | lua_initconstant(); |
| 127 | n = lua_constcreate(s); | 130 | if (t->constindex == UNMARKED_STRING) |
| 128 | if (indexstring(n) == UNMARKED_STRING) | ||
| 129 | { | 131 | { |
| 130 | if (lua_nconstant == lua_maxconstant) | 132 | if (lua_nconstant == lua_maxconstant) |
| 131 | { | 133 | { |
| @@ -136,11 +138,11 @@ int lua_findconstant (char *s) | |||
| 136 | if (lua_constant == NULL) | 138 | if (lua_constant == NULL) |
| 137 | lua_error ("constant table: not enough memory"); | 139 | lua_error ("constant table: not enough memory"); |
| 138 | } | 140 | } |
| 139 | indexstring(n) = lua_nconstant; | 141 | t->constindex = lua_nconstant; |
| 140 | lua_constant[lua_nconstant] = n; | 142 | lua_constant[lua_nconstant] = t->str; |
| 141 | lua_nconstant++; | 143 | lua_nconstant++; |
| 142 | } | 144 | } |
| 143 | return indexstring(n); | 145 | return t->constindex; |
| 144 | } | 146 | } |
| 145 | 147 | ||
| 146 | 148 | ||
