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-github-11a70220670f25a9929439f0b27331f09f05235c.tar.gz |
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 @@ /* -** $Id: ltable.c,v 1.39 2000/03/31 16:28:45 roberto Exp roberto $ +** $Id: ltable.c,v 1.40 2000/04/25 16:55:09 roberto Exp roberto $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ @@ -24,6 +24,7 @@ #include "lmem.h" #include "lobject.h" #include "lstate.h" +#include "lstring.h" #include "ltable.h" #include "lua.h" @@ -46,14 +47,17 @@ Node *luaH_mainposition (const Hash *t, const TObject *key) { case TAG_NUMBER: h = (unsigned long)(long)nvalue(key); break; - case TAG_STRING: case TAG_USERDATA: - h = tsvalue(key)->hash; + case TAG_STRING: + h = tsvalue(key)->u.s.hash; + break; + case TAG_USERDATA: + h = IntPoint(tsvalue(key)); break; case TAG_TABLE: - h = IntPoint(L, avalue(key)); + h = IntPoint(avalue(key)); break; case TAG_LCLOSURE: case TAG_CCLOSURE: - h = IntPoint(L, clvalue(key)); + h = IntPoint(clvalue(key)); break; default: return NULL; /* invalid key */ @@ -91,8 +95,8 @@ const TObject *luaH_getnum (const Hash *t, Number key) { /* specialized version for strings */ -static const TObject *luaH_getstr (const Hash *t, TString *key) { - Node *n = &t->node[key->hash&(t->size-1)]; +const TObject *luaH_getstr (const Hash *t, TString *key) { + Node *n = &t->node[key->u.s.hash&(t->size-1)]; do { if (ttype(&n->key) == TAG_STRING && tsvalue(&n->key) == key) return &n->val; @@ -248,3 +252,7 @@ void luaH_setint (lua_State *L, Hash *t, int key, const TObject *val) { luaH_set(L, t, &index, val); } + +const TObject *luaH_getglobal (lua_State *L, const char *name) { + return luaH_getstr(L->gt, luaS_new(L, name)); +} |