aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-09-26 12:02:26 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-09-26 12:02:26 -0300
commita580480b07cdf7201306b246deeb2fe84f2c25a9 (patch)
tree30e9d4798228156eea5be2589834f1ff2db4355e /lapi.c
parent0dd6d1080e7f58eb17cb8a2ad3fc5801ed7c0532 (diff)
downloadlua-a580480b07cdf7201306b246deeb2fe84f2c25a9.tar.gz
lua-a580480b07cdf7201306b246deeb2fe84f2c25a9.tar.bz2
lua-a580480b07cdf7201306b246deeb2fe84f2c25a9.zip
new implementation for globals: Global value is stored in TaggedString
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/lapi.c b/lapi.c
index 7a7e13e7..d67ecd45 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.1 1997/08/14 13:40:46 roberto Exp roberto $ 2** $Id: lapi.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -13,7 +13,6 @@
13#include "ldo.h" 13#include "ldo.h"
14#include "lfunc.h" 14#include "lfunc.h"
15#include "lgc.h" 15#include "lgc.h"
16#include "lglobal.h"
17#include "lmem.h" 16#include "lmem.h"
18#include "lobject.h" 17#include "lobject.h"
19#include "lstring.h" 18#include "lstring.h"
@@ -182,14 +181,15 @@ lua_Object lua_createtable (void)
182lua_Object lua_getglobal (char *name) 181lua_Object lua_getglobal (char *name)
183{ 182{
184 luaD_checkstack(2); /* may need that to call T.M. */ 183 luaD_checkstack(2); /* may need that to call T.M. */
185 luaV_getglobal(luaG_findsymbolbyname(name)); 184 luaV_getglobal(luaS_new(name));
186 return put_luaObjectonTop(); 185 return put_luaObjectonTop();
187} 186}
188 187
189 188
190lua_Object lua_rawgetglobal (char *name) 189lua_Object lua_rawgetglobal (char *name)
191{ 190{
192 return put_luaObject(&luaG_global[luaG_findsymbolbyname(name)].object); 191 TaggedString *ts = luaS_new(name);
192 return put_luaObject(&ts->u.globalval);
193} 193}
194 194
195 195
@@ -197,15 +197,15 @@ void lua_setglobal (char *name)
197{ 197{
198 checkCparams(1); 198 checkCparams(1);
199 luaD_checkstack(2); /* may need that to call T.M. */ 199 luaD_checkstack(2); /* may need that to call T.M. */
200 luaV_setglobal(luaG_findsymbolbyname(name)); 200 luaV_setglobal(luaS_new(name));
201} 201}
202 202
203 203
204void lua_rawsetglobal (char *name) 204void lua_rawsetglobal (char *name)
205{ 205{
206 Word n = luaG_findsymbolbyname(name); 206 TaggedString *ts = luaS_new(name);
207 checkCparams(1); 207 checkCparams(1);
208 s_object(n) = *(--luaD_stack.top); 208 luaS_rawsetglobal(ts, --luaD_stack.top);
209} 209}
210 210
211 211
@@ -268,7 +268,7 @@ void *lua_getuserdata (lua_Object object)
268{ 268{
269 if (object == LUA_NOOBJECT || ttype(Address(object)) != LUA_T_USERDATA) 269 if (object == LUA_NOOBJECT || ttype(Address(object)) != LUA_T_USERDATA)
270 return NULL; 270 return NULL;
271 else return tsvalue(Address(object))->u.v; 271 else return tsvalue(Address(object))->u.d.v;
272} 272}
273 273
274lua_CFunction lua_getcfunction (lua_Object object) 274lua_CFunction lua_getcfunction (lua_Object object)
@@ -352,7 +352,7 @@ int lua_tag (lua_Object lo)
352 TObject *o = Address(lo); 352 TObject *o = Address(lo);
353 lua_Type t = ttype(o); 353 lua_Type t = ttype(o);
354 if (t == LUA_T_USERDATA) 354 if (t == LUA_T_USERDATA)
355 return o->value.ts->tag; 355 return o->value.ts->u.d.tag;
356 else if (t == LUA_T_ARRAY) 356 else if (t == LUA_T_ARRAY)
357 return o->value.a->htag; 357 return o->value.a->htag;
358 else return t; 358 else return t;
@@ -369,7 +369,7 @@ void lua_settag (int tag)
369 (luaD_stack.top-1)->value.a->htag = tag; 369 (luaD_stack.top-1)->value.a->htag = tag;
370 break; 370 break;
371 case LUA_T_USERDATA: 371 case LUA_T_USERDATA:
372 (luaD_stack.top-1)->value.ts->tag = tag; 372 (luaD_stack.top-1)->value.ts->u.d.tag = tag;
373 break; 373 break;
374 default: 374 default:
375 luaL_verror("cannot change the tag of a %s", 375 luaL_verror("cannot change the tag of a %s",
@@ -483,7 +483,7 @@ char *lua_getobjname (lua_Object o, char **name)
483 functofind = Address(o); 483 functofind = Address(o);
484 if ((*name = luaT_travtagmethods(checkfunc)) != NULL) 484 if ((*name = luaT_travtagmethods(checkfunc)) != NULL)
485 return "tag-method"; 485 return "tag-method";
486 else if ((*name = luaG_travsymbol(checkfunc)) != NULL) 486 else if ((*name = luaS_travsymbol(checkfunc)) != NULL)
487 return "global"; 487 return "global";
488 else return ""; 488 else return "";
489} 489}