Skip to content

Commit f743911

Browse files
committed
Details (in test library)
- Added support for negative stack indices in the "C interpreter" - Improved format when printing values
1 parent 39a14ea commit f743911

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

ltests.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,19 @@ void lua_printvalue (TValue *v) {
343343
printf("%s", (!l_isfalse(v) ? "true" : "false"));
344344
break;
345345
}
346+
case LUA_TLIGHTUSERDATA: {
347+
printf("light udata: %p", pvalue(v));
348+
break;
349+
}
346350
case LUA_TNIL: {
347351
printf("nil");
348352
break;
349353
}
350354
default: {
351-
void *p = iscollectable(v) ? gcvalue(v) : NULL;
352-
printf("%s: %p", ttypename(ttype(v)), p);
355+
if (ttislcf(v))
356+
printf("light C function: %p", fvalue(v));
357+
else /* must be collectable */
358+
printf("%s: %p", ttypename(ttype(v)), gcvalue(v));
353359
break;
354360
}
355361
}
@@ -1499,9 +1505,14 @@ static int getindex_aux (lua_State *L, lua_State *L1, const char **pc) {
14991505
skip(pc);
15001506
switch (*(*pc)++) {
15011507
case 'R': return LUA_REGISTRYINDEX;
1502-
case 'G': return luaL_error(L, "deprecated index 'G'");
15031508
case 'U': return lua_upvalueindex(getnum_aux(L, L1, pc));
1504-
default: (*pc)--; return getnum_aux(L, L1, pc);
1509+
default: {
1510+
int n;
1511+
(*pc)--; /* to read again */
1512+
n = getnum_aux(L, L1, pc);
1513+
if (n == 0) return 0;
1514+
else return lua_absindex(L1, n);
1515+
}
15051516
}
15061517
}
15071518

@@ -1550,7 +1561,7 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) {
15501561
const char *inst = getstring;
15511562
if EQ("") return 0;
15521563
else if EQ("absindex") {
1553-
lua_pushinteger(L1, lua_absindex(L1, getindex));
1564+
lua_pushinteger(L1, getindex);
15541565
}
15551566
else if EQ("append") {
15561567
int t = getindex;

0 commit comments

Comments
 (0)