A few more tests for table access in the API
Added tests where the table being accessed is also the index or value in the operation.
This commit is contained in:
16
ltests.c
16
ltests.c
@@ -1488,6 +1488,10 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) {
|
|||||||
else if EQ("pushfstringP") {
|
else if EQ("pushfstringP") {
|
||||||
lua_pushfstring(L1, lua_tostring(L, -2), lua_topointer(L, -1));
|
lua_pushfstring(L1, lua_tostring(L, -2), lua_topointer(L, -1));
|
||||||
}
|
}
|
||||||
|
else if EQ("rawget") {
|
||||||
|
int t = getindex;
|
||||||
|
lua_rawget(L1, t);
|
||||||
|
}
|
||||||
else if EQ("rawgeti") {
|
else if EQ("rawgeti") {
|
||||||
int t = getindex;
|
int t = getindex;
|
||||||
lua_rawgeti(L1, t, getnum);
|
lua_rawgeti(L1, t, getnum);
|
||||||
@@ -1496,6 +1500,14 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) {
|
|||||||
int t = getindex;
|
int t = getindex;
|
||||||
lua_rawgetp(L1, t, cast_voidp(cast_sizet(getnum)));
|
lua_rawgetp(L1, t, cast_voidp(cast_sizet(getnum)));
|
||||||
}
|
}
|
||||||
|
else if EQ("rawset") {
|
||||||
|
int t = getindex;
|
||||||
|
lua_rawset(L1, t);
|
||||||
|
}
|
||||||
|
else if EQ("rawseti") {
|
||||||
|
int t = getindex;
|
||||||
|
lua_rawseti(L1, t, getnum);
|
||||||
|
}
|
||||||
else if EQ("rawsetp") {
|
else if EQ("rawsetp") {
|
||||||
int t = getindex;
|
int t = getindex;
|
||||||
lua_rawsetp(L1, t, cast_voidp(cast_sizet(getnum)));
|
lua_rawsetp(L1, t, cast_voidp(cast_sizet(getnum)));
|
||||||
@@ -1538,6 +1550,10 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) {
|
|||||||
const char *s = getstring;
|
const char *s = getstring;
|
||||||
lua_setfield(L1, t, s);
|
lua_setfield(L1, t, s);
|
||||||
}
|
}
|
||||||
|
else if EQ("seti") {
|
||||||
|
int t = getindex;
|
||||||
|
lua_seti(L1, t, getnum);
|
||||||
|
}
|
||||||
else if EQ("setglobal") {
|
else if EQ("setglobal") {
|
||||||
const char *s = getstring;
|
const char *s = getstring;
|
||||||
lua_setglobal(L1, s);
|
lua_setglobal(L1, s);
|
||||||
|
|||||||
@@ -498,7 +498,53 @@ do -- getp/setp
|
|||||||
local a = {}
|
local a = {}
|
||||||
T.testC("rawsetp 2 1", a, 20)
|
T.testC("rawsetp 2 1", a, 20)
|
||||||
assert(a[T.pushuserdata(1)] == 20)
|
assert(a[T.pushuserdata(1)] == 20)
|
||||||
assert(T.testC("rawgetp 2 1; return 1", a) == 20)
|
assert(T.testC("rawgetp -1 1; return 1", a) == 20)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
do -- using the table itself as index
|
||||||
|
local a = {}
|
||||||
|
a[a] = 10
|
||||||
|
local prog = "gettable -1; return *"
|
||||||
|
local res = {T.testC(prog, a)}
|
||||||
|
assert(#res == 2 and res[1] == prog and res[2] == 10)
|
||||||
|
|
||||||
|
local prog = "settable -2; return *"
|
||||||
|
local res = {T.testC(prog, a, 20)}
|
||||||
|
assert(a[a] == 20)
|
||||||
|
assert(#res == 1 and res[1] == prog)
|
||||||
|
|
||||||
|
-- raw
|
||||||
|
a[a] = 10
|
||||||
|
local prog = "rawget -1; return *"
|
||||||
|
local res = {T.testC(prog, a)}
|
||||||
|
assert(#res == 2 and res[1] == prog and res[2] == 10)
|
||||||
|
|
||||||
|
local prog = "rawset -2; return *"
|
||||||
|
local res = {T.testC(prog, a, 20)}
|
||||||
|
assert(a[a] == 20)
|
||||||
|
assert(#res == 1 and res[1] == prog)
|
||||||
|
|
||||||
|
-- using the table as the value to set
|
||||||
|
local prog = "rawset -1; return *"
|
||||||
|
local res = {T.testC(prog, 30, a)}
|
||||||
|
assert(a[30] == a)
|
||||||
|
assert(#res == 1 and res[1] == prog)
|
||||||
|
|
||||||
|
local prog = "settable -1; return *"
|
||||||
|
local res = {T.testC(prog, 40, a)}
|
||||||
|
assert(a[40] == a)
|
||||||
|
assert(#res == 1 and res[1] == prog)
|
||||||
|
|
||||||
|
local prog = "rawseti -1 100; return *"
|
||||||
|
local res = {T.testC(prog, a)}
|
||||||
|
assert(a[100] == a)
|
||||||
|
assert(#res == 1 and res[1] == prog)
|
||||||
|
|
||||||
|
local prog = "seti -1 200; return *"
|
||||||
|
local res = {T.testC(prog, a)}
|
||||||
|
assert(a[200] == a)
|
||||||
|
assert(#res == 1 and res[1] == prog)
|
||||||
end
|
end
|
||||||
|
|
||||||
a = {x=0, y=12}
|
a = {x=0, y=12}
|
||||||
|
|||||||
Reference in New Issue
Block a user