aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-12-02 14:24:45 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-12-02 14:24:45 -0200
commit8223ff473f3ffe782629fb1ba9ce1f96efeb7fd4 (patch)
tree94d59b8fcc1845002f8972f46069140cee7079c0 /lapi.c
parentfe237ad8085f34e89fcd3610a9771215af63f03f (diff)
downloadlua-8223ff473f3ffe782629fb1ba9ce1f96efeb7fd4.tar.gz
lua-8223ff473f3ffe782629fb1ba9ce1f96efeb7fd4.tar.bz2
lua-8223ff473f3ffe782629fb1ba9ce1f96efeb7fd4.zip
lua_Object is a pointer to the stack (because now the stack doen't move)
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c102
1 files changed, 51 insertions, 51 deletions
diff --git a/lapi.c b/lapi.c
index 364179a4..b4f17b37 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.60 1999/11/29 19:31:29 roberto Exp roberto $ 2** $Id: lapi.c,v 1.61 1999/12/01 19:50:08 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*/
@@ -31,11 +31,6 @@ const char lua_ident[] = "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n"
31 31
32 32
33 33
34TObject *luaA_Address (lua_State *L, lua_Object o) {
35 return (o != LUA_NOOBJECT) ? Address(L, o) : NULL;
36}
37
38
39static lua_Type normalized_type (const TObject *o) { 34static lua_Type normalized_type (const TObject *o) {
40 int t = ttype(o); 35 int t = ttype(o);
41 switch (t) { 36 switch (t) {
@@ -71,14 +66,14 @@ static void checkCparams (lua_State *L, int nParams) {
71static lua_Object put_luaObject (lua_State *L, const TObject *o) { 66static lua_Object put_luaObject (lua_State *L, const TObject *o) {
72 luaD_openstack(L, L->Cstack.base); 67 luaD_openstack(L, L->Cstack.base);
73 *L->Cstack.base++ = *o; 68 *L->Cstack.base++ = *o;
74 return Ref(L, L->Cstack.base-1); 69 return L->Cstack.base-1;
75} 70}
76 71
77 72
78lua_Object luaA_putObjectOnTop (lua_State *L) { 73lua_Object luaA_putObjectOnTop (lua_State *L) {
79 luaD_openstack(L, L->Cstack.base); 74 luaD_openstack(L, L->Cstack.base);
80 *L->Cstack.base++ = *(--L->top); 75 *L->Cstack.base++ = *(--L->top);
81 return Ref(L, L->Cstack.base-1); 76 return L->Cstack.base-1;
82} 77}
83 78
84 79
@@ -102,7 +97,7 @@ lua_Object lua_pop (lua_State *L) {
102*/ 97*/
103lua_Object lua_lua2C (lua_State *L, int number) { 98lua_Object lua_lua2C (lua_State *L, int number) {
104 if (number <= 0 || number > L->Cstack.num) return LUA_NOOBJECT; 99 if (number <= 0 || number > L->Cstack.num) return LUA_NOOBJECT;
105 return Ref(L, L->Cstack.lua2C+number-1); 100 return L->Cstack.lua2C+number-1;
106} 101}
107 102
108 103
@@ -111,7 +106,7 @@ int lua_callfunction (lua_State *L, lua_Object function) {
111 return 1; 106 return 1;
112 else { 107 else {
113 luaD_openstack(L, L->Cstack.base); 108 luaD_openstack(L, L->Cstack.base);
114 set_normalized(L->Cstack.base, Address(L, function)); 109 set_normalized(L->Cstack.base, function);
115 return luaD_protectedrun(L); 110 return luaD_protectedrun(L);
116 } 111 }
117} 112}
@@ -205,27 +200,33 @@ void lua_rawsetglobal (lua_State *L, const char *name) {
205 200
206 201
207const char *lua_type (lua_State *L, lua_Object o) { 202const char *lua_type (lua_State *L, lua_Object o) {
208 return (o == LUA_NOOBJECT) ? "NOOBJECT" : luaO_typename(L, Address(L, o)); 203 UNUSED(L);
204 return (o == LUA_NOOBJECT) ? "NOOBJECT" : luaO_typename(L, o);
209} 205}
210 206
211int lua_isnil (lua_State *L, lua_Object o) { 207int lua_isnil (lua_State *L, lua_Object o) {
212 return (o != LUA_NOOBJECT) && (ttype(Address(L, o)) == LUA_T_NIL); 208 UNUSED(L);
209 return (o != LUA_NOOBJECT) && (ttype(o) == LUA_T_NIL);
213} 210}
214 211
215int lua_istable (lua_State *L, lua_Object o) { 212int lua_istable (lua_State *L, lua_Object o) {
216 return (o != LUA_NOOBJECT) && (ttype(Address(L, o)) == LUA_T_ARRAY); 213 UNUSED(L);
214 return (o != LUA_NOOBJECT) && (ttype(o) == LUA_T_ARRAY);
217} 215}
218 216
219int lua_isuserdata (lua_State *L, lua_Object o) { 217int lua_isuserdata (lua_State *L, lua_Object o) {
220 return (o != LUA_NOOBJECT) && (ttype(Address(L, o)) == LUA_T_USERDATA); 218 UNUSED(L);
219 return (o != LUA_NOOBJECT) && (ttype(o) == LUA_T_USERDATA);
221} 220}
222 221
223int lua_iscfunction (lua_State *L, lua_Object o) { 222int lua_iscfunction (lua_State *L, lua_Object o) {
223 UNUSED(L);
224 return (lua_tag(L, o) == LUA_T_CPROTO); 224 return (lua_tag(L, o) == LUA_T_CPROTO);
225} 225}
226 226
227int lua_isnumber (lua_State *L, lua_Object o) { 227int lua_isnumber (lua_State *L, lua_Object o) {
228 return (o != LUA_NOOBJECT) && (tonumber(Address(L, o)) == 0); 228 UNUSED(L);
229 return (o != LUA_NOOBJECT) && (tonumber(o) == 0);
229} 230}
230 231
231int lua_isstring (lua_State *L, lua_Object o) { 232int lua_isstring (lua_State *L, lua_Object o) {
@@ -239,41 +240,44 @@ int lua_isfunction (lua_State *L, lua_Object o) {
239} 240}
240 241
241int lua_equal(lua_State *L, lua_Object o1, lua_Object o2) { 242int lua_equal(lua_State *L, lua_Object o1, lua_Object o2) {
243 UNUSED(L);
242 if (o1 == LUA_NOOBJECT || o2 == LUA_NOOBJECT) return (o1 == o2); 244 if (o1 == LUA_NOOBJECT || o2 == LUA_NOOBJECT) return (o1 == o2);
243 else return luaO_equalObj(Address(L, o1), Address(L, o2)); 245 else return luaO_equalObj(o1, o2);
244} 246}
245 247
246 248
247double lua_getnumber (lua_State *L, lua_Object obj) { 249double lua_getnumber (lua_State *L, lua_Object obj) {
248 if (obj == LUA_NOOBJECT) return 0.0; 250 UNUSED(L);
249 if (tonumber(Address(L, obj))) return 0.0; 251 if (obj == LUA_NOOBJECT) return 0.0;
250 else return (nvalue(Address(L, obj))); 252 if (tonumber(obj)) return 0.0;
253 else return (nvalue(obj));
251} 254}
252 255
253const char *lua_getstring (lua_State *L, lua_Object obj) { 256const char *lua_getstring (lua_State *L, lua_Object obj) {
254 luaC_checkGC(L); /* `tostring' may create a new string */ 257 luaC_checkGC(L); /* `tostring' may create a new string */
255 if (obj == LUA_NOOBJECT || tostring(L, Address(L, obj))) 258 if (obj == LUA_NOOBJECT || tostring(L, obj))
256 return NULL; 259 return NULL;
257 else return (svalue(Address(L, obj))); 260 else return (svalue(obj));
258} 261}
259 262
260long lua_strlen (lua_State *L, lua_Object obj) { 263long lua_strlen (lua_State *L, lua_Object obj) {
261 luaC_checkGC(L); /* `tostring' may create a new string */ 264 UNUSED(L);
262 if (obj == LUA_NOOBJECT || tostring(L, Address(L, obj))) 265 if (obj == LUA_NOOBJECT || tostring(L, obj))
263 return 0L; 266 return 0L;
264 else return (tsvalue(Address(L, obj))->u.s.len); 267 else return (tsvalue(obj)->u.s.len);
265} 268}
266 269
267void *lua_getuserdata (lua_State *L, lua_Object obj) { 270void *lua_getuserdata (lua_State *L, lua_Object obj) {
268 if (obj == LUA_NOOBJECT || ttype(Address(L, obj)) != LUA_T_USERDATA) 271 UNUSED(L);
272 if (obj == LUA_NOOBJECT || ttype(obj) != LUA_T_USERDATA)
269 return NULL; 273 return NULL;
270 else return tsvalue(Address(L, obj))->u.d.value; 274 else return tsvalue(obj)->u.d.value;
271} 275}
272 276
273lua_CFunction lua_getcfunction (lua_State *L, lua_Object obj) { 277lua_CFunction lua_getcfunction (lua_State *L, lua_Object obj) {
274 if (!lua_iscfunction(L, obj)) 278 if (!lua_iscfunction(L, obj))
275 return NULL; 279 return NULL;
276 else return fvalue(luaA_protovalue(Address(L, obj))); 280 else return fvalue(luaA_protovalue(obj));
277} 281}
278 282
279 283
@@ -330,16 +334,16 @@ void luaA_pushobject (lua_State *L, const TObject *o) {
330void lua_pushobject (lua_State *L, lua_Object o) { 334void lua_pushobject (lua_State *L, lua_Object o) {
331 if (o == LUA_NOOBJECT) 335 if (o == LUA_NOOBJECT)
332 lua_error(L, "API error - attempt to push a NOOBJECT"); 336 lua_error(L, "API error - attempt to push a NOOBJECT");
333 set_normalized(L->top, Address(L, o)); 337 set_normalized(L->top, o);
334 incr_top; 338 incr_top;
335} 339}
336 340
337 341
338int lua_tag (lua_State *L, lua_Object lo) { 342int lua_tag (lua_State *L, lua_Object o) {
339 if (lo == LUA_NOOBJECT) 343 UNUSED(L);
344 if (o == LUA_NOOBJECT)
340 return LUA_T_NIL; 345 return LUA_T_NIL;
341 else { 346 else {
342 const TObject *o = Address(L, lo);
343 int t; 347 int t;
344 switch (t = ttype(o)) { 348 switch (t = ttype(o)) {
345 case LUA_T_USERDATA: 349 case LUA_T_USERDATA:
@@ -429,8 +433,7 @@ int luaA_next (lua_State *L, const Hash *t, int i) {
429} 433}
430 434
431 435
432int lua_next (lua_State *L, lua_Object o, int i) { 436int lua_next (lua_State *L, lua_Object t, int i) {
433 const TObject *t = Address(L, o);
434 if (ttype(t) != LUA_T_ARRAY) 437 if (ttype(t) != LUA_T_ARRAY)
435 lua_error(L, "API error - object is not a table in `lua_next'"); 438 lua_error(L, "API error - object is not a table in `lua_next'");
436 i = luaA_next(L, avalue(t), i); 439 i = luaA_next(L, avalue(t), i);
@@ -482,33 +485,31 @@ lua_Function lua_stackedfunction (lua_State *L, int level) {
482 int t = L->stack[i].ttype; 485 int t = L->stack[i].ttype;
483 if (t == LUA_T_CLMARK || t == LUA_T_PMARK || t == LUA_T_CMARK) 486 if (t == LUA_T_CLMARK || t == LUA_T_PMARK || t == LUA_T_CMARK)
484 if (level-- == 0) 487 if (level-- == 0)
485 return Ref(L, L->stack+i); 488 return L->stack+i;
486 } 489 }
487 return LUA_NOOBJECT; 490 return LUA_NOOBJECT;
488} 491}
489 492
490 493
491int lua_nups (lua_State *L, lua_Function func) { 494int lua_nups (lua_State *L, lua_Function f) {
492 const TObject *o = luaA_Address(L, func); 495 UNUSED(L);
493 return (!o || normalized_type(o) != LUA_T_CLOSURE) ? 0 : o->value.cl->nelems; 496 return (!f || normalized_type(f) != LUA_T_CLOSURE) ? 0 : f->value.cl->nelems;
494} 497}
495 498
496 499
497int lua_currentline (lua_State *L, lua_Function func) { 500int lua_currentline (lua_State *L, lua_Function f) {
498 const TObject *f = Address(L, func);
499 return (f+1 < L->top && (f+1)->ttype == LUA_T_LINE) ? (f+1)->value.i : -1; 501 return (f+1 < L->top && (f+1)->ttype == LUA_T_LINE) ? (f+1)->value.i : -1;
500} 502}
501 503
502 504
503lua_Object lua_getlocal (lua_State *L, lua_Function func, int local_number, 505lua_Object lua_getlocal (lua_State *L, lua_Function f, int local_number,
504 const char **name) { 506 const char **name) {
505 /* check whether func is a Lua function */ 507 /* check whether `f' is a Lua function */
506 if (lua_tag(L, func) != LUA_T_PROTO) 508 if (lua_tag(L, f) != LUA_T_PROTO)
507 return LUA_NOOBJECT; 509 return LUA_NOOBJECT;
508 else { 510 else {
509 TObject *f = Address(L, func);
510 TProtoFunc *fp = luaA_protovalue(f)->value.tf; 511 TProtoFunc *fp = luaA_protovalue(f)->value.tf;
511 *name = luaF_getlocalname(fp, local_number, lua_currentline(L, func)); 512 *name = luaF_getlocalname(fp, local_number, lua_currentline(L, f));
512 if (*name) { 513 if (*name) {
513 /* if "*name", there must be a LUA_T_LINE */ 514 /* if "*name", there must be a LUA_T_LINE */
514 /* therefore, f+2 points to function base */ 515 /* therefore, f+2 points to function base */
@@ -520,15 +521,14 @@ lua_Object lua_getlocal (lua_State *L, lua_Function func, int local_number,
520} 521}
521 522
522 523
523int lua_setlocal (lua_State *L, lua_Function func, int local_number) { 524int lua_setlocal (lua_State *L, lua_Function f, int local_number) {
524 /* check whether func is a Lua function */ 525 /* check whether `f' is a Lua function */
525 if (lua_tag(L, func) != LUA_T_PROTO) 526 if (lua_tag(L, f) != LUA_T_PROTO)
526 return 0; 527 return 0;
527 else { 528 else {
528 TObject *f = Address(L, func);
529 TProtoFunc *fp = luaA_protovalue(f)->value.tf; 529 TProtoFunc *fp = luaA_protovalue(f)->value.tf;
530 const char *name = luaF_getlocalname(fp, local_number, 530 const char *name = luaF_getlocalname(fp, local_number,
531 lua_currentline(L, func)); 531 lua_currentline(L, f));
532 checkCparams(L, 1); 532 checkCparams(L, 1);
533 --L->top; 533 --L->top;
534 if (name) { 534 if (name) {
@@ -548,7 +548,7 @@ void lua_funcinfo (lua_State *L, lua_Object func,
548 if (!lua_isfunction(L, func)) 548 if (!lua_isfunction(L, func))
549 lua_error(L, "API error - `funcinfo' called with a non-function value"); 549 lua_error(L, "API error - `funcinfo' called with a non-function value");
550 else { 550 else {
551 const TObject *f = luaA_protovalue(Address(L, func)); 551 const TObject *f = luaA_protovalue(func);
552 if (normalized_type(f) == LUA_T_PROTO) { 552 if (normalized_type(f) == LUA_T_PROTO) {
553 *source = tfvalue(f)->source->str; 553 *source = tfvalue(f)->source->str;
554 *linedefined = tfvalue(f)->lineDefined; 554 *linedefined = tfvalue(f)->lineDefined;
@@ -569,7 +569,7 @@ static int checkfunc (lua_State *L, TObject *o) {
569const char *lua_getobjname (lua_State *L, lua_Object o, const char **name) { 569const char *lua_getobjname (lua_State *L, lua_Object o, const char **name) {
570 /* try to find a name for given function */ 570 /* try to find a name for given function */
571 GlobalVar *g; 571 GlobalVar *g;
572 set_normalized(L->top, Address(L, o)); /* to be used by `checkfunc' */ 572 set_normalized(L->top, o); /* to be used by `checkfunc' */
573 for (g=L->rootglobal; g; g=g->next) { 573 for (g=L->rootglobal; g; g=g->next) {
574 if (checkfunc(L, &g->value)) { 574 if (checkfunc(L, &g->value)) {
575 *name = g->name->str; 575 *name = g->name->str;