diff options
Diffstat (limited to 'lbuiltin.c')
-rw-r--r-- | lbuiltin.c | 27 |
1 files changed, 25 insertions, 2 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbuiltin.c,v 1.15 1997/12/09 13:35:19 roberto Exp roberto $ | 2 | ** $Id: lbuiltin.c,v 1.16 1997/12/11 17:21:11 roberto Exp roberto $ |
3 | ** Built-in functions | 3 | ** Built-in functions |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -140,10 +140,18 @@ static char *to_string (lua_Object obj) | |||
140 | sprintf(buff, "table: %p", (void *)o->value.a); | 140 | sprintf(buff, "table: %p", (void *)o->value.a); |
141 | return buff; | 141 | return buff; |
142 | } | 142 | } |
143 | case LUA_T_FUNCTION: { | 143 | case LUA_T_CLOSURE: { |
144 | sprintf(buff, "function: %p", (void *)o->value.cl); | 144 | sprintf(buff, "function: %p", (void *)o->value.cl); |
145 | return buff; | 145 | return buff; |
146 | } | 146 | } |
147 | case LUA_T_PROTO: { | ||
148 | sprintf(buff, "function: %p", (void *)o->value.tf); | ||
149 | return buff; | ||
150 | } | ||
151 | case LUA_T_CPROTO: { | ||
152 | sprintf(buff, "function: %p", (void *)o->value.f); | ||
153 | return buff; | ||
154 | } | ||
147 | case LUA_T_USERDATA: { | 155 | case LUA_T_USERDATA: { |
148 | sprintf(buff, "userdata: %p", o->value.ts->u.d.v); | 156 | sprintf(buff, "userdata: %p", o->value.ts->u.d.v); |
149 | return buff; | 157 | return buff; |
@@ -372,6 +380,20 @@ static void mem_query (void) | |||
372 | } | 380 | } |
373 | 381 | ||
374 | 382 | ||
383 | static void countlist (void) | ||
384 | { | ||
385 | char *s = luaL_check_string(1); | ||
386 | GCnode *l = (s[0]=='t') ? L->roottable.next : (s[0]=='c') ? L->rootcl.next : | ||
387 | (s[0]=='p') ? L->rootproto.next : L->rootglobal.next; | ||
388 | int i=0; | ||
389 | while (l) { | ||
390 | i++; | ||
391 | l = l->next; | ||
392 | } | ||
393 | lua_pushnumber(i); | ||
394 | } | ||
395 | |||
396 | |||
375 | static void testC (void) | 397 | static void testC (void) |
376 | { | 398 | { |
377 | #define getnum(s) ((*s++) - '0') | 399 | #define getnum(s) ((*s++) - '0') |
@@ -433,6 +455,7 @@ static struct luaL_reg int_funcs[] = { | |||
433 | #ifdef DEBUG | 455 | #ifdef DEBUG |
434 | {"testC", testC}, | 456 | {"testC", testC}, |
435 | {"totalmem", mem_query}, | 457 | {"totalmem", mem_query}, |
458 | {"count", countlist}, | ||
436 | #endif | 459 | #endif |
437 | {"assert", luaI_assert}, | 460 | {"assert", luaI_assert}, |
438 | {"call", luaI_call}, | 461 | {"call", luaI_call}, |