diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-05-08 16:32:53 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-05-08 16:32:53 -0300 |
commit | 11a70220670f25a9929439f0b27331f09f05235c (patch) | |
tree | c4a962b5a3e53ac6df8894fb3ad2248c4a1256cb /ltable.c | |
parent | 35a6ed283881f313152457f24cc6c677122d5058 (diff) | |
download | lua-11a70220670f25a9929439f0b27331f09f05235c.tar.gz lua-11a70220670f25a9929439f0b27331f09f05235c.tar.bz2 lua-11a70220670f25a9929439f0b27331f09f05235c.zip |
global variables are stored in a Lua table
Diffstat (limited to 'ltable.c')
-rw-r--r-- | ltable.c | 22 |
1 files changed, 15 insertions, 7 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltable.c,v 1.39 2000/03/31 16:28:45 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 1.40 2000/04/25 16:55:09 roberto Exp roberto $ |
3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -24,6 +24,7 @@ | |||
24 | #include "lmem.h" | 24 | #include "lmem.h" |
25 | #include "lobject.h" | 25 | #include "lobject.h" |
26 | #include "lstate.h" | 26 | #include "lstate.h" |
27 | #include "lstring.h" | ||
27 | #include "ltable.h" | 28 | #include "ltable.h" |
28 | #include "lua.h" | 29 | #include "lua.h" |
29 | 30 | ||
@@ -46,14 +47,17 @@ Node *luaH_mainposition (const Hash *t, const TObject *key) { | |||
46 | case TAG_NUMBER: | 47 | case TAG_NUMBER: |
47 | h = (unsigned long)(long)nvalue(key); | 48 | h = (unsigned long)(long)nvalue(key); |
48 | break; | 49 | break; |
49 | case TAG_STRING: case TAG_USERDATA: | 50 | case TAG_STRING: |
50 | h = tsvalue(key)->hash; | 51 | h = tsvalue(key)->u.s.hash; |
52 | break; | ||
53 | case TAG_USERDATA: | ||
54 | h = IntPoint(tsvalue(key)); | ||
51 | break; | 55 | break; |
52 | case TAG_TABLE: | 56 | case TAG_TABLE: |
53 | h = IntPoint(L, avalue(key)); | 57 | h = IntPoint(avalue(key)); |
54 | break; | 58 | break; |
55 | case TAG_LCLOSURE: case TAG_CCLOSURE: | 59 | case TAG_LCLOSURE: case TAG_CCLOSURE: |
56 | h = IntPoint(L, clvalue(key)); | 60 | h = IntPoint(clvalue(key)); |
57 | break; | 61 | break; |
58 | default: | 62 | default: |
59 | return NULL; /* invalid key */ | 63 | return NULL; /* invalid key */ |
@@ -91,8 +95,8 @@ const TObject *luaH_getnum (const Hash *t, Number key) { | |||
91 | 95 | ||
92 | 96 | ||
93 | /* specialized version for strings */ | 97 | /* specialized version for strings */ |
94 | static const TObject *luaH_getstr (const Hash *t, TString *key) { | 98 | const TObject *luaH_getstr (const Hash *t, TString *key) { |
95 | Node *n = &t->node[key->hash&(t->size-1)]; | 99 | Node *n = &t->node[key->u.s.hash&(t->size-1)]; |
96 | do { | 100 | do { |
97 | if (ttype(&n->key) == TAG_STRING && tsvalue(&n->key) == key) | 101 | if (ttype(&n->key) == TAG_STRING && tsvalue(&n->key) == key) |
98 | return &n->val; | 102 | return &n->val; |
@@ -248,3 +252,7 @@ void luaH_setint (lua_State *L, Hash *t, int key, const TObject *val) { | |||
248 | luaH_set(L, t, &index, val); | 252 | luaH_set(L, t, &index, val); |
249 | } | 253 | } |
250 | 254 | ||
255 | |||
256 | const TObject *luaH_getglobal (lua_State *L, const char *name) { | ||
257 | return luaH_getstr(L->gt, luaS_new(L, name)); | ||
258 | } | ||