@@ -1,12 +1,10 @@
11if T == nil then
2−(Message or print)("
3− >>> testC not active: skipping API tests <<<
4−")
2+(Message or print)("\10\32\62\62\62\32\116\101\115\116\67\32\110\111\116\32\97\99\116\105\118\101\58\32\115\107\105\112\112\105\110\103\32\65\80\73\32\116\101\115\116\115\32\60\60\60\10")
53return
64end
7−local debug = require("debug")
5+local debug = require("\100\101\98\117\103")
86local pack = table.pack
9−local MEMERRMSG = "not enough memory"
7+local MEMERRMSG = "\110\111\116\32\101\110\111\117\103\104\32\109\101\109\111\114\121"
108local function tcheck
119(t1,t2)
1210assert(t1.n == (t2.n or # t2) + 1)
@@ -20,226 +18,197 @@ local function checkerr
2018local stat,err = pcall(f,...)
2119assert(not stat and string.find(err,msg))
2220end
23−print("testing C API")
24−local a = T.testC("pushvalue R; return 1")
21+print("\116\101\115\116\105\110\103\32\67\32\65\80\73")
22+local a = T.testC("\112\117\115\104\118\97\108\117\101\32\82\59\32\114\101\116\117\114\110\32\49")
2523assert(a == debug.getregistry())
26−assert(T.testC("settop 10; absindex -1; return 1") == 10)
27−assert(T.testC("settop 5; absindex -5; return 1") == 1)
28−assert(T.testC("settop 10; absindex 1; return 1") == 1)
29−assert(T.testC("settop 10; absindex R; return 1") < - 10)
30−a=T.d2s(12458954321123)
31−assert(a == string.pack("d",12458954321123))
32−assert(T.s2d(a) == 12458954321123)
33−local a,b,c = T.testC("pushnum 1; pushnum 2; pushnum 3; return 2")
24+assert(T.testC("\115\101\116\116\111\112\32\49\48\59\32\97\98\115\105\110\100\101\120\32\45\49\59\32\114\101\116\117\114\110\32\49") == 10)
25+assert(T.testC("\115\101\116\116\111\112\32\53\59\32\97\98\115\105\110\100\101\120\32\45\53\59\32\114\101\116\117\114\110\32\49") == 1)
26+assert(T.testC("\115\101\116\116\111\112\32\49\48\59\32\97\98\115\105\110\100\101\120\32\49\59\32\114\101\116\117\114\110\32\49") == 1)
27+assert(T.testC("\115\101\116\116\111\112\32\49\48\59\32\97\98\115\105\110\100\101\120\32\82\59\32\114\101\116\117\114\110\32\49") < - 10)
28+a=T.d2s(12458954321123.0)
29+assert(a == string.pack("\100",12458954321123.0))
30+assert(T.s2d(a) == 12458954321123.0)
31+local a,b,c = T.testC("\112\117\115\104\110\117\109\32\49\59\32\112\117\115\104\110\117\109\32\50\59\32\112\117\115\104\110\117\109\32\51\59\32\114\101\116\117\114\110\32\50")
3432assert(a == 2 and b == 3 and not c)
35−local f = T.makeCfunc("pushnum 1; pushnum 2; pushnum 3; return 2")
33+local f = T.makeCfunc("\112\117\115\104\110\117\109\32\49\59\32\112\117\115\104\110\117\109\32\50\59\32\112\117\115\104\110\117\109\32\51\59\32\114\101\116\117\114\110\32\50")
3634a,b,c=f()
3735assert(a == 2 and b == 3 and not c)
38−a,b,c=T.testC("pushbool 1; pushbool 2; pushbool 0; return 3")
36+a,b,c=T.testC("\112\117\115\104\98\111\111\108\32\49\59\32\112\117\115\104\98\111\111\108\32\50\59\32\112\117\115\104\98\111\111\108\32\48\59\32\114\101\116\117\114\110\32\51")
3937assert(a == b and a == true and c == false)
40−a,b,c=T.testC("pushbool 0; pushbool 10; pushnil;
41− tobool -3; tobool -3; tobool -3; return 3")
38+a,b,c=T.testC("\112\117\115\104\98\111\111\108\32\48\59\32\112\117\115\104\98\111\111\108\32\49\48\59\32\112\117\115\104\110\105\108\59\10\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\116\111\98\111\111\108\32\45\51\59\32\116\111\98\111\111\108\32\45\51\59\32\116\111\98\111\111\108\32\45\51\59\32\114\101\116\117\114\110\32\51")
4239assert(a == false and b == true and c == false)
43−a,b,c=T.testC("gettop; return 2",10,20,30,40)
40+a,b,c=T.testC("\103\101\116\116\111\112\59\32\114\101\116\117\114\110\32\50",10,20,30,40)
4441assert(a == 40 and b == 5 and not c)
45−local t = pack(T.testC("settop 5; return *",2,3))
46−tcheck(t,{["n"] = 4,2,3})
47−t=pack(T.testC("settop 0; settop 15; return 10",3,1,23))
42+local t = pack(T.testC("\115\101\116\116\111\112\32\53\59\32\114\101\116\117\114\110\32\42",2,3))
43+tcheck(t,{["\110"] = 4,2,3})
44+t=pack(T.testC("\115\101\116\116\111\112\32\48\59\32\115\101\116\116\111\112\32\49\53\59\32\114\101\116\117\114\110\32\49\48",3,1,23))
4845assert(t.n == 10 and t[1] == nil and t[10] == nil)
49−t=pack(T.testC("remove -2; return *",2,3,4))
50−tcheck(t,{["n"] = 2,2,4})
51−t=pack(T.testC("insert -1; return *",2,3))
52−tcheck(t,{["n"] = 2,2,3})
53−t=pack(T.testC("insert 3; return *",2,3,4,5))
54−tcheck(t,{["n"] = 4,2,5,3,4})
55−t=pack(T.testC("replace 2; return *",2,3,4,5))
56−tcheck(t,{["n"] = 3,5,3,4})
57−t=pack(T.testC("replace -2; return *",2,3,4,5))
58−tcheck(t,{["n"] = 3,2,3,5})
59−t=pack(T.testC("remove 3; return *",2,3,4,5))
60−tcheck(t,{["n"] = 3,2,4,5})
61−t=pack(T.testC("copy 3 4; return *",2,3,4,5))
62−tcheck(t,{["n"] = 4,2,3,3,5})
63−t=pack(T.testC("copy -3 -1; return *",2,3,4,5))
64−tcheck(t,{["n"] = 4,2,3,4,3})
46+t=pack(T.testC("\114\101\109\111\118\101\32\45\50\59\32\114\101\116\117\114\110\32\42",2,3,4))
47+tcheck(t,{["\110"] = 2,2,4})
48+t=pack(T.testC("\105\110\115\101\114\116\32\45\49\59\32\114\101\116\117\114\110\32\42",2,3))
49+tcheck(t,{["\110"] = 2,2,3})
50+t=pack(T.testC("\105\110\115\101\114\116\32\51\59\32\114\101\116\117\114\110\32\42",2,3,4,5))
51+tcheck(t,{["\110"] = 4,2,5,3,4})
52+t=pack(T.testC("\114\101\112\108\97\99\101\32\50\59\32\114\101\116\117\114\110\32\42",2,3,4,5))
53+tcheck(t,{["\110"] = 3,5,3,4})
54+t=pack(T.testC("\114\101\112\108\97\99\101\32\45\50\59\32\114\101\116\117\114\110\32\42",2,3,4,5))
55+tcheck(t,{["\110"] = 3,2,3,5})
56+t=pack(T.testC("\114\101\109\111\118\101\32\51\59\32\114\101\116\117\114\110\32\42",2,3,4,5))
57+tcheck(t,{["\110"] = 3,2,4,5})
58+t=pack(T.testC("\99\111\112\121\32\51\32\52\59\32\114\101\116\117\114\110\32\42",2,3,4,5))
59+tcheck(t,{["\110"] = 4,2,3,3,5})
60+t=pack(T.testC("\99\111\112\121\32\45\51\32\45\49\59\32\114\101\116\117\114\110\32\42",2,3,4,5))
61+tcheck(t,{["\110"] = 4,2,3,4,3})
62+do
6563local t = {10,20,30,40,50,60}
6664for i = - 6, 6
6765do
68−local s = string.format("rotate 2 %d; return 7",i)
66+local s = string.format("\114\111\116\97\116\101\32\50\32\37\100\59\32\114\101\116\117\114\110\32\55",i)
6967local t1 = pack(T.testC(s,10,20,30,40,50,60))
7068tcheck(t1,t)
7169table.insert(t,1,table.remove(t))
7270end
73−t=pack(T.testC("rotate -2 1; return *",10,20,30,40))
71+t=pack(T.testC("\114\111\116\97\116\101\32\45\50\32\49\59\32\114\101\116\117\114\110\32\42",10,20,30,40))
7472tcheck(t,{10,20,40,30})
75−t=pack(T.testC("rotate -2 -1; return *",10,20,30,40))
73+t=pack(T.testC("\114\111\116\97\116\101\32\45\50\32\45\49\59\32\114\101\116\117\114\110\32\42",10,20,30,40))
7674tcheck(t,{10,20,40,30})
77−t=pack(T.testC("rotate -1 0; return *",10,20,30,40))
75+t=pack(T.testC("\114\111\116\97\116\101\32\45\49\32\48\59\32\114\101\116\117\114\110\32\42",10,20,30,40))
7876tcheck(t,{10,20,30,40})
79−t=pack(T.testC("rotate -1 1; return *",10,20,30,40))
77+t=pack(T.testC("\114\111\116\97\116\101\32\45\49\32\49\59\32\114\101\116\117\114\110\32\42",10,20,30,40))
8078tcheck(t,{10,20,30,40})
81−t=pack(T.testC("rotate 5 -1; return *",10,20,30,40))
79+t=pack(T.testC("\114\111\116\97\116\101\32\53\32\45\49\59\32\114\101\116\117\114\110\32\42",10,20,30,40))
8280tcheck(t,{10,20,30,40})
83−T.testC(" warningC "#This shold be a"
84− warningC " single "
85− warning "warning"
86− warningC "#This should be "
87− warning "another one"
88−")
89−local f = T.makeCfunc(" getglobal error
90− pushstring bola
91− pcall 1 1 1 # call 'error' with given handler
92− pushstatus
93− return 2 # return error message and status
94− ")
81+end
82+T.testC("\32\32\119\97\114\110\105\110\103\67\32\34\35\84\104\105\115\32\115\104\111\108\100\32\98\101\32\97\34\10\32\32\119\97\114\110\105\110\103\67\32\34\32\115\105\110\103\108\101\32\34\10\32\32\119\97\114\110\105\110\103\32\34\119\97\114\110\105\110\103\34\10\32\32\119\97\114\110\105\110\103\67\32\34\35\84\104\105\115\32\115\104\111\117\108\100\32\98\101\32\34\10\32\32\119\97\114\110\105\110\103\32\34\97\110\111\116\104\101\114\32\111\110\101\34\10")
83+do
84+local f = T.makeCfunc("\32\32\32\32\103\101\116\103\108\111\98\97\108\32\101\114\114\111\114\10\32\32\32\32\112\117\115\104\115\116\114\105\110\103\32\98\111\108\97\10\32\32\32\32\112\99\97\108\108\32\49\32\49\32\49\32\32\32\35\32\99\97\108\108\32\39\101\114\114\111\114\39\32\119\105\116\104\32\103\105\118\101\110\32\104\97\110\100\108\101\114\10\32\32\32\32\112\117\115\104\115\116\97\116\117\115\10\32\32\32\32\114\101\116\117\114\110\32\50\32\32\32\32\32\35\32\114\101\116\117\114\110\32\101\114\114\111\114\32\109\101\115\115\97\103\101\32\97\110\100\32\115\116\97\116\117\115\10\32\32")
9585local msg,st = f(string.upper)
96−assert(st == "ERRRUN" and msg == "BOLA")
86+assert(st == "\69\82\82\82\85\78" and msg == "\66\79\76\65")
9787local msg,st = f(string.len)
98−assert(st == "ERRRUN" and msg == 4)
99−t=pack(T.testC("insert 3; pushvalue 3; remove 3; pushvalue 2; remove 2;
100− insert 2; pushvalue 1; remove 1; insert 1;
101− insert -2; pushvalue -2; remove -3; return *",2,3,4,5,10,40,90))
102−tcheck(t,{["n"] = 7,2,3,4,5,10,40,90})
103−t=pack(T.testC("concat 5; return *","alo",2,3,"joao",12))
104−tcheck(t,{["n"] = 1,"alo23joao12"})
105−t=pack(T.testC("call 2,-1; return *",(a,b)
88+assert(st == "\69\82\82\82\85\78" and msg == 4)
89+end
90+t=pack(T.testC("\105\110\115\101\114\116\32\51\59\32\112\117\115\104\118\97\108\117\101\32\51\59\32\114\101\109\111\118\101\32\51\59\32\112\117\115\104\118\97\108\117\101\32\50\59\32\114\101\109\111\118\101\32\50\59\32\10\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\105\110\115\101\114\116\32\50\59\32\112\117\115\104\118\97\108\117\101\32\49\59\32\114\101\109\111\118\101\32\49\59\32\105\110\115\101\114\116\32\49\59\32\10\32\32\32\32\32\32\105\110\115\101\114\116\32\45\50\59\32\112\117\115\104\118\97\108\117\101\32\45\50\59\32\114\101\109\111\118\101\32\45\51\59\32\114\101\116\117\114\110\32\42",2,3,4,5,10,40,90))
91+tcheck(t,{["\110"] = 7,2,3,4,5,10,40,90})
92+t=pack(T.testC("\99\111\110\99\97\116\32\53\59\32\114\101\116\117\114\110\32\42","\97\108\111",2,3,"\106\111\97\111",12))
93+tcheck(t,{["\110"] = 1,"\97\108\111\50\51\106\111\97\111\49\50"})
94+t=pack(T.testC("\99\97\108\108\32\50\44\45\49\59\32\114\101\116\117\114\110\32\42",function (a,b)
10695return 1,2,3,4,a,b
107−end,"alo","joao"))
108−tcheck(t,{["n"] = 6,1,2,3,4,"alo","joao"})
96+end,"\97\108\111","\106\111\97\111"))
97+tcheck(t,{["\110"] = 6,1,2,3,4,"\97\108\111","\106\111\97\111"})
98+do
10999local a = {}
110−for i = 1, 1e3
100+for i = 1, 1000
111101do
112102a[i]=true
113103end
114104;
115105a[999]=10
116−local b = T.testC("pcall 1 -1 0; pop 1; tostring -1; return 1",table.unpack,a)
117−assert(b == "10")
106+local b = T.testC("\112\99\97\108\108\32\49\32\45\49\32\48\59\32\112\111\112\32\49\59\32\116\111\115\116\114\105\110\103\32\45\49\59\32\114\101\116\117\114\110\32\49",table.unpack,a)
107+assert(b == "\49\48")
108+end
118109_G.AA=14
119110;
120−_G.BB="a31"
121−local a = {T.testC(" getglobal AA;
122− getglobal BB;
123− getglobal BB;
124− setglobal AA;
125− return *
126−")}
127−assert(a[2] == 14 and a[3] == "a31" and a[4] == nil and _G.AA == "a31")
111+_G.BB="\97\51\49"
112+local a = {T.testC("\32\32\103\101\116\103\108\111\98\97\108\32\65\65\59\10\32\32\103\101\116\103\108\111\98\97\108\32\66\66\59\10\32\32\103\101\116\103\108\111\98\97\108\32\66\66\59\10\32\32\115\101\116\103\108\111\98\97\108\32\65\65\59\10\32\32\114\101\116\117\114\110\32\42\10")}
113+assert(a[2] == 14 and a[3] == "\97\51\49" and a[4] == nil and _G.AA == "\97\51\49")
128114_G.AA,_G.BB=nil
129−assert(T.testC("pushnum 10; pushnum 20; arith /; return 1") == 0.5)
130−assert(T.testC("pushnum 10; pushnum 20; arith -; return 1") == - 10)
131−assert(T.testC("pushnum 10; pushnum -20; arith *; return 1") == - 200)
132−assert(T.testC("pushnum 10; pushnum 3; arith ^; return 1") == 1e3)
133−assert(T.testC("pushnum 10; pushstring 20; arith /; return 1") == 0.5)
134−assert(T.testC("pushstring 10; pushnum 20; arith -; return 1") == - 10)
135−assert(T.testC("pushstring 10; pushstring -20; arith *; return 1") == - 200)
136−assert(T.testC("pushstring 10; pushstring 3; arith ^; return 1") == 1e3)
137−assert(T.testC("arith /; return 1",2,0) == 10 / 0)
138−a=T.testC("pushnum 10; pushint 3; arith \; return 1")
139−assert(a == 3 and math.type(a) == "float")
140−a=T.testC("pushint 10; pushint 3; arith \; return 1")
141−assert(a == 3 and math.type(a) == "integer")
142−a=assert(T.testC("pushint 10; pushint 3; arith +; return 1"))
143−assert(a == 13 and math.type(a) == "integer")
144−a=assert(T.testC("pushnum 10; pushint 3; arith +; return 1"))
145−assert(a == 13 and math.type(a) == "float")
146−a,b,c=T.testC("pushnum 1;
147− pushstring 10; arith _;
148− pushstring 5; return 3")
149−assert(a == 1 and b == - 10 and c == "5")
150−local mt = {["__add"] = (a,b)
115+assert(T.testC("\112\117\115\104\110\117\109\32\49\48\59\32\112\117\115\104\110\117\109\32\50\48\59\32\97\114\105\116\104\32\47\59\32\114\101\116\117\114\110\32\49") == 0.5)
116+assert(T.testC("\112\117\115\104\110\117\109\32\49\48\59\32\112\117\115\104\110\117\109\32\50\48\59\32\97\114\105\116\104\32\45\59\32\114\101\116\117\114\110\32\49") == - 10)
117+assert(T.testC("\112\117\115\104\110\117\109\32\49\48\59\32\112\117\115\104\110\117\109\32\45\50\48\59\32\97\114\105\116\104\32\42\59\32\114\101\116\117\114\110\32\49") == - 200)
118+assert(T.testC("\112\117\115\104\110\117\109\32\49\48\59\32\112\117\115\104\110\117\109\32\51\59\32\97\114\105\116\104\32\94\59\32\114\101\116\117\114\110\32\49") == 1000)
119+assert(T.testC("\112\117\115\104\110\117\109\32\49\48\59\32\112\117\115\104\115\116\114\105\110\103\32\50\48\59\32\97\114\105\116\104\32\47\59\32\114\101\116\117\114\110\32\49") == 0.5)
120+assert(T.testC("\112\117\115\104\115\116\114\105\110\103\32\49\48\59\32\112\117\115\104\110\117\109\32\50\48\59\32\97\114\105\116\104\32\45\59\32\114\101\116\117\114\110\32\49") == - 10)
121+assert(T.testC("\112\117\115\104\115\116\114\105\110\103\32\49\48\59\32\112\117\115\104\115\116\114\105\110\103\32\45\50\48\59\32\97\114\105\116\104\32\42\59\32\114\101\116\117\114\110\32\49") == - 200)
122+assert(T.testC("\112\117\115\104\115\116\114\105\110\103\32\49\48\59\32\112\117\115\104\115\116\114\105\110\103\32\51\59\32\97\114\105\116\104\32\94\59\32\114\101\116\117\114\110\32\49") == 1000)
123+assert(T.testC("\97\114\105\116\104\32\47\59\32\114\101\116\117\114\110\32\49",2,0) == 10.0 / 0)
124+a=T.testC("\112\117\115\104\110\117\109\32\49\48\59\32\112\117\115\104\105\110\116\32\51\59\32\97\114\105\116\104\32\92\59\32\114\101\116\117\114\110\32\49")
125+assert(a == 3.0 and math.type(a) == "\102\108\111\97\116")
126+a=T.testC("\112\117\115\104\105\110\116\32\49\48\59\32\112\117\115\104\105\110\116\32\51\59\32\97\114\105\116\104\32\92\59\32\114\101\116\117\114\110\32\49")
127+assert(a == 3 and math.type(a) == "\105\110\116\101\103\101\114")
128+a=assert(T.testC("\112\117\115\104\105\110\116\32\49\48\59\32\112\117\115\104\105\110\116\32\51\59\32\97\114\105\116\104\32\43\59\32\114\101\116\117\114\110\32\49"))
129+assert(a == 13 and math.type(a) == "\105\110\116\101\103\101\114")
130+a=assert(T.testC("\112\117\115\104\110\117\109\32\49\48\59\32\112\117\115\104\105\110\116\32\51\59\32\97\114\105\116\104\32\43\59\32\114\101\116\117\114\110\32\49"))
131+assert(a == 13 and math.type(a) == "\102\108\111\97\116")
132+a,b,c=T.testC("\112\117\115\104\110\117\109\32\49\59\10\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\112\117\115\104\115\116\114\105\110\103\32\49\48\59\32\97\114\105\116\104\32\95\59\10\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\112\117\115\104\115\116\114\105\110\103\32\53\59\32\114\101\116\117\114\110\32\51")
133+assert(a == 1 and b == - 10 and c == "\53")
134+local mt = {["\95\95\97\100\100"] = function (a,b)
151135return setmetatable({a[1] + b[1]},mt)
152−end,["__mod"] = (a,b)
136+end,["\95\95\109\111\100"] = function (a,b)
153137return setmetatable({a[1] % b[1]},mt)
154−end,["__unm"] = (a)
138+end,["\95\95\117\110\109"] = function (a)
155139return setmetatable({a[1] * 2},mt)
156140end}
157141a,b,c=setmetatable({4},mt),setmetatable({8},mt),setmetatable({- 3},mt)
158−local x,y,z = T.testC("arith +; return 2",10,a,b)
142+local x,y,z = T.testC("\97\114\105\116\104\32\43\59\32\114\101\116\117\114\110\32\50",10,a,b)
159143assert(x == 10 and y[1] == 12 and z == nil)
160−assert(T.testC("arith %; return 1",a,c)[1] == 4 % - 3)
161−assert(T.testC("arith _; arith +; arith %; return 1",b,a,c)[1] == 8 % (4 + (- 3) * 2))
162−checkerr("divide by zero",T.testC,"arith \",10,0)
163−checkerr("%%0",T.testC,"arith %",10,0)
164−assert(T.testC("compare LT 2 5, return 1",3,2,2,4,2,2))
165−assert(T.testC("compare LE 2 5, return 1",3,2,2,4,2,2))
166−assert(not T.testC("compare LT 3 4, return 1",3,2,2,4,2,2))
167−assert(T.testC("compare LE 3 4, return 1",3,2,2,4,2,2))
168−assert(T.testC("compare LT 5 2, return 1",4,2,2,3,2,2))
169−assert(not T.testC("compare LT 2 -3, return 1","4","2","2","3","2","2"))
170−assert(not T.testC("compare LT -3 2, return 1","3","2","2","4","2","2"))
171−assert(not T.testC("compare LT 1 4, return 1"))
172−assert(not T.testC("compare LE 9 1, return 1"))
173−assert(not T.testC("compare EQ 9 9, return 1"))
174−local b = {["__lt"] = (a,b)
144+assert(T.testC("\97\114\105\116\104\32\37\59\32\114\101\116\117\114\110\32\49",a,c)[1] == 4 % - 3)
145+assert(T.testC("\97\114\105\116\104\32\95\59\32\97\114\105\116\104\32\43\59\32\97\114\105\116\104\32\37\59\32\114\101\116\117\114\110\32\49",b,a,c)[1] == 8 % (4 + (- 3) * 2))
146+checkerr("\100\105\118\105\100\101\32\98\121\32\122\101\114\111",T.testC,"\97\114\105\116\104\32\92",10,0)
147+checkerr("\37\37\48",T.testC,"\97\114\105\116\104\32\37",10,0)
148+assert(T.testC("\99\111\109\112\97\114\101\32\76\84\32\50\32\53\44\32\114\101\116\117\114\110\32\49",3,2,2,4,2,2))
149+assert(T.testC("\99\111\109\112\97\114\101\32\76\69\32\50\32\53\44\32\114\101\116\117\114\110\32\49",3,2,2,4,2,2))
150+assert(not T.testC("\99\111\109\112\97\114\101\32\76\84\32\51\32\52\44\32\114\101\116\117\114\110\32\49",3,2,2,4,2,2))
151+assert(T.testC("\99\111\109\112\97\114\101\32\76\69\32\51\32\52\44\32\114\101\116\117\114\110\32\49",3,2,2,4,2,2))
152+assert(T.testC("\99\111\109\112\97\114\101\32\76\84\32\53\32\50\44\32\114\101\116\117\114\110\32\49",4,2,2,3,2,2))
153+assert(not T.testC("\99\111\109\112\97\114\101\32\76\84\32\50\32\45\51\44\32\114\101\116\117\114\110\32\49","\52","\50","\50","\51","\50","\50"))
154+assert(not T.testC("\99\111\109\112\97\114\101\32\76\84\32\45\51\32\50\44\32\114\101\116\117\114\110\32\49","\51","\50","\50","\52","\50","\50"))
155+assert(not T.testC("\99\111\109\112\97\114\101\32\76\84\32\49\32\52\44\32\114\101\116\117\114\110\32\49"))
156+assert(not T.testC("\99\111\109\112\97\114\101\32\76\69\32\57\32\49\44\32\114\101\116\117\114\110\32\49"))
157+assert(not T.testC("\99\111\109\112\97\114\101\32\69\81\32\57\32\57\44\32\114\101\116\117\114\110\32\49"))
158+local b = {["\95\95\108\116"] = function (a,b)
175159return a[1] < b[1]
176160end}
177161local a1,a3,a4 = setmetatable({1},b),setmetatable({3},b),setmetatable({4},b)
178−assert(T.testC("compare LT 2 5, return 1",a3,2,2,a4,2,2))
179−assert(T.testC("compare LE 2 5, return 1",a3,2,2,a4,2,2))
180−assert(T.testC("compare LT 5 -6, return 1",a4,2,2,a3,2,2))
181−a,b=T.testC("compare LT 5 -6, return 2",a1,2,2,a3,2,20)
162+assert(T.testC("\99\111\109\112\97\114\101\32\76\84\32\50\32\53\44\32\114\101\116\117\114\110\32\49",a3,2,2,a4,2,2))
163+assert(T.testC("\99\111\109\112\97\114\101\32\76\69\32\50\32\53\44\32\114\101\116\117\114\110\32\49",a3,2,2,a4,2,2))
164+assert(T.testC("\99\111\109\112\97\114\101\32\76\84\32\53\32\45\54\44\32\114\101\116\117\114\110\32\49",a4,2,2,a3,2,2))
165+a,b=T.testC("\99\111\109\112\97\114\101\32\76\84\32\53\32\45\54\44\32\114\101\116\117\114\110\32\50",a1,2,2,a3,2,20)
182166assert(a == 20 and b == false)
183−a,b=T.testC("compare LE 5 -6, return 2",a1,2,2,a3,2,20)
167+a,b=T.testC("\99\111\109\112\97\114\101\32\76\69\32\53\32\45\54\44\32\114\101\116\117\114\110\32\50",a1,2,2,a3,2,20)
184168assert(a == 20 and b == false)
185−a,b=T.testC("compare LE 5 -6, return 2",a1,2,2,a1,2,20)
169+a,b=T.testC("\99\111\109\112\97\114\101\32\76\69\32\53\32\45\54\44\32\114\101\116\117\114\110\32\50",a1,2,2,a1,2,20)
186170assert(a == 20 and b == true)
187−local mt = {["__lt"] = (a,b)
171+do
172+local mt = {["\95\95\108\116"] = function (a,b)
188173return a[1] < b[1]
189−end,["__le"] = (a,b)
174+end,["\95\95\108\101"] = function (a,b)
190175return a[1] <= b[1]
191−end,["__eq"] = (a,b)
176+end,["\95\95\101\113"] = function (a,b)
192177return a[1] == b[1]
193178end}
194179local function O
195180(x)
196181return setmetatable({x},mt)
197182end
198−local a,b = T.testC("compare LT 2 3; pushint 10; return 2",O(1),O(2))
183+local a,b = T.testC("\99\111\109\112\97\114\101\32\76\84\32\50\32\51\59\32\112\117\115\104\105\110\116\32\49\48\59\32\114\101\116\117\114\110\32\50",O(1),O(2))
199184assert(a == true and b == 10)
200−local a,b = T.testC("compare LE 2 3; pushint 10; return 2",O(3),O(2))
185+local a,b = T.testC("\99\111\109\112\97\114\101\32\76\69\32\50\32\51\59\32\112\117\115\104\105\110\116\32\49\48\59\32\114\101\116\117\114\110\32\50",O(3),O(2))
201186assert(a == false and b == 10)
202−local a,b = T.testC("compare EQ 2 3; pushint 10; return 2",O(3),O(3))
187+local a,b = T.testC("\99\111\109\112\97\114\101\32\69\81\32\50\32\51\59\32\112\117\115\104\105\110\116\32\49\48\59\32\114\101\116\117\114\110\32\50",O(3),O(3))
203188assert(a == true and b == 10)
204−local t = setmetatable({["x"] = 20},{["__len"] = (t)
189+end
190+local t = setmetatable({["\120"] = 20},{["\95\95\108\101\110"] = function (t)
205191return t.x
206192end})
207−a,b,c=T.testC(" len 2;
208− Llen 2;
209− objsize 2;
210− return 3
211−",t)
193+a,b,c=T.testC("\32\32\32\108\101\110\32\50\59\10\32\32\32\76\108\101\110\32\50\59\10\32\32\32\111\98\106\115\105\122\101\32\50\59\10\32\32\32\114\101\116\117\114\110\32\51\10",t)
212194assert(a == 20 and b == 20 and c == 0)
213−t.x="234"
195+t.x="\50\51\52"
214196;
215197t[1]=20
216−a,b,c=T.testC(" len 2;
217− Llen 2;
218− objsize 2;
219− return 3
220−",t)
221−assert(a == "234" and b == 234 and c == 1)
198+a,b,c=T.testC("\32\32\32\108\101\110\32\50\59\10\32\32\32\76\108\101\110\32\50\59\10\32\32\32\111\98\106\115\105\122\101\32\50\59\10\32\32\32\114\101\116\117\114\110\32\51\10",t)
199+assert(a == "\50\51\52" and b == 234 and c == 1)
222200t.x=print
223201;
224202t[1]=20
225−a,c=T.testC(" len 2;
226− objsize 2;
227− return 2
228−",t)
203+a,c=T.testC("\32\32\32\108\101\110\32\50\59\10\32\32\32\111\98\106\115\105\122\101\32\50\59\10\32\32\32\114\101\116\117\114\110\32\50\10",t)
229204assert(a == print and c == 1)
230−a=setmetatable({["x"] = "u"},{["__concat"] = (a,b)
231−return a.x .. "." .. b.x
205+a=setmetatable({["\120"] = "\117"},{["\95\95\99\111\110\99\97\116"] = function (a,b)
206+return a.x .. "\46" .. b.x
232207end})
233−x,y=T.testC(" pushnum 5
234− pushvalue 2;
235− pushvalue 2;
236− concat 2;
237− pushvalue -2;
238− return 2;
239−",a,a)
208+x,y=T.testC("\32\32\112\117\115\104\110\117\109\32\53\10\32\32\112\117\115\104\118\97\108\117\101\32\50\59\10\32\32\112\117\115\104\118\97\108\117\101\32\50\59\10\32\32\99\111\110\99\97\116\32\50\59\10\32\32\112\117\115\104\118\97\108\117\101\32\45\50\59\10\32\32\114\101\116\117\114\110\32\50\59\10",a,a)
240209assert(x == a .. a and y == 5)
241−assert(T.testC("concat 0; return 1") == "")
242−assert(T.testC("concat 1; return 1","xuxu") == "xuxu")
210+assert(T.testC("\99\111\110\99\97\116\32\48\59\32\114\101\116\117\114\110\32\49") == "")
211+assert(T.testC("\99\111\110\99\97\116\32\49\59\32\114\101\116\117\114\110\32\49","\120\117\120\117") == "\120\117\120\117")
243212local function B
244213(x)
245214return x and 1 or 0
@@ -247,26 +216,17 @@ end
247216local function count
248217(x,n)
249218n=n or 2
250−local prog = " isnumber %d;
251− isstring %d;
252− isfunction %d;
253− iscfunction %d;
254− istable %d;
255− isuserdata %d;
256− isnil %d;
257− isnull %d;
258− return 8
259− "
219+local prog = "\32\32\32\32\105\115\110\117\109\98\101\114\32\37\100\59\10\32\32\32\32\105\115\115\116\114\105\110\103\32\37\100\59\10\32\32\32\32\105\115\102\117\110\99\116\105\111\110\32\37\100\59\10\32\32\32\32\105\115\99\102\117\110\99\116\105\111\110\32\37\100\59\10\32\32\32\32\105\115\116\97\98\108\101\32\37\100\59\10\32\32\32\32\105\115\117\115\101\114\100\97\116\97\32\37\100\59\10\32\32\32\32\105\115\110\105\108\32\37\100\59\10\32\32\32\32\105\115\110\117\108\108\32\37\100\59\10\32\32\32\32\114\101\116\117\114\110\32\56\10\32\32"
260220prog=string.format(prog,n,n,n,n,n,n,n,n)
261221local a,b,c,d,e,f,g,h = T.testC(prog,x)
262222return B(a) + B(b) + B(c) + B(d) + B(e) + B(f) + B(g) + (100 * B(h))
263223end
264224assert(count(3) == 2)
265−assert(count("alo") == 1)
266−assert(count("32") == 2)
225+assert(count("\97\108\111") == 1)
226+assert(count("\51\50") == 2)
267227assert(count({}) == 1)
268228assert(count(print) == 2)
269−assert(count(()
229+assert(count(function ()
270230
271231end) == 1)
272232assert(count(nil) == 1)
@@ -275,100 +235,88 @@ assert(count(nil,15) == 100)
275235local function to
276236(s,x,n)
277237n=n or 2
278−return T.testC(string.format("%s %d; return 1",s,n),x)
238+return T.testC(string.format("\37\115\32\37\100\59\32\114\101\116\117\114\110\32\49",s,n),x)
279239end
280240local null = T.pushuserdata(0)
281241local hfunc = string.gmatch("","")
282242assert(debug.getupvalue(hfunc,1))
283−assert(to("tostring",{}) == nil)
284−assert(to("tostring","alo") == "alo")
285−assert(to("tostring",12) == "12")
286−assert(to("tostring",12,3) == nil)
287−assert(to("objsize",{}) == 0)
288−assert(to("objsize",{1,2,3}) == 3)
289−assert(to("objsize","aloa") == 6)
290−assert(to("objsize",T.newuserdata(0)) == 0)
291−assert(to("objsize",T.newuserdata(101)) == 101)
292−assert(to("objsize",124) == 0)
293−assert(to("objsize",true) == 0)
294−assert(to("tonumber",{}) == 0)
295−assert(to("tonumber","12") == 12)
296−assert(to("tonumber","s2") == 0)
297−assert(to("tonumber",1,20) == 0)
298−assert(to("topointer",10) == null)
299−assert(to("topointer",true) == null)
300−assert(to("topointer",nil) == null)
301−assert(to("topointer","abc") ~= null)
302−assert(to("topointer",string.rep("x",10)) == to("topointer",string.rep("x",10)))
303−local s1 = string.rep("x",300)
304−local s2 = string.rep("x",300)
305−assert(to("topointer",s1) ~= to("topointer",s2))
306−assert(to("topointer",T.pushuserdata(20)) ~= null)
307−assert(to("topointer",io.read) ~= null)
308−assert(to("topointer",hfunc) ~= null)
309−assert(to("topointer",()
243+assert(to("\116\111\115\116\114\105\110\103",{}) == nil)
244+assert(to("\116\111\115\116\114\105\110\103","\97\108\111") == "\97\108\111")
245+assert(to("\116\111\115\116\114\105\110\103",12) == "\49\50")
246+assert(to("\116\111\115\116\114\105\110\103",12,3) == nil)
247+assert(to("\111\98\106\115\105\122\101",{}) == 0)
248+assert(to("\111\98\106\115\105\122\101",{1,2,3}) == 3)
249+assert(to("\111\98\106\115\105\122\101","\97\108\111\97") == 6)
250+assert(to("\111\98\106\115\105\122\101",T.newuserdata(0)) == 0)
251+assert(to("\111\98\106\115\105\122\101",T.newuserdata(101)) == 101)
252+assert(to("\111\98\106\115\105\122\101",124) == 0)
253+assert(to("\111\98\106\115\105\122\101",true) == 0)
254+assert(to("\116\111\110\117\109\98\101\114",{}) == 0)
255+assert(to("\116\111\110\117\109\98\101\114","\49\50") == 12)
256+assert(to("\116\111\110\117\109\98\101\114","\115\50") == 0)
257+assert(to("\116\111\110\117\109\98\101\114",1,20) == 0)
258+assert(to("\116\111\112\111\105\110\116\101\114",10) == null)
259+assert(to("\116\111\112\111\105\110\116\101\114",true) == null)
260+assert(to("\116\111\112\111\105\110\116\101\114",nil) == null)
261+assert(to("\116\111\112\111\105\110\116\101\114","\97\98\99") ~= null)
262+assert(to("\116\111\112\111\105\110\116\101\114",string.rep("\120",10)) == to("\116\111\112\111\105\110\116\101\114",string.rep("\120",10)))
263+do
264+local s1 = string.rep("\120",300)
265+local s2 = string.rep("\120",300)
266+assert(to("\116\111\112\111\105\110\116\101\114",s1) ~= to("\116\111\112\111\105\110\116\101\114",s2))
267+end
268+assert(to("\116\111\112\111\105\110\116\101\114",T.pushuserdata(20)) ~= null)
269+assert(to("\116\111\112\111\105\110\116\101\114",io.read) ~= null)
270+assert(to("\116\111\112\111\105\110\116\101\114",hfunc) ~= null)
271+assert(to("\116\111\112\111\105\110\116\101\114",function ()
310272
311273end) ~= null)
312−assert(to("topointer",io.stdin) ~= null)
313−assert(to("func2num",20) == 0)
314−assert(to("func2num",T.pushuserdata(10)) == 0)
315−assert(to("func2num",io.read) ~= 0)
316−assert(to("func2num",hfunc) ~= 0)
317−a=to("tocfunction",math.deg)
274+assert(to("\116\111\112\111\105\110\116\101\114",io.stdin) ~= null)
275+assert(to("\102\117\110\99\50\110\117\109",20) == 0)
276+assert(to("\102\117\110\99\50\110\117\109",T.pushuserdata(10)) == 0)
277+assert(to("\102\117\110\99\50\110\117\109",io.read) ~= 0)
278+assert(to("\102\117\110\99\50\110\117\109",hfunc) ~= 0)
279+a=to("\116\111\99\102\117\110\99\116\105\111\110",math.deg)
318280assert(a(3) == math.deg(3) and a == math.deg)
319−print("testing panic function")
320−assert(T.checkpanic("pushstring hi; error") == "hi")
321−assert(T.checkpanic("pushstring hi; error;","checkstack 5 XX
322− pushstring ' alo'
323− pushstring ' mundo'
324− concat 3") == "hi alo mundo")
325−assert(T.checkpanic("loadstring 4") == "bad argument #4 (string expected, got no value)")
326−T.totalmem(T.totalmem() + 1e4)
327−assert(T.checkpanic("newuserdata 20000") == MEMERRMSG)
281+print("\116\101\115\116\105\110\103\32\112\97\110\105\99\32\102\117\110\99\116\105\111\110")
282+do
283+assert(T.checkpanic("\112\117\115\104\115\116\114\105\110\103\32\104\105\59\32\101\114\114\111\114") == "\104\105")
284+assert(T.checkpanic("\112\117\115\104\115\116\114\105\110\103\32\104\105\59\32\101\114\114\111\114\59","\99\104\101\99\107\115\116\97\99\107\32\53\32\88\88\10\32\32\32\32\32\32\112\117\115\104\115\116\114\105\110\103\32\39\32\97\108\111\39\10\32\32\32\32\32\32\112\117\115\104\115\116\114\105\110\103\32\39\32\109\117\110\100\111\39\10\32\32\32\32\32\32\99\111\110\99\97\116\32\51") == "\104\105\32\97\108\111\32\109\117\110\100\111")
285+assert(T.checkpanic("\108\111\97\100\115\116\114\105\110\103\32\52") == "\98\97\100\32\97\114\103\117\109\101\110\116\32\35\52\32\40\115\116\114\105\110\103\32\101\120\112\101\99\116\101\100\44\32\103\111\116\32\110\111\32\118\97\108\117\101\41")
286+T.totalmem(T.totalmem() + 10000)
287+assert(T.checkpanic("\110\101\119\117\115\101\114\100\97\116\97\32\50\48\48\48\48") == MEMERRMSG)
328288T.totalmem(0)
329289if not _soft then
330−local msg = T.checkpanic(" pushstring "function f() f() end"
331− loadstring -1; call 0 0
332− getglobal f; call 0 0
333− ")
334−assert(string.find(msg,"stack overflow"))
335−end
336−assert(T.checkpanic(" pushstring "return {__close = function () Y = 'ho'; end}"
337− newtable
338− loadstring -2
339− call 0 1
340− setmetatable -2
341− toclose -1
342− pushstring "hi"
343− error
344− "," getglobal Y
345− concat 2 # concat original error with global Y
346− ") == "hiho")
290+local msg = T.checkpanic("\32\32\32\32\32\32\112\117\115\104\115\116\114\105\110\103\32\34\102\117\110\99\116\105\111\110\32\102\40\41\32\102\40\41\32\101\110\100\34\10\32\32\32\32\32\32\108\111\97\100\115\116\114\105\110\103\32\45\49\59\32\99\97\108\108\32\48\32\48\10\32\32\32\32\32\32\103\101\116\103\108\111\98\97\108\32\102\59\32\99\97\108\108\32\48\32\48\10\32\32\32\32")
291+assert(string.find(msg,"\115\116\97\99\107\32\111\118\101\114\102\108\111\119"))
292+end
293+assert(T.checkpanic("\32\32\32\32\112\117\115\104\115\116\114\105\110\103\32\34\114\101\116\117\114\110\32\123\95\95\99\108\111\115\101\32\61\32\102\117\110\99\116\105\111\110\32\40\41\32\89\32\61\32\39\104\111\39\59\32\101\110\100\125\34\10\32\32\32\32\110\101\119\116\97\98\108\101\10\32\32\32\32\108\111\97\100\115\116\114\105\110\103\32\45\50\10\32\32\32\32\99\97\108\108\32\48\32\49\10\32\32\32\32\115\101\116\109\101\116\97\116\97\98\108\101\32\45\50\10\32\32\32\32\116\111\99\108\111\115\101\32\45\49\10\32\32\32\32\112\117\115\104\115\116\114\105\110\103\32\34\104\105\34\10\32\32\32\32\101\114\114\111\114\10\32\32","\32\32\32\32\103\101\116\103\108\111\98\97\108\32\89\10\32\32\32\32\99\111\110\99\97\116\32\50\32\32\32\32\32\32\32\32\32\35\32\99\111\110\99\97\116\32\111\114\105\103\105\110\97\108\32\101\114\114\111\114\32\119\105\116\104\32\103\108\111\98\97\108\32\89\10\32\32") == "\104\105\104\111")
294+end
347295if not _soft then
348−print("testing stack overflow")
349−collectgarbage("stop")
350−checkerr("XXXX",T.testC,"checkstack 1000023 XXXX")
351−checkerr("^stack overflow$",T.testC,"checkstack 1000023 ''")
352−local s = string.rep("pushnil;checkstack 1 XX;",1e6)
353−checkerr("overflow",T.testC,s)
354−collectgarbage("restart")
355−print("+")
356−end
357−local lim = _soft and 500 or 1.2e4
358−local prog = {"checkstack " .. (lim * 2 + 100) .. "msg","newtable"}
296+print("\116\101\115\116\105\110\103\32\115\116\97\99\107\32\111\118\101\114\102\108\111\119")
297+collectgarbage("\115\116\111\112")
298+checkerr("\88\88\88\88",T.testC,"\99\104\101\99\107\115\116\97\99\107\32\49\48\48\48\48\50\51\32\88\88\88\88")
299+checkerr("\94\115\116\97\99\107\32\111\118\101\114\102\108\111\119\36",T.testC,"\99\104\101\99\107\115\116\97\99\107\32\49\48\48\48\48\50\51\32\39\39")
300+local s = string.rep("\112\117\115\104\110\105\108\59\99\104\101\99\107\115\116\97\99\107\32\49\32\88\88\59",1000000)
301+checkerr("\111\118\101\114\102\108\111\119",T.testC,s)
302+collectgarbage("\114\101\115\116\97\114\116")
303+print("\43")
304+end
305+local lim = _soft and 500 or 12000
306+local prog = {"\99\104\101\99\107\115\116\97\99\107\32" .. (lim * 2 + 100) .. "\109\115\103","\110\101\119\116\97\98\108\101"}
359307for i = 1, lim
360308do
361−prog[# prog + 1]="pushnum " .. i
362−prog[# prog + 1]="pushnum " .. i * 10
309+prog[# prog + 1]="\112\117\115\104\110\117\109\32" .. i
310+prog[# prog + 1]="\112\117\115\104\110\117\109\32" .. i * 10
363311end
364−prog[# prog + 1]="rawgeti R 2"
365−prog[# prog + 1]="insert " .. - (2 * lim + 2)
312+prog[# prog + 1]="\114\97\119\103\101\116\105\32\82\32\50"
313+prog[# prog + 1]="\105\110\115\101\114\116\32" .. - (2 * lim + 2)
366314for i = 1, lim
367315do
368−prog[# prog + 1]="settable " .. - (2 * (lim - i + 1) + 1)
316+prog[# prog + 1]="\115\101\116\116\97\98\108\101\32" .. - (2 * (lim - i + 1) + 1)
369317end
370−prog[# prog + 1]="return 2"
371−prog=table.concat(prog,";")
318+prog[# prog + 1]="\114\101\116\117\114\110\32\50"
319+prog=table.concat(prog,"\59")
372320local g,t = T.testC(prog)
373321assert(g == _G)
374322for i = 1, lim
@@ -379,16 +327,12 @@ t[i]=undef
379327end
380328assert(next(t) == nil)
381329prog,g,t=nil
382−a=T.testC(" loadstring 2; pcall 0 1 0;
383− pushvalue 3; insert -2; pcall 1 1 0;
384− pcall 0 0 0;
385− return 1
386−","XX=150",(a)
330+a=T.testC("\32\32\108\111\97\100\115\116\114\105\110\103\32\50\59\32\112\99\97\108\108\32\48\32\49\32\48\59\10\32\32\112\117\115\104\118\97\108\117\101\32\51\59\32\105\110\115\101\114\116\32\45\50\59\32\112\99\97\108\108\32\49\32\49\32\48\59\10\32\32\112\99\97\108\108\32\48\32\48\32\48\59\10\32\32\114\101\116\117\114\110\32\49\10","\88\88\61\49\53\48",function (a)
387331assert(a == nil)
388332;
389333return 3
390334end)
391−assert(type(a) == "string" and XX == 150)
335+assert(type(a) == "\115\116\114\105\110\103" and XX == 150)
392336_G.XX=nil
393337local function check3
394338(p, ...)
@@ -396,160 +340,168 @@ local arg = {...}
396340assert(# arg == 3)
397341assert(string.find(arg[3],p))
398342end
399−check3(":1:",T.testC("loadstring 2; return *","x="))
400−check3("%.",T.testC("loadfile 2; return *","."))
401−check3("xxxx",T.testC("loadfile 2; return *","xxxx"))
343+check3("\58\49\58",T.testC("\108\111\97\100\115\116\114\105\110\103\32\50\59\32\114\101\116\117\114\110\32\42","\120\61"))
344+check3("\37\46",T.testC("\108\111\97\100\102\105\108\101\32\50\59\32\114\101\116\117\114\110\32\42","\46"))
345+check3("\120\120\120\120",T.testC("\108\111\97\100\102\105\108\101\32\50\59\32\114\101\116\117\114\110\32\42","\120\120\120\120"))
402346local function checkerrnopro
403347(code,msg)
404−local th = coroutine.create(()
348+local th = coroutine.create(function ()
405349
406350end)
407351local stt,err = pcall(T.testC,th,code)
408352assert(not stt and string.find(err,msg))
409353end
410354if not _soft then
411−collectgarbage("stop")
412−checkerrnopro("pushnum 3; call 0 0","attempt to call")
413−print("testing stack overflow in unprotected thread")
355+collectgarbage("\115\116\111\112")
356+checkerrnopro("\112\117\115\104\110\117\109\32\51\59\32\99\97\108\108\32\48\32\48","\97\116\116\101\109\112\116\32\116\111\32\99\97\108\108")
357+print("\116\101\115\116\105\110\103\32\115\116\97\99\107\32\111\118\101\114\102\108\111\119\32\105\110\32\117\110\112\114\111\116\101\99\116\101\100\32\116\104\114\101\97\100")
414358function F()
415359F()
416360end
417−checkerrnopro("getglobal 'F'; call 0 0;","stack overflow")
361+checkerrnopro("\103\101\116\103\108\111\98\97\108\32\39\70\39\59\32\99\97\108\108\32\48\32\48\59","\115\116\97\99\107\32\111\118\101\114\102\108\111\119")
418362F=nil
419−collectgarbage("restart")
363+collectgarbage("\114\101\115\116\97\114\116")
420364end
421−print("+")
365+print("\43")
366+do
422367local a = {}
423−local a1 = T.testC("rawsetp 2 1; return 1",a,20)
368+local a1 = T.testC("\114\97\119\115\101\116\112\32\50\32\49\59\32\114\101\116\117\114\110\32\49",a,20)
424369assert(a == a1)
425370assert(a[T.pushuserdata(1)] == 20)
426−local a1,res = T.testC("rawgetp -1 1; return 2",a)
371+local a1,res = T.testC("\114\97\119\103\101\116\112\32\45\49\32\49\59\32\114\101\116\117\114\110\32\50",a)
427372assert(a == a1 and res == 20)
373+end
374+do
428375local a = {}
429376a[a]=10
430−local prog = "gettable -1; return *"
377+local prog = "\103\101\116\116\97\98\108\101\32\45\49\59\32\114\101\116\117\114\110\32\42"
431378local res = {T.testC(prog,a)}
432379assert(# res == 2 and res[1] == prog and res[2] == 10)
433−local prog = "settable -2; return *"
380+local prog = "\115\101\116\116\97\98\108\101\32\45\50\59\32\114\101\116\117\114\110\32\42"
434381local res = {T.testC(prog,a,20)}
435382assert(a[a] == 20)
436383assert(# res == 1 and res[1] == prog)
437384a[a]=10
438−local prog = "rawget -1; return *"
385+local prog = "\114\97\119\103\101\116\32\45\49\59\32\114\101\116\117\114\110\32\42"
439386local res = {T.testC(prog,a)}
440387assert(# res == 2 and res[1] == prog and res[2] == 10)
441−local prog = "rawset -2; return *"
388+local prog = "\114\97\119\115\101\116\32\45\50\59\32\114\101\116\117\114\110\32\42"
442389local res = {T.testC(prog,a,20)}
443390assert(a[a] == 20)
444391assert(# res == 1 and res[1] == prog)
445−local prog = "rawset -1; return *"
392+local prog = "\114\97\119\115\101\116\32\45\49\59\32\114\101\116\117\114\110\32\42"
446393local res = {T.testC(prog,30,a)}
447394assert(a[30] == a)
448395assert(# res == 1 and res[1] == prog)
449−local prog = "settable -1; return *"
396+local prog = "\115\101\116\116\97\98\108\101\32\45\49\59\32\114\101\116\117\114\110\32\42"
450397local res = {T.testC(prog,40,a)}
451398assert(a[40] == a)
452399assert(# res == 1 and res[1] == prog)
453−local prog = "rawseti -1 100; return *"
400+local prog = "\114\97\119\115\101\116\105\32\45\49\32\49\48\48\59\32\114\101\116\117\114\110\32\42"
454401local res = {T.testC(prog,a)}
455402assert(a[100] == a)
456403assert(# res == 1 and res[1] == prog)
457−local prog = "seti -1 200; return *"
404+local prog = "\115\101\116\105\32\45\49\32\50\48\48\59\32\114\101\116\117\114\110\32\42"
458405local res = {T.testC(prog,a)}
459406assert(a[200] == a)
460407assert(# res == 1 and res[1] == prog)
461−a={["x"] = 0,["y"] = 12}
462−x,y=T.testC("gettable 2; pushvalue 4; gettable 2; return 2",a,3,"y",4,"x")
408+end
409+a={["\120"] = 0,["\121"] = 12}
410+x,y=T.testC("\103\101\116\116\97\98\108\101\32\50\59\32\112\117\115\104\118\97\108\117\101\32\52\59\32\103\101\116\116\97\98\108\101\32\50\59\32\114\101\116\117\114\110\32\50",a,3,"\121",4,"\120")
463411assert(x == 0 and y == 12)
464−T.testC("settable -5",a,3,4,"x",15)
412+T.testC("\115\101\116\116\97\98\108\101\32\45\53",a,3,4,"\120",15)
465413assert(a.x == 15)
466414a[a]=print
467−x=T.testC("gettable 2; return 1",a)
415+x=T.testC("\103\101\116\116\97\98\108\101\32\50\59\32\114\101\116\117\114\110\32\49",a)
468416assert(x == print)
469−T.testC("settable 2",a,"x")
470−assert(a[a] == "x")
471−b=setmetatable({["p"] = a},{})
472−getmetatable(b).__index=(t,i)
417+T.testC("\115\101\116\116\97\98\108\101\32\50",a,"\120")
418+assert(a[a] == "\120")
419+b=setmetatable({["\112"] = a},{})
420+getmetatable(b).__index=function (t,i)
473421return t.p[i]
474422end
475−local k,x = T.testC("gettable 3, return 2",4,b,20,35,"x")
423+local k,x = T.testC("\103\101\116\116\97\98\108\101\32\51\44\32\114\101\116\117\114\110\32\50",4,b,20,35,"\120")
476424assert(x == 15 and k == 35)
477−k=T.testC("getfield 2 y, return 1",b)
425+k=T.testC("\103\101\116\102\105\101\108\100\32\50\32\121\44\32\114\101\116\117\114\110\32\49",b)
478426assert(k == 12)
479−getmetatable(b).__index=(t,i)
427+getmetatable(b).__index=function (t,i)
480428return a[i]
481429end
482−getmetatable(b).__newindex=(t,i,v)
430+getmetatable(b).__newindex=function (t,i,v)
483431a[i]=v
484432end
485−y=T.testC("insert 2; gettable -5; return 1",2,3,4,"y",b)
433+y=T.testC("\105\110\115\101\114\116\32\50\59\32\103\101\116\116\97\98\108\101\32\45\53\59\32\114\101\116\117\114\110\32\49",2,3,4,"\121",b)
486434assert(y == 12)
487−k=T.testC("settable -5, return 1",b,3,4,"x",16)
435+k=T.testC("\115\101\116\116\97\98\108\101\32\45\53\44\32\114\101\116\117\114\110\32\49",b,3,4,"\120",16)
488436assert(a.x == 16 and k == 4)
489−a[b]="xuxu"
490−y=T.testC("gettable 2, return 1",b)
491−assert(y == "xuxu")
492−T.testC("settable 2",b,19)
437+a[b]="\120\117\120\117"
438+y=T.testC("\103\101\116\116\97\98\108\101\32\50\44\32\114\101\116\117\114\110\32\49",b)
439+assert(y == "\120\117\120\117")
440+T.testC("\115\101\116\116\97\98\108\101\32\50",b,19)
493441assert(a[b] == 19)
494−local t = {["_012345678901234567890123456789012345678901234567890123456789"] = 32}
495−local a = T.testC(" getfield 2 _012345678901234567890123456789012345678901234567890123456789
496− return 1
497− ",t)
442+do
443+local t = {["\95\48\49\50\51\52\53\54\55\56\57\48\49\50\51\52\53\54\55\56\57\48\49\50\51\52\53\54\55\56\57\48\49\50\51\52\53\54\55\56\57\48\49\50\51\52\53\54\55\56\57\48\49\50\51\52\53\54\55\56\57"] = 32}
444+local a = T.testC("\32\32\32\32\103\101\116\102\105\101\108\100\32\50\32\95\48\49\50\51\52\53\54\55\56\57\48\49\50\51\52\53\54\55\56\57\48\49\50\51\52\53\54\55\56\57\48\49\50\51\52\53\54\55\56\57\48\49\50\51\52\53\54\55\56\57\48\49\50\51\52\53\54\55\56\57\10\32\32\32\32\114\101\116\117\114\110\32\49\10\32\32",t)
498445assert(a == 32)
499−local a = T.testC(" pushnum 33
500− setglobal _012345678901234567890123456789012345678901234567890123456789
501− ")
446+local a = T.testC("\32\32\32\32\112\117\115\104\110\117\109\32\51\51\10\32\32\32\32\115\101\116\103\108\111\98\97\108\32\95\48\49\50\51\52\53\54\55\56\57\48\49\50\51\52\53\54\55\56\57\48\49\50\51\52\53\54\55\56\57\48\49\50\51\52\53\54\55\56\57\48\49\50\51\52\53\54\55\56\57\48\49\50\51\52\53\54\55\56\57\10\32\32")
502447assert(_012345678901234567890123456789012345678901234567890123456789 == 33)
503448_012345678901234567890123456789012345678901234567890123456789=nil
449+end
504450a={}
505−t=pack(T.testC("next; return *",a,nil))
506−tcheck(t,{["n"] = 1,a})
507−a={["a"] = 3}
508−t=pack(T.testC("next; return *",a,nil))
509−tcheck(t,{["n"] = 3,a,"a",3})
510−t=pack(T.testC("next; pop 1; next; return *",a,nil))
511−tcheck(t,{["n"] = 1,a})
512−local A = T.testC(" pushnum 10; pushnum 20; pushcclosure 2; return 1")
513−t,b,c=A("pushvalue U0; pushvalue U1; pushvalue U2; return 3")
514−assert(b == 10 and c == 20 and type(t) == "table")
515−a,b=A("tostring U3; tonumber U4; return 2")
451+t=pack(T.testC("\110\101\120\116\59\32\114\101\116\117\114\110\32\42",a,nil))
452+tcheck(t,{["\110"] = 1,a})
453+a={["\97"] = 3}
454+t=pack(T.testC("\110\101\120\116\59\32\114\101\116\117\114\110\32\42",a,nil))
455+tcheck(t,{["\110"] = 3,a,"\97",3})
456+t=pack(T.testC("\110\101\120\116\59\32\112\111\112\32\49\59\32\110\101\120\116\59\32\114\101\116\117\114\110\32\42",a,nil))
457+tcheck(t,{["\110"] = 1,a})
458+do
459+local A = T.testC("\32\112\117\115\104\110\117\109\32\49\48\59\32\112\117\115\104\110\117\109\32\50\48\59\32\112\117\115\104\99\99\108\111\115\117\114\101\32\50\59\32\114\101\116\117\114\110\32\49")
460+t,b,c=A("\112\117\115\104\118\97\108\117\101\32\85\48\59\32\112\117\115\104\118\97\108\117\101\32\85\49\59\32\112\117\115\104\118\97\108\117\101\32\85\50\59\32\114\101\116\117\114\110\32\51")
461+assert(b == 10 and c == 20 and type(t) == "\116\97\98\108\101")
462+a,b=A("\116\111\115\116\114\105\110\103\32\85\51\59\32\116\111\110\117\109\98\101\114\32\85\52\59\32\114\101\116\117\114\110\32\50")
516463assert(a == nil and b == 0)
517−A("pushnum 100; pushnum 200; replace U2; replace U1")
518−b,c=A("pushvalue U1; pushvalue U2; return 2")
464+A("\112\117\115\104\110\117\109\32\49\48\48\59\32\112\117\115\104\110\117\109\32\50\48\48\59\32\114\101\112\108\97\99\101\32\85\50\59\32\114\101\112\108\97\99\101\32\85\49")
465+b,c=A("\112\117\115\104\118\97\108\117\101\32\85\49\59\32\112\117\115\104\118\97\108\117\101\32\85\50\59\32\114\101\116\117\114\110\32\50")
519466assert(b == 100 and c == 200)
520−A("replace U2; replace U1",{["x"] = 1},{["x"] = 2})
521−b,c=A("pushvalue U1; pushvalue U2; return 2")
467+A("\114\101\112\108\97\99\101\32\85\50\59\32\114\101\112\108\97\99\101\32\85\49",{["\120"] = 1},{["\120"] = 2})
468+b,c=A("\112\117\115\104\118\97\108\117\101\32\85\49\59\32\112\117\115\104\118\97\108\117\101\32\85\50\59\32\114\101\116\117\114\110\32\50")
522469assert(b.x == 1 and c.x == 2)
523470T.checkmemory()
524−assert(T.testC("isnull U1; return 1") == true)
525−assert(T.testC("isnull U100; return 1") == true)
526−assert(T.testC("pushvalue U1; return 1") == nil)
527−local f = T.testC(" pushnum 10; pushnum 20; pushcclosure 2; return 1")
471+end
472+assert(T.testC("\105\115\110\117\108\108\32\85\49\59\32\114\101\116\117\114\110\32\49") == true)
473+assert(T.testC("\105\115\110\117\108\108\32\85\49\48\48\59\32\114\101\116\117\114\110\32\49") == true)
474+assert(T.testC("\112\117\115\104\118\97\108\117\101\32\85\49\59\32\114\101\116\117\114\110\32\49") == nil)
475+local f = T.testC("\32\112\117\115\104\110\117\109\32\49\48\59\32\112\117\115\104\110\117\109\32\50\48\59\32\112\117\115\104\99\99\108\111\115\117\114\101\32\50\59\32\114\101\116\117\114\110\32\49")
528476assert(T.upvalue(f,1) == 10 and T.upvalue(f,2) == 20 and T.upvalue(f,3) == nil)
529−T.upvalue(f,2,"xuxu")
530−assert(T.upvalue(f,2) == "xuxu")
531−local A = "checkstack 300 msg;" .. string.rep("pushnum 10;",255) .. "pushcclosure 255; return 1"
477+T.upvalue(f,2,"\120\117\120\117")
478+assert(T.upvalue(f,2) == "\120\117\120\117")
479+do
480+local A = "\99\104\101\99\107\115\116\97\99\107\32\51\48\48\32\109\115\103\59" .. string.rep("\112\117\115\104\110\117\109\32\49\48\59",255) .. "\112\117\115\104\99\99\108\111\115\117\114\101\32\50\53\53\59\32\114\101\116\117\114\110\32\49"
532481A=T.testC(A)
533482for i = 1, 255
534483do
535−assert(A(("pushvalue U%d; return 1"):format(i)) == 10)
484+assert(A(("\112\117\115\104\118\97\108\117\101\32\85\37\100\59\32\114\101\116\117\114\110\32\49"):format(i)) == 10)
485+end
486+assert(A("\105\115\110\117\108\108\32\85\50\53\54\59\32\114\101\116\117\114\110\32\49"))
487+assert(not A("\105\115\110\105\108\32\85\50\53\54\59\32\114\101\116\117\114\110\32\49"))
536488end
537−assert(A("isnull U256; return 1"))
538−assert(not A("isnil U256; return 1"))
539−checkerr("got number",debug.setuservalue,3,{})
540−checkerr("got nil",debug.setuservalue,nil,{})
541−checkerr("got light userdata",debug.setuservalue,T.pushuserdata(1),{})
489+checkerr("\103\111\116\32\110\117\109\98\101\114",debug.setuservalue,3,{})
490+checkerr("\103\111\116\32\110\105\108",debug.setuservalue,nil,{})
491+checkerr("\103\111\116\32\108\105\103\104\116\32\117\115\101\114\100\97\116\97",debug.setuservalue,T.pushuserdata(1),{})
542492local b = T.newuserdata(0,10)
543493for i = 1, 10
544494do
545495local v,p = debug.getuservalue(b,i)
546496assert(v == nil and p)
547497end
498+do
548499local v,p = debug.getuservalue(b,- 2)
549500assert(v == nil and not p)
550501local v,p = debug.getuservalue(b,11)
551502assert(v == nil and not p)
552−local t = {true,false,4.56,print,{},b,"XYZ"}
503+end
504+local t = {true,false,4.56,print,{},b,"\88\89\90"}
553505for k,v in ipairs(t)
554506do
555507debug.setuservalue(b,v,k)
@@ -560,7 +512,7 @@ local v1,p = debug.getuservalue(b,k)
560512assert(v1 == v and p)
561513end
562514assert(not debug.getuservalue(4))
563−debug.setuservalue(b,()
515+debug.setuservalue(b,function ()
564516return 10
565517end,10)
566518collectgarbage()
@@ -568,21 +520,23 @@ assert(debug.getuservalue(b,10)() == 10)
568520debug.setuservalue(b,134)
569521collectgarbage()
570522assert(debug.getuservalue(b) == 134)
571−local oldmode = collectgarbage("incremental")
572−T.gcstate("atomic")
573−assert(T.gccolor(b) == "black")
574−debug.setuservalue(b,{["x"] = 100})
575−T.gcstate("pause")
523+do
524+local oldmode = collectgarbage("\105\110\99\114\101\109\101\110\116\97\108")
525+T.gcstate("\97\116\111\109\105\99")
526+assert(T.gccolor(b) == "\98\108\97\99\107")
527+debug.setuservalue(b,{["\120"] = 100})
528+T.gcstate("\112\97\117\115\101")
576529assert(debug.getuservalue(b).x == 100)
577530collectgarbage(oldmode)
578−for i = 1, 1e3
531+end
532+for i = 1, 1000
579533do
580534local bb = T.newuserdata(0,1)
581535debug.setuservalue(bb,b)
582536b=bb
583537end
584538collectgarbage()
585−for i = 1, 1e3
539+for i = 1, 1000
586540do
587541b=debug.getuservalue(b)
588542end
@@ -607,9 +561,9 @@ T.unref(Arr[i])
607561end
608562local function printlocks
609563()
610−local f = T.makeCfunc("gettable R; return 1")
611−local n = f("n")
612−print("n",n)
564+local f = T.makeCfunc("\103\101\116\116\97\98\108\101\32\82\59\32\114\101\116\117\114\110\32\49")
565+local n = f("\110")
566+print("\110",n)
613567for i = 0, n
614568do
615569print(i,f(i))
@@ -623,28 +577,28 @@ for i = 1, Lim, 2
623577do
624578T.unref(Arr[i])
625579end
626−assert(type(T.getref(Arr[2])) == "table")
580+assert(type(T.getref(Arr[2])) == "\116\97\98\108\101")
627581assert(T.getref(- 1) == nil)
628582a=T.ref({})
629583collectgarbage()
630−assert(type(T.getref(a)) == "table")
584+assert(type(T.getref(a)) == "\116\97\98\108\101")
631585local tt = {}
632−local cl = {["n"] = 0}
586+local cl = {["\110"] = 0}
633587A=nil
634588;
635589B=nil
636−local F =
637−F=(x)
590+local F
591+F=function (x)
638592local udval = T.udataval(x)
639593table.insert(cl,udval)
640594local d = T.newuserdata(100)
641595d=nil
642596assert(debug.getmetatable(x).__gc == F)
643−assert(load("table.insert({}, {})"))()
597+assert(load("\116\97\98\108\101\46\105\110\115\101\114\116\40\123\125\44\32\123\125\41"))()
644598assert(not collectgarbage())
645599local dummy = {}
646600if A ~= nil then
647−assert(type(A) == "userdata")
601+assert(type(A) == "\117\115\101\114\100\97\116\97")
648602assert(T.udataval(A) == B)
649603debug.getmetatable(A)
650604end
@@ -653,45 +607,47 @@ B=udval
653607return 1,2,3
654608end
655609tt.__gc=F
610+do
656611collectgarbage()
657612;
658613collectgarbage()
659614;
660−local x = collectgarbage("count")
615+local x = collectgarbage("\99\111\117\110\116")
661616;
662617local a = T.newuserdata(5001)
663−assert(T.testC("objsize 2; return 1",a) == 5001)
664−assert(collectgarbage("count") >= x + 4)
618+assert(T.testC("\111\98\106\115\105\122\101\32\50\59\32\114\101\116\117\114\110\32\49",a) == 5001)
619+assert(collectgarbage("\99\111\117\110\116") >= x + 4)
665620a=nil
666621collectgarbage()
667622;
668−assert(collectgarbage("count") <= x + 1)
669−x=collectgarbage("count")
670−collectgarbage("stop")
671−for i = 1, 1e3
623+assert(collectgarbage("\99\111\117\110\116") <= x + 1)
624+x=collectgarbage("\99\111\117\110\116")
625+collectgarbage("\115\116\111\112")
626+for i = 1, 1000
672627do
673628T.newuserdata(0)
674629end
675−assert(collectgarbage("count") > x + 10)
630+assert(collectgarbage("\99\111\117\110\116") > x + 10)
676631collectgarbage()
677−assert(collectgarbage("count") <= x + 1)
632+assert(collectgarbage("\99\111\117\110\116") <= x + 1)
678633collectgarbage()
679−x=collectgarbage("count")
680−collectgarbage("stop")
681−a={["__gc"] = ()
634+x=collectgarbage("\99\111\117\110\116")
635+collectgarbage("\115\116\111\112")
636+a={["\95\95\103\99"] = function ()
682637
683638end}
684−for i = 1, 1e3
639+for i = 1, 1000
685640do
686641debug.setmetatable(T.newuserdata(0),a)
687642end
688−assert(collectgarbage("count") >= x + 10)
643+assert(collectgarbage("\99\111\117\110\116") >= x + 10)
689644collectgarbage()
690−assert(collectgarbage("count") >= x + 10)
645+assert(collectgarbage("\99\111\117\110\116") >= x + 10)
691646collectgarbage()
692−assert(collectgarbage("count") <= x + 1)
693−collectgarbage("restart")
694−collectgarbage("stop")
647+assert(collectgarbage("\99\111\117\110\116") <= x + 1)
648+collectgarbage("\114\101\115\116\97\114\116")
649+end
650+collectgarbage("\115\116\111\112")
695651a=T.newuserdata(0)
696652;
697653debug.setmetatable(a,tt)
@@ -709,8 +665,8 @@ debug.setmetatable(c,tt)
709665local nc = T.udataval(c)
710666x=T.newuserdata(4)
711667y=T.newuserdata(0)
712−checkerr("FILE%* expected, got userdata",io.input,a)
713−checkerr("FILE%* expected, got userdata",io.input,x)
668+checkerr("\70\73\76\69\37\42\32\101\120\112\101\99\116\101\100\44\32\103\111\116\32\117\115\101\114\100\97\116\97",io.input,a)
669+checkerr("\70\73\76\69\37\42\32\101\120\112\101\99\116\101\100\44\32\103\111\116\32\117\115\101\114\100\97\116\97",io.input,x)
714670assert(debug.getmetatable(x) == nil and debug.getmetatable(y) == nil)
715671local d = T.ref(a)
716672;
@@ -732,7 +688,7 @@ T.unref(f)
732688collectgarbage()
733689assert(# cl == 1 and cl[1] == nc)
734690x=T.getref(d)
735−assert(type(x) == "userdata" and debug.getmetatable(x) == tt)
691+assert(type(x) == "\117\115\101\114\100\97\116\97" and debug.getmetatable(x) == tt)
736692x=nil
737693tt.b=b
738694tt=nil
@@ -741,17 +697,17 @@ b=nil
741697T.unref(d)
742698;
743699local n5 = T.newuserdata(0)
744−debug.setmetatable(n5,{["__gc"] = F})
700+debug.setmetatable(n5,{["\95\95\103\99"] = F})
745701n5=T.udataval(n5)
746702collectgarbage()
747703assert(# cl == 4)
748704assert(cl[2] == n5 and cl[3] == nb and cl[4] == na)
749−collectgarbage("restart")
705+collectgarbage("\114\101\115\116\97\114\116")
750706a,na={},{}
751707for i = 30, 1, - 1
752708do
753709a[i]=T.newuserdata(0)
754−debug.setmetatable(a[i],{["__gc"] = F})
710+debug.setmetatable(a[i],{["\95\95\103\99"] = F})
755711na[i]=T.udataval(a[i])
756712end
757713cl={}
@@ -770,8 +726,8 @@ T.unref(Arr[i])
770726end
771727x=T.newuserdata(41)
772728;
773−debug.setmetatable(x,{["__gc"] = F})
774−assert(T.testC("objsize 2; return 1",x) == 41)
729+debug.setmetatable(x,{["\95\95\103\99"] = F})
730+assert(T.testC("\111\98\106\115\105\122\101\32\50\59\32\114\101\116\117\114\110\32\49",x) == 41)
775731cl={}
776732a={[x] = 1}
777733x=T.udataval(x)
@@ -783,14 +739,15 @@ a[n]=undef
783739end
784740collectgarbage()
785741assert(# cl == 1 and cl[1] == x)
786−assert(T.testC("compare EQ 2 4; return 1",print,1,print,20))
787−assert(T.testC("compare EQ 3 2; return 1","alo","alo"))
788−assert(T.testC("compare EQ 2 3; return 1",nil,nil))
789−assert(not T.testC("compare EQ 2 3; return 1",{},{}))
790−assert(not T.testC("compare EQ 2 3; return 1"))
791−assert(not T.testC("compare EQ 2 3; return 1",3))
742+assert(T.testC("\99\111\109\112\97\114\101\32\69\81\32\50\32\52\59\32\114\101\116\117\114\110\32\49",print,1,print,20))
743+assert(T.testC("\99\111\109\112\97\114\101\32\69\81\32\51\32\50\59\32\114\101\116\117\114\110\32\49","\97\108\111","\97\108\111"))
744+assert(T.testC("\99\111\109\112\97\114\101\32\69\81\32\50\32\51\59\32\114\101\116\117\114\110\32\49",nil,nil))
745+assert(not T.testC("\99\111\109\112\97\114\101\32\69\81\32\50\32\51\59\32\114\101\116\117\114\110\32\49",{},{}))
746+assert(not T.testC("\99\111\109\112\97\114\101\32\69\81\32\50\32\51\59\32\114\101\116\117\114\110\32\49"))
747+assert(not T.testC("\99\111\109\112\97\114\101\32\69\81\32\50\32\51\59\32\114\101\116\117\114\110\32\49",3))
748+do
792749local map = {}
793−local t = {["__eq"] = (a,b)
750+local t = {["\95\95\101\113"] = function (a,b)
794751return map[a] == map[b]
795752end}
796753local function f
@@ -802,18 +759,14 @@ return u
802759end
803760assert(f(10) == f(10))
804761assert(f(10) ~= f(11))
805−assert(T.testC("compare EQ 2 3; return 1",f(10),f(10)))
806−assert(not T.testC("compare EQ 2 3; return 1",f(10),f(20)))
762+assert(T.testC("\99\111\109\112\97\114\101\32\69\81\32\50\32\51\59\32\114\101\116\117\114\110\32\49",f(10),f(10)))
763+assert(not T.testC("\99\111\109\112\97\114\101\32\69\81\32\50\32\51\59\32\114\101\116\117\114\110\32\49",f(10),f(20)))
807764t.__eq=nil
808765assert(f(10) ~= f(10))
809−print("+")
766+end
767+print("\43")
810768_G.TT={}
811−T.sethook(" # set a line hook after 3 count hooks
812− sethook 4 0 '
813− getglobal TT;
814− pushvalue -3; append -2
815− pushvalue -2; append -2
816− '","c",3)
769+T.sethook("\32\32\35\32\115\101\116\32\97\32\108\105\110\101\32\104\111\111\107\32\97\102\116\101\114\32\51\32\99\111\117\110\116\32\104\111\111\107\115\10\32\32\115\101\116\104\111\111\107\32\52\32\48\32\39\10\32\32\32\32\103\101\116\103\108\111\98\97\108\32\84\84\59\10\32\32\32\32\112\117\115\104\118\97\108\117\101\32\45\51\59\32\97\112\112\101\110\100\32\45\50\10\32\32\32\32\112\117\115\104\118\97\108\117\101\32\45\50\59\32\97\112\112\101\110\100\32\45\50\10\32\32\39","\99",3)
817770local a = 1
818771a=1
819772a=1
@@ -821,14 +774,15 @@ a=1
821774a=1
822775debug.sethook()
823776local t = _G.TT
824−assert(t[1] == "line")
777+assert(t[1] == "\108\105\110\101")
825778local line = t[2]
826−assert(t[3] == "line" and t[4] == line + 1)
827−assert(t[5] == "line" and t[6] == line + 2)
779+assert(t[3] == "\108\105\110\101" and t[4] == line + 1)
780+assert(t[5] == "\108\105\110\101" and t[6] == line + 2)
828781assert(t[7] == nil)
829782_G.TT=nil
830−warn("@off")
831−collectgarbage("stop")
783+do
784+warn("\64\111\102\102")
785+collectgarbage("\115\116\111\112")
832786local a = {}
833787for i = 1, 20
834788do
@@ -836,23 +790,25 @@ a[i]=T.newuserdata(i)
836790end
837791for i = 1, 20, 2
838792do
839−debug.setmetatable(a[i],{["__gc"] = (x)
840−error("@expected error in gc")
793+debug.setmetatable(a[i],{["\95\95\103\99"] = function (x)
794+error("\64\101\120\112\101\99\116\101\100\32\101\114\114\111\114\32\105\110\32\103\99")
841795end})
842796end
843797for i = 2, 20, 2
844798do
845−debug.setmetatable(a[i],{["__gc"] = (x)
846−load("A=A+1")()
799+debug.setmetatable(a[i],{["\95\95\103\99"] = function (x)
800+load("\65\61\65\43\49")()
847801end})
848802end
849803a=nil
850804_G.A=0
851805collectgarbage()
852806assert(A == 10)
853−collectgarbage("restart")
854−warn("@on")
807+collectgarbage("\114\101\115\116\97\114\116")
808+warn("\64\111\110")
809+end
855810_G.A=nil
811+do
856812local a = {}
857813;
858814local lim = 30
@@ -876,47 +832,40 @@ for i = 0, lim
876832do
877833a[T.pushuserdata(i)]=i
878834end
879−assert(type(tostring(a[1])) == "string")
835+assert(type(tostring(a[1])) == "\115\116\114\105\110\103")
836+end
880837T.closestate(T.newstate())
881838;
882839L1=T.newstate()
883840assert(L1)
884−assert(T.doremote(L1,"X='a'; return 'a'") == "a")
885−assert(# pack(T.doremote(L1,"function f () return 'alo', 3 end; f()")) == 0)
886−a,b=T.doremote(L1,"return f()")
887−assert(a == "alo" and b == "3")
888−T.doremote(L1,"_ERRORMESSAGE = nil")
889−a,b,c=T.doremote(L1,"return sin(1)")
841+assert(T.doremote(L1,"\88\61\39\97\39\59\32\114\101\116\117\114\110\32\39\97\39") == "\97")
842+assert(# pack(T.doremote(L1,"\102\117\110\99\116\105\111\110\32\102\32\40\41\32\114\101\116\117\114\110\32\39\97\108\111\39\44\32\51\32\101\110\100\59\32\102\40\41")) == 0)
843+a,b=T.doremote(L1,"\114\101\116\117\114\110\32\102\40\41")
844+assert(a == "\97\108\111" and b == "\51")
845+T.doremote(L1,"\95\69\82\82\79\82\77\69\83\83\65\71\69\32\61\32\110\105\108")
846+a,b,c=T.doremote(L1,"\114\101\116\117\114\110\32\115\105\110\40\49\41")
890847assert(a == nil and c == 2)
891−a,b,c=T.doremote(L1,"return a+")
892−assert(a == nil and c == 3 and type(b) == "string")
848+a,b,c=T.doremote(L1,"\114\101\116\117\114\110\32\97\43")
849+assert(a == nil and c == 3 and type(b) == "\115\116\114\105\110\103")
893850T.loadlib(L1)
894−a,b,c=T.doremote(L1," string = require'string'
895− a = require'_G'; assert(a == _G and require("_G") == a)
896− io = require'io'; assert(type(io.read) == "function")
897− assert(require("io") == io)
898− a = require'table'; assert(type(a.insert) == "function")
899− a = require'debug'; assert(type(a.getlocal) == "function")
900− a = require'math'; assert(type(a.sin) == "function")
901− return string.sub('okinama', 1, 2)
902−")
903−assert(a == "ok")
851+a,b,c=T.doremote(L1,"\32\32\115\116\114\105\110\103\32\61\32\114\101\113\117\105\114\101\39\115\116\114\105\110\103\39\10\32\32\97\32\61\32\114\101\113\117\105\114\101\39\95\71\39\59\32\97\115\115\101\114\116\40\97\32\61\61\32\95\71\32\97\110\100\32\114\101\113\117\105\114\101\40\34\95\71\34\41\32\61\61\32\97\41\10\32\32\105\111\32\61\32\114\101\113\117\105\114\101\39\105\111\39\59\32\97\115\115\101\114\116\40\116\121\112\101\40\105\111\46\114\101\97\100\41\32\61\61\32\34\102\117\110\99\116\105\111\110\34\41\10\32\32\97\115\115\101\114\116\40\114\101\113\117\105\114\101\40\34\105\111\34\41\32\61\61\32\105\111\41\10\32\32\97\32\61\32\114\101\113\117\105\114\101\39\116\97\98\108\101\39\59\32\97\115\115\101\114\116\40\116\121\112\101\40\97\46\105\110\115\101\114\116\41\32\61\61\32\34\102\117\110\99\116\105\111\110\34\41\10\32\32\97\32\61\32\114\101\113\117\105\114\101\39\100\101\98\117\103\39\59\32\97\115\115\101\114\116\40\116\121\112\101\40\97\46\103\101\116\108\111\99\97\108\41\32\61\61\32\34\102\117\110\99\116\105\111\110\34\41\10\32\32\97\32\61\32\114\101\113\117\105\114\101\39\109\97\116\104\39\59\32\97\115\115\101\114\116\40\116\121\112\101\40\97\46\115\105\110\41\32\61\61\32\34\102\117\110\99\116\105\111\110\34\41\10\32\32\114\101\116\117\114\110\32\115\116\114\105\110\103\46\115\117\98\40\39\111\107\105\110\97\109\97\39\44\32\49\44\32\50\41\10")
852+assert(a == "\111\107")
904853T.closestate(L1)
905854;
906855L1=T.newstate()
907856T.loadlib(L1)
908−T.doremote(L1,"a = {}")
909−T.testC(L1,"getglobal "a"; pushstring "x"; pushint 1;
910− settable -3")
911−assert(T.doremote(L1,"return a.x") == "1")
857+T.doremote(L1,"\97\32\61\32\123\125")
858+T.testC(L1,"\103\101\116\103\108\111\98\97\108\32\34\97\34\59\32\112\117\115\104\115\116\114\105\110\103\32\34\120\34\59\32\112\117\115\104\105\110\116\32\49\59\10\32\32\32\32\32\32\32\32\32\32\32\32\32\115\101\116\116\97\98\108\101\32\45\51")
859+assert(T.doremote(L1,"\114\101\116\117\114\110\32\97\46\120") == "\49")
912860T.closestate(L1)
913861L1=nil
914−print("+")
915−print("testing to-be-closed variables")
862+print("\43")
863+print("\116\101\115\116\105\110\103\32\116\111\45\98\101\45\99\108\111\115\101\100\32\118\97\114\105\97\98\108\101\115")
864+do
916865local openresource = {}
917866local function newresource
918867()
919−local x = setmetatable({10},{["__close"] = (y)
868+local x = setmetatable({10},{["\95\95\99\108\111\115\101"] = function (y)
920869assert(openresource[# openresource] == y)
921870openresource[# openresource]=nil
922871y[1]=y[1] + 1
@@ -924,85 +873,33 @@ end})
924873openresource[# openresource + 1]=x
925874return x
926875end
927−local a,b = T.testC(" call 0 1 # create resource
928− pushnil
929− toclose -2 # mark call result to be closed
930− toclose -1 # mark nil to be closed (will be ignored)
931− return 2
932− ",newresource)
876+local a,b = T.testC("\32\32\32\32\99\97\108\108\32\48\32\49\32\32\32\35\32\99\114\101\97\116\101\32\114\101\115\111\117\114\99\101\10\32\32\32\32\112\117\115\104\110\105\108\10\32\32\32\32\116\111\99\108\111\115\101\32\45\50\32\32\35\32\109\97\114\107\32\99\97\108\108\32\114\101\115\117\108\116\32\116\111\32\98\101\32\99\108\111\115\101\100\10\32\32\32\32\116\111\99\108\111\115\101\32\45\49\32\32\35\32\109\97\114\107\32\110\105\108\32\116\111\32\98\101\32\99\108\111\115\101\100\32\40\119\105\108\108\32\98\101\32\105\103\110\111\114\101\100\41\10\32\32\32\32\114\101\116\117\114\110\32\50\10\32\32",newresource)
933877assert(a[1] == 11 and b == nil)
934878assert(# openresource == 0)
935−local a = {T.testC(" call 0 1 # create resource
936− toclose 2 # mark it to be closed
937− return 2
938− ",newresource)}
939−assert(type(a[1]) == "string" and a[2][1] == 11)
879+local a = {T.testC("\32\32\32\32\99\97\108\108\32\48\32\49\32\32\32\35\32\99\114\101\97\116\101\32\114\101\115\111\117\114\99\101\10\32\32\32\32\116\111\99\108\111\115\101\32\50\32\35\32\109\97\114\107\32\105\116\32\116\111\32\98\101\32\99\108\111\115\101\100\10\32\32\32\32\114\101\116\117\114\110\32\50\10\32\32",newresource)}
880+assert(type(a[1]) == "\115\116\114\105\110\103" and a[2][1] == 11)
940881assert(# openresource == 0)
941−local a,b = pcall(T.makeCfunc(" call 0 1 # create resource
942− toclose -1 # mark it to be closed
943− error # resource is the error object
944− "),newresource)
882+local a,b = pcall(T.makeCfunc("\32\32\32\32\99\97\108\108\32\48\32\49\32\32\32\35\32\99\114\101\97\116\101\32\114\101\115\111\117\114\99\101\10\32\32\32\32\116\111\99\108\111\115\101\32\45\49\32\35\32\109\97\114\107\32\105\116\32\116\111\32\98\101\32\99\108\111\115\101\100\10\32\32\32\32\101\114\114\111\114\32\32\32\32\32\32\32\35\32\114\101\115\111\117\114\99\101\32\105\115\32\116\104\101\32\101\114\114\111\114\32\111\98\106\101\99\116\10\32\32"),newresource)
945883assert(a == false and b[1] == 11)
946884assert(# openresource == 0)
947−local a,b = pcall(T.makeCfunc(" newtable # create non-closable object
948− toclose -1 # mark it to be closed (should raise an error)
949− abort # will not be executed
950− "))
951−assert(a == false and string.find(b,"non%-closable value"))
885+local a,b = pcall(T.makeCfunc("\32\32\32\32\110\101\119\116\97\98\108\101\32\32\32\35\32\99\114\101\97\116\101\32\110\111\110\45\99\108\111\115\97\98\108\101\32\111\98\106\101\99\116\10\32\32\32\32\116\111\99\108\111\115\101\32\45\49\32\35\32\109\97\114\107\32\105\116\32\116\111\32\98\101\32\99\108\111\115\101\100\32\40\115\104\111\117\108\100\32\114\97\105\115\101\32\97\110\32\101\114\114\111\114\41\10\32\32\32\32\97\98\111\114\116\32\32\35\32\119\105\108\108\32\110\111\116\32\98\101\32\101\120\101\99\117\116\101\100\10\32\32"))
886+assert(a == false and string.find(b,"\110\111\110\37\45\99\108\111\115\97\98\108\101\32\118\97\108\117\101"))
952887local function check
953888(n)
954889assert(# openresource == n)
955890end
956891_ENV.xxx=true
957−local a = T.testC(" pushvalue 2 # stack: S, NR, CH, NR
958− call 0 1 # create resource; stack: S, NR, CH, R
959− toclose -1 # mark it to be closed
960− pushvalue 2 # stack: S, NR, CH, R, NR
961− call 0 1 # create another resource; stack: S, NR, CH, R, R
962− toclose -1 # mark it to be closed
963− pushvalue 3 # stack: S, NR, CH, R, R, CH
964− pushint 2 # there should be two open resources
965− call 1 0 # stack: S, NR, CH, R, R
966− closeslot -1 # close second resource
967− pushvalue 3 # stack: S, NR, CH, R, R, CH
968− pushint 1 # there should be one open resource
969− call 1 0 # stack: S, NR, CH, R, R
970− closeslot 4
971− setglobal "xxx" # previous op. erased the slot
972− pop 1 # pop other resource from the stack
973− pushint *
974− return 1 # return stack size
975− ",newresource,check)
892+local a = T.testC("\32\32\32\32\112\117\115\104\118\97\108\117\101\32\50\32\32\35\32\115\116\97\99\107\58\32\83\44\32\78\82\44\32\67\72\44\32\78\82\10\32\32\32\32\99\97\108\108\32\48\32\49\32\32\32\35\32\99\114\101\97\116\101\32\114\101\115\111\117\114\99\101\59\32\115\116\97\99\107\58\32\83\44\32\78\82\44\32\67\72\44\32\82\10\32\32\32\32\116\111\99\108\111\115\101\32\45\49\32\35\32\109\97\114\107\32\105\116\32\116\111\32\98\101\32\99\108\111\115\101\100\10\32\32\32\32\112\117\115\104\118\97\108\117\101\32\50\32\32\35\32\32\115\116\97\99\107\58\32\83\44\32\78\82\44\32\67\72\44\32\82\44\32\78\82\10\32\32\32\32\99\97\108\108\32\48\32\49\32\32\32\35\32\99\114\101\97\116\101\32\97\110\111\116\104\101\114\32\114\101\115\111\117\114\99\101\59\32\115\116\97\99\107\58\32\83\44\32\78\82\44\32\67\72\44\32\82\44\32\82\10\32\32\32\32\116\111\99\108\111\115\101\32\45\49\32\35\32\109\97\114\107\32\105\116\32\116\111\32\98\101\32\99\108\111\115\101\100\10\32\32\32\32\112\117\115\104\118\97\108\117\101\32\51\32\32\35\32\115\116\97\99\107\58\32\83\44\32\78\82\44\32\67\72\44\32\82\44\32\82\44\32\67\72\10\32\32\32\32\112\117\115\104\105\110\116\32\50\32\32\32\35\32\116\104\101\114\101\32\115\104\111\117\108\100\32\98\101\32\116\119\111\32\111\112\101\110\32\114\101\115\111\117\114\99\101\115\10\32\32\32\32\99\97\108\108\32\49\32\48\32\32\35\32\32\115\116\97\99\107\58\32\83\44\32\78\82\44\32\67\72\44\32\82\44\32\82\10\32\32\32\32\99\108\111\115\101\115\108\111\116\32\45\49\32\32\32\35\32\99\108\111\115\101\32\115\101\99\111\110\100\32\114\101\115\111\117\114\99\101\10\32\32\32\32\112\117\115\104\118\97\108\117\101\32\51\32\32\35\32\115\116\97\99\107\58\32\83\44\32\78\82\44\32\67\72\44\32\82\44\32\82\44\32\67\72\10\32\32\32\32\112\117\115\104\105\110\116\32\49\32\32\32\35\32\116\104\101\114\101\32\115\104\111\117\108\100\32\98\101\32\111\110\101\32\111\112\101\110\32\114\101\115\111\117\114\99\101\10\32\32\32\32\99\97\108\108\32\49\32\48\32\32\35\32\115\116\97\99\107\58\32\83\44\32\78\82\44\32\67\72\44\32\82\44\32\82\10\32\32\32\32\99\108\111\115\101\115\108\111\116\32\52\10\32\32\32\32\115\101\116\103\108\111\98\97\108\32\34\120\120\120\34\32\32\35\32\112\114\101\118\105\111\117\115\32\111\112\46\32\101\114\97\115\101\100\32\116\104\101\32\115\108\111\116\10\32\32\32\32\112\111\112\32\49\32\32\32\32\32\32\32\35\32\112\111\112\32\111\116\104\101\114\32\114\101\115\111\117\114\99\101\32\102\114\111\109\32\116\104\101\32\115\116\97\99\107\10\32\32\32\32\112\117\115\104\105\110\116\32\42\10\32\32\32\32\114\101\116\117\114\110\32\49\32\32\32\32\35\32\114\101\116\117\114\110\32\115\116\97\99\107\32\115\105\122\101\10\32\32",newresource,check)
976893assert(a == 3 and _ENV.xxx == nil)
977−local a = T.testC(" pushvalue 2 # stack: S, NR, CH, NR
978− call 0 1 # create resource; stack: S, NR, CH, R
979− toclose -1 # mark it to be closed
980− pushvalue 2 # stack: S, NR, CH, R, NR
981− call 0 1 # create another resource; stack: S, NR, CH, R, R
982− toclose -1 # mark it to be closed
983− pushvalue 3 # stack: S, NR, CH, R, R, CH
984− pushint 2 # there should be two open resources
985− call 1 0 # stack: S, NR, CH, R, R
986− pop 1 # pop second resource
987− pushvalue 3 # stack: S, NR, CH, R, CH
988− pushint 1 # there should be one open resource
989− call 1 0 # stack: S, NR, CH, R
990− pop 1 # pop other resource from the stack
991− pushvalue 3 # stack: S, NR, CH, CH
992− pushint 0 # there should be no open resources
993− call 1 0 # stack: S, NR, CH
994− pushint *
995− return 1 # return stack size
996− ",newresource,check)
894+local a = T.testC("\32\32\32\32\112\117\115\104\118\97\108\117\101\32\50\32\32\35\32\115\116\97\99\107\58\32\83\44\32\78\82\44\32\67\72\44\32\78\82\10\32\32\32\32\99\97\108\108\32\48\32\49\32\32\32\35\32\99\114\101\97\116\101\32\114\101\115\111\117\114\99\101\59\32\115\116\97\99\107\58\32\83\44\32\78\82\44\32\67\72\44\32\82\10\32\32\32\32\116\111\99\108\111\115\101\32\45\49\32\35\32\109\97\114\107\32\105\116\32\116\111\32\98\101\32\99\108\111\115\101\100\10\32\32\32\32\112\117\115\104\118\97\108\117\101\32\50\32\32\35\32\32\115\116\97\99\107\58\32\83\44\32\78\82\44\32\67\72\44\32\82\44\32\78\82\10\32\32\32\32\99\97\108\108\32\48\32\49\32\32\32\35\32\99\114\101\97\116\101\32\97\110\111\116\104\101\114\32\114\101\115\111\117\114\99\101\59\32\115\116\97\99\107\58\32\83\44\32\78\82\44\32\67\72\44\32\82\44\32\82\10\32\32\32\32\116\111\99\108\111\115\101\32\45\49\32\35\32\109\97\114\107\32\105\116\32\116\111\32\98\101\32\99\108\111\115\101\100\10\32\32\32\32\112\117\115\104\118\97\108\117\101\32\51\32\32\35\32\115\116\97\99\107\58\32\83\44\32\78\82\44\32\67\72\44\32\82\44\32\82\44\32\67\72\10\32\32\32\32\112\117\115\104\105\110\116\32\50\32\32\32\35\32\116\104\101\114\101\32\115\104\111\117\108\100\32\98\101\32\116\119\111\32\111\112\101\110\32\114\101\115\111\117\114\99\101\115\10\32\32\32\32\99\97\108\108\32\49\32\48\32\32\35\32\32\115\116\97\99\107\58\32\83\44\32\78\82\44\32\67\72\44\32\82\44\32\82\10\32\32\32\32\112\111\112\32\49\32\32\32\35\32\112\111\112\32\115\101\99\111\110\100\32\114\101\115\111\117\114\99\101\10\32\32\32\32\112\117\115\104\118\97\108\117\101\32\51\32\32\35\32\115\116\97\99\107\58\32\83\44\32\78\82\44\32\67\72\44\32\82\44\32\67\72\10\32\32\32\32\112\117\115\104\105\110\116\32\49\32\32\32\35\32\116\104\101\114\101\32\115\104\111\117\108\100\32\98\101\32\111\110\101\32\111\112\101\110\32\114\101\115\111\117\114\99\101\10\32\32\32\32\99\97\108\108\32\49\32\48\32\32\35\32\115\116\97\99\107\58\32\83\44\32\78\82\44\32\67\72\44\32\82\10\32\32\32\32\112\111\112\32\49\32\32\32\32\32\32\32\35\32\112\111\112\32\111\116\104\101\114\32\114\101\115\111\117\114\99\101\32\102\114\111\109\32\116\104\101\32\115\116\97\99\107\10\32\32\32\32\112\117\115\104\118\97\108\117\101\32\51\32\32\35\32\115\116\97\99\107\58\32\83\44\32\78\82\44\32\67\72\44\32\67\72\10\32\32\32\32\112\117\115\104\105\110\116\32\48\32\32\32\35\32\116\104\101\114\101\32\115\104\111\117\108\100\32\98\101\32\110\111\32\111\112\101\110\32\114\101\115\111\117\114\99\101\115\10\32\32\32\32\99\97\108\108\32\49\32\48\32\32\35\32\115\116\97\99\107\58\32\83\44\32\78\82\44\32\67\72\10\32\32\32\32\112\117\115\104\105\110\116\32\42\10\32\32\32\32\114\101\116\117\114\110\32\49\32\32\32\32\35\32\114\101\116\117\114\110\32\115\116\97\99\107\32\115\105\122\101\10\32\32",newresource,check)
997895assert(a == 3)
998−local a,b = pcall(T.makeCfunc(" pushint 32
999− toclose -1
1000− "))
1001−assert(not a and string.find(b,"(C temporary)"))
1002−print("memory-allocation errors")
1003−checkerr("block too big",T.newuserdata,math.maxinteger)
896+local a,b = pcall(T.makeCfunc("\32\32\32\32\112\117\115\104\105\110\116\32\51\50\10\32\32\32\32\116\111\99\108\111\115\101\32\45\49\10\32\32"))
897+assert(not a and string.find(b,"\40\67\32\116\101\109\112\111\114\97\114\121\41"))
898+end
899+print("\109\101\109\111\114\121\45\97\108\108\111\99\97\116\105\111\110\32\101\114\114\111\114\115")
900+checkerr("\98\108\111\99\107\32\116\111\111\32\98\105\103",T.newuserdata,math.maxinteger)
1004901collectgarbage()
1005−local f = load("local a={}; for i=1,100000 do a[i]=i end")
902+local f = load("\108\111\99\97\108\32\97\61\123\125\59\32\102\111\114\32\105\61\49\44\49\48\48\48\48\48\32\100\111\32\97\91\105\93\61\105\32\101\110\100")
1006903T.alloccount(10)
1007904checkerr(MEMERRMSG,f)
1008905T.alloccount()
@@ -1017,16 +914,17 @@ collectgarbage()
1017914;
1018915collectgarbage()
1019916T.totalmem(M)
1020−a,b=T.testC("pcall 0 1 0; pushstatus; return 2",f)
917+a,b=T.testC("\112\99\97\108\108\32\48\32\49\32\48\59\32\112\117\115\104\115\116\97\116\117\115\59\32\114\101\116\117\114\110\32\50",f)
1021918T.totalmem(0)
1022−if a and b == "OK" then
919+if a and b == "\79\75" then
1023920break
1024921end
1025−if b ~= "OK" and b ~= MEMERRMSG then
922+if b ~= "\79\75" and b ~= MEMERRMSG then
1026923error(a,0)
1027924end
1028925M=M + 7
1029−print(string.format("minimum memory for %s: %d bytes",s,M - oldM))
926+end
927+print(string.format("\109\105\110\105\109\117\109\32\109\101\109\111\114\121\32\102\111\114\32\37\115\58\32\37\100\32\98\121\116\101\115",s,M - oldM))
1030928return a
1031929end
1032930local function testalloc
@@ -1039,16 +937,17 @@ collectgarbage()
1039937;
1040938collectgarbage()
1041939T.alloccount(M)
1042−a,b=T.testC("pcall 0 1 0; pushstatus; return 2",f)
940+a,b=T.testC("\112\99\97\108\108\32\48\32\49\32\48\59\32\112\117\115\104\115\116\97\116\117\115\59\32\114\101\116\117\114\110\32\50",f)
1043941T.alloccount()
1044−if a and b == "OK" then
942+if a and b == "\79\75" then
1045943break
1046944end
1047−if b ~= "OK" and b ~= MEMERRMSG then
945+if b ~= "\79\75" and b ~= MEMERRMSG then
1048946error(a,0)
1049947end
1050948M=M + 1
1051−print(string.format("minimum allocations for %s: %d allocations",s,M))
949+end
950+print(string.format("\109\105\110\105\109\117\109\32\97\108\108\111\99\97\116\105\111\110\115\32\102\111\114\32\37\115\58\32\37\100\32\97\108\108\111\99\97\116\105\111\110\115",s,M))
1052951return a
1053952end
1054953local function testamem
@@ -1056,88 +955,83 @@ local function testamem
1056955testalloc(s,f)
1057956return testbytes(s,f)
1058957end
1059−b=testamem("doing nothing",()
958+b=testamem("\100\111\105\110\103\32\110\111\116\104\105\110\103",function ()
1060959return 10
1061960end)
1062961assert(b == 10)
1063−testamem("state creation",()
962+testamem("\115\116\97\116\101\32\99\114\101\97\116\105\111\110",function ()
1064963local st = T.newstate()
1065964if st then
1066965T.closestate(st)
1067966end
1068967return st
1069968end)
1070−testamem("empty-table creation",()
969+testamem("\101\109\112\116\121\45\116\97\98\108\101\32\99\114\101\97\116\105\111\110",function ()
1071970return {}
1072971end)
1073−testamem("string creation",()
1074−return "XXX" .. "YYY"
972+testamem("\115\116\114\105\110\103\32\99\114\101\97\116\105\111\110",function ()
973+return "\88\88\88" .. "\89\89\89"
1075974end)
1076−testamem("coroutine creation",()
975+testamem("\99\111\114\111\117\116\105\110\101\32\99\114\101\97\116\105\111\110",function ()
1077976return coroutine.create(print)
1078977end)
1079−testamem("to-be-closed variables",()
1080−local flag =
1081−local x <close> = setmetatable({},{["__close"] = ()
978+testamem("\116\111\45\98\101\45\99\108\111\115\101\100\32\118\97\114\105\97\98\108\101\115",function ()
979+local flag
980+do
981+local x <close> = setmetatable({},{["\95\95\99\108\111\115\101"] = function ()
1082982flag=true
1083983end})
1084984flag=false
1085985local x = {}
986+end
1086987return flag
1087988end)
1088−local mt = T.testC("rawgeti R 1; return 1")
1089−assert(type(mt) == "thread" and coroutine.running() == mt)
989+local mt = T.testC("\114\97\119\103\101\116\105\32\82\32\49\59\32\114\101\116\117\114\110\32\49")
990+assert(type(mt) == "\116\104\114\101\97\100" and coroutine.running() == mt)
1090991local function expand
1091992(n,s)
1092993if n == 0 then
1093994return ""
1094995end
1095−local e = string.rep("=",n)
1096−return string.format("T.doonnewstack([%s[ %s;
1097− collectgarbage(); %s]%s])
1098−",e,s,expand(n - 1,s),e)
996+local e = string.rep("\61",n)
997+return string.format("\84\46\100\111\111\110\110\101\119\115\116\97\99\107\40\91\37\115\91\32\37\115\59\10\32\99\111\108\108\101\99\116\103\97\114\98\97\103\101\40\41\59\32\37\115\93\37\115\93\41\10",e,s,expand(n - 1,s),e)
1099998end
1100999G=0
11011000;
11021001collectgarbage()
11031002;
1104−a=collectgarbage("count")
1105−load(expand(20,"G=G+1"))()
1003+a=collectgarbage("\99\111\117\110\116")
1004+load(expand(20,"\71\61\71\43\49"))()
11061005assert(G == 20)
11071006;
11081007collectgarbage()
11091008;
11101009G=nil
1111−testamem("running code on new thread",()
1112−return T.doonnewstack("local x=1") == 0
1010+testamem("\114\117\110\110\105\110\103\32\99\111\100\101\32\111\110\32\110\101\119\32\116\104\114\101\97\100",function ()
1011+return T.doonnewstack("\108\111\99\97\108\32\120\61\49") == 0
11131012end)
1114−testamem("loadstring",()
1115−return load("x=1")
1013+testamem("\108\111\97\100\115\116\114\105\110\103",function ()
1014+return load("\120\61\49")
11161015end)
1117−local testprog = "local function foo () return end
1118−local t = {"x"}
1119−AA = "aaa"
1120−for i = 1, #t do AA = AA .. t[i] end
1121−return true
1122−"
1016+local testprog = "\108\111\99\97\108\32\102\117\110\99\116\105\111\110\32\102\111\111\32\40\41\32\114\101\116\117\114\110\32\101\110\100\10\108\111\99\97\108\32\116\32\61\32\123\34\120\34\125\10\65\65\32\61\32\34\97\97\97\34\10\102\111\114\32\105\32\61\32\49\44\32\35\116\32\100\111\32\65\65\32\61\32\65\65\32\46\46\32\116\91\105\93\32\101\110\100\10\114\101\116\117\114\110\32\116\114\117\101\10"
11231017_G.AA=nil
11241018local t = os.tmpname()
1125−local f = assert(io.open(t,"w"))
1019+local f = assert(io.open(t,"\119"))
11261020f:write(testprog)
11271021f:close()
1128−testamem("dofile",()
1022+testamem("\100\111\102\105\108\101",function ()
11291023local a = loadfile(t)
11301024return a and a()
11311025end)
11321026assert(os.remove(t))
1133−assert(_G.AA == "aaax")
1134−testamem("gsub",()
1135−local a,b = string.gsub("alo alo","(a)",(x)
1136−return x .. "b"
1027+assert(_G.AA == "\97\97\97\120")
1028+testamem("\103\115\117\98",function ()
1029+local a,b = string.gsub("\97\108\111\32\97\108\111","\40\97\41",function (x)
1030+return x .. "\98"
11371031end)
1138−return (a == "ablo ablo")
1032+return (a == "\97\98\108\111\32\97\98\108\111")
11391033end)
1140−testamem("dump/undump",()
1034+testamem("\100\117\109\112\47\117\110\100\117\109\112",function ()
11411035local a = load(testprog)
11421036local b = a and string.dump(a)
11431037a=b and load(b)
@@ -1145,57 +1039,59 @@ return a and a()
11451039end)
11461040_G.AA=nil
11471041local t = os.tmpname()
1148−testamem("file creation",()
1149−local f = assert(io.open(t,"w"))
1150−assert(not io.open("nomenaoexistente"))
1042+testamem("\102\105\108\101\32\99\114\101\97\116\105\111\110",function ()
1043+local f = assert(io.open(t,"\119"))
1044+assert(not io.open("\110\111\109\101\110\97\111\101\120\105\115\116\101\110\116\101"))
11511045io.close(f)
11521046;
1153−return not loadfile("nomenaoexistente")
1047+return not loadfile("\110\111\109\101\110\97\111\101\120\105\115\116\101\110\116\101")
11541048end)
11551049assert(os.remove(t))
1156−testamem("table creation",()
1050+testamem("\116\97\98\108\101\32\99\114\101\97\116\105\111\110",function ()
11571051local a,lim = {},10
11581052for i = 1, lim
11591053do
11601054a[i]=i
11611055;
1162−a[i .. "a"]={}
1056+a[i .. "\97"]={}
11631057end
1164−return (type(a[lim .. "a"]) == "table" and a[lim] == lim)
1058+return (type(a[lim .. "\97"]) == "\116\97\98\108\101" and a[lim] == lim)
11651059end)
1166−testamem("constructors",()
1167−local a = {10,20,30,40,50,["a"] = 1,["b"] = 2,["c"] = 3,["d"] = 4,["e"] = 5}
1168−return (type(a) == "table" and a.e == 5)
1060+testamem("\99\111\110\115\116\114\117\99\116\111\114\115",function ()
1061+local a = {10,20,30,40,50,["\97"] = 1,["\98"] = 2,["\99"] = 3,["\100"] = 4,["\101"] = 5}
1062+return (type(a) == "\116\97\98\108\101" and a.e == 5)
11691063end)
11701064local a = 1
11711065local close = nil
1172−testamem("closure creation",()
1066+testamem("\99\108\111\115\117\114\101\32\99\114\101\97\116\105\111\110",function ()
11731067function close(b)
1174−return (x)
1068+return function (x)
11751069return b + x
11761070end
11771071end
11781072return (close(2)(4) == 6)
11791073end)
1180−testamem("using coroutines",()
1181−local a = coroutine.wrap(()
1182−coroutine.yield(string.rep("a",10))
1074+testamem("\117\115\105\110\103\32\99\111\114\111\117\116\105\110\101\115",function ()
1075+local a = coroutine.wrap(function ()
1076+coroutine.yield(string.rep("\97",10))
11831077return {}
11841078end)
11851079assert(string.len(a()) == 10)
11861080return a()
11871081end)
1082+do
11881083local lim = 100
11891084local a = {}
11901085;
11911086for i = 1, lim
11921087do
1193−a[i]="01234567890123456789"
1088+a[i]="\48\49\50\51\52\53\54\55\56\57\48\49\50\51\52\53\54\55\56\57"
11941089end
1195−testamem("auxiliary buffer",()
1196−return (# table.concat(a,",") == 20 * lim + lim - 1)
1090+testamem("\97\117\120\105\108\105\97\114\121\32\98\117\102\102\101\114",function ()
1091+return (# table.concat(a,"\44") == 20 * lim + lim - 1)
11971092end)
1198−testamem("growing stack",()
1093+end
1094+testamem("\103\114\111\119\105\110\103\32\115\116\97\99\107",function ()
11991095local function foo
12001096(n)
12011097if n == 0 then
@@ -1206,91 +1102,66 @@ end
12061102end
12071103return foo(100)
12081104end)
1209−local res = T.testC("rawcheckstack 500000; return 1")
1105+do
1106+local res = T.testC("\114\97\119\99\104\101\99\107\115\116\97\99\107\32\53\48\48\48\48\48\59\32\114\101\116\117\114\110\32\49")
12101107assert(res == false)
12111108local L = T.newstate()
12121109T.alloccount(0)
1213−res=T.testC(L,"rawcheckstack 5000; return 1")
1110+res=T.testC(L,"\114\97\119\99\104\101\99\107\115\116\97\99\107\32\53\48\48\48\59\32\114\101\116\117\114\110\32\49")
12141111T.alloccount()
12151112T.closestate(L)
12161113assert(res == false)
1114+end
1115+do
12171116local L = T.newstate()
12181117T.alloccount(0)
12191118T.closestate(L)
12201119T.alloccount()
1120+end
1121+do
12211122local L = T.newstate()
12221123T.loadlib(L)
1223−local res = (T.doremote(L," _ENV = require"_G"
1224− local T = require"T"
1225− local a = {}
1226− for i = 1, 1000 do a[i] = 'i' .. i end -- grow string table
1227− local stsize, stuse = T.querystr()
1228− assert(stuse > 1000)
1229− local function foo (n)
1230− if n > 0 then foo(n - 1) end
1231− end
1232− foo(180) -- grow stack
1233− local _, stksize = T.stacklevel()
1234− assert(stksize > 180)
1235− a = nil
1236− T.alloccount(0)
1237− collectgarbage()
1238− T.alloccount()
1239− -- stack and string table could not be reallocated,
1240− -- so they kept their sizes (without errors)
1241− assert(select(2, T.stacklevel()) == stksize)
1242− assert(T.querystr() == stsize)
1243− return 'ok'
1244− "))
1245−assert(res == "ok")
1124+local res = (T.doremote(L,"\32\32\32\32\95\69\78\86\32\61\32\114\101\113\117\105\114\101\34\95\71\34\10\32\32\32\32\108\111\99\97\108\32\84\32\61\32\114\101\113\117\105\114\101\34\84\34\10\32\32\32\32\108\111\99\97\108\32\97\32\61\32\123\125\10\32\32\32\32\102\111\114\32\105\32\61\32\49\44\32\49\48\48\48\32\100\111\32\97\91\105\93\32\61\32\39\105\39\32\46\46\32\105\32\101\110\100\32\32\32\32\45\45\32\103\114\111\119\32\115\116\114\105\110\103\32\116\97\98\108\101\10\32\32\32\32\108\111\99\97\108\32\115\116\115\105\122\101\44\32\115\116\117\115\101\32\61\32\84\46\113\117\101\114\121\115\116\114\40\41\10\32\32\32\32\97\115\115\101\114\116\40\115\116\117\115\101\32\62\32\49\48\48\48\41\10\32\32\32\32\108\111\99\97\108\32\102\117\110\99\116\105\111\110\32\102\111\111\32\40\110\41\10\32\32\32\32\32\32\105\102\32\110\32\62\32\48\32\116\104\101\110\32\102\111\111\40\110\32\45\32\49\41\32\101\110\100\10\32\32\32\32\101\110\100\10\32\32\32\32\102\111\111\40\49\56\48\41\32\32\32\32\45\45\32\103\114\111\119\32\115\116\97\99\107\10\32\32\32\32\108\111\99\97\108\32\95\44\32\115\116\107\115\105\122\101\32\61\32\84\46\115\116\97\99\107\108\101\118\101\108\40\41\10\32\32\32\32\97\115\115\101\114\116\40\115\116\107\115\105\122\101\32\62\32\49\56\48\41\10\32\32\32\32\97\32\61\32\110\105\108\10\32\32\32\32\84\46\97\108\108\111\99\99\111\117\110\116\40\48\41\10\32\32\32\32\99\111\108\108\101\99\116\103\97\114\98\97\103\101\40\41\10\32\32\32\32\84\46\97\108\108\111\99\99\111\117\110\116\40\41\10\32\32\32\32\45\45\32\115\116\97\99\107\32\97\110\100\32\115\116\114\105\110\103\32\116\97\98\108\101\32\99\111\117\108\100\32\110\111\116\32\98\101\32\114\101\97\108\108\111\99\97\116\101\100\44\10\32\32\32\32\45\45\32\115\111\32\116\104\101\121\32\107\101\112\116\32\116\104\101\105\114\32\115\105\122\101\115\32\40\119\105\116\104\111\117\116\32\101\114\114\111\114\115\41\10\32\32\32\32\97\115\115\101\114\116\40\115\101\108\101\99\116\40\50\44\32\84\46\115\116\97\99\107\108\101\118\101\108\40\41\41\32\61\61\32\115\116\107\115\105\122\101\41\10\32\32\32\32\97\115\115\101\114\116\40\84\46\113\117\101\114\121\115\116\114\40\41\32\61\61\32\115\116\115\105\122\101\41\10\32\32\32\32\114\101\116\117\114\110\32\39\111\107\39\10\32\32"))
1125+assert(res == "\111\107")
12461126T.closestate(L)
1247−print("+")
1127+end
1128+print("\43")
12481129local function gsub
12491130(a,b,c)
1250−a,b=T.testC("gsub 2 3 4; gettop; return 2",a,b,c)
1131+a,b=T.testC("\103\115\117\98\32\50\32\51\32\52\59\32\103\101\116\116\111\112\59\32\114\101\116\117\114\110\32\50",a,b,c)
12511132assert(b == 5)
12521133return a
12531134end
1254−assert(gsub("alo.alo.uhuh.",".","//") == "alo//alo//uhuh//")
1255−assert(gsub("alo.alo.uhuh.","alo","//") == "//.//.uhuh.")
1256−assert(gsub("","alo","//") == "")
1257−assert(gsub("...",".","/.") == "/././.")
1258−assert(gsub("...","...","") == "")
1259−local mt_xuxu,res,top = T.testC("newmetatable xuxu; gettop; return 3")
1260−assert(type(mt_xuxu) == "table" and res and top == 3)
1261−local d,res,top = T.testC("newmetatable xuxu; gettop; return 3")
1135+assert(gsub("\97\108\111\46\97\108\111\46\117\104\117\104\46","\46","\47\47") == "\97\108\111\47\47\97\108\111\47\47\117\104\117\104\47\47")
1136+assert(gsub("\97\108\111\46\97\108\111\46\117\104\117\104\46","\97\108\111","\47\47") == "\47\47\46\47\47\46\117\104\117\104\46")
1137+assert(gsub("","\97\108\111","\47\47") == "")
1138+assert(gsub("\46\46\46","\46","\47\46") == "\47\46\47\46\47\46")
1139+assert(gsub("\46\46\46","\46\46\46","") == "")
1140+local mt_xuxu,res,top = T.testC("\110\101\119\109\101\116\97\116\97\98\108\101\32\120\117\120\117\59\32\103\101\116\116\111\112\59\32\114\101\116\117\114\110\32\51")
1141+assert(type(mt_xuxu) == "\116\97\98\108\101" and res and top == 3)
1142+local d,res,top = T.testC("\110\101\119\109\101\116\97\116\97\98\108\101\32\120\117\120\117\59\32\103\101\116\116\111\112\59\32\114\101\116\117\114\110\32\51")
12621143assert(mt_xuxu == d and not res and top == 3)
1263−d,res,top=T.testC("newmetatable xuxu1; gettop; return 3")
1144+d,res,top=T.testC("\110\101\119\109\101\116\97\116\97\98\108\101\32\120\117\120\117\49\59\32\103\101\116\116\111\112\59\32\114\101\116\117\114\110\32\51")
12641145assert(mt_xuxu ~= d and res and top == 3)
12651146x=T.newuserdata(0)
12661147;
12671148y=T.newuserdata(0)
12681149;
1269−T.testC("pushstring xuxu; gettable R; setmetatable 2",x)
1150+T.testC("\112\117\115\104\115\116\114\105\110\103\32\120\117\120\117\59\32\103\101\116\116\97\98\108\101\32\82\59\32\115\101\116\109\101\116\97\116\97\98\108\101\32\50",x)
12701151assert(getmetatable(x) == mt_xuxu)
1271−local res1,res2,top = T.testC("testudata -1 xuxu
1272− testudata 2 xuxu
1273− gettop
1274− return 3",x)
1152+local res1,res2,top = T.testC("\116\101\115\116\117\100\97\116\97\32\45\49\32\120\117\120\117\10\32\32\32\9\32\9\9\9\32\32\116\101\115\116\117\100\97\116\97\32\50\32\120\117\120\117\10\9\9\9\9\32\32\103\101\116\116\111\112\10\9\9\9\9\32\32\114\101\116\117\114\110\32\51",x)
12751153assert(res1 and res2 and top == 4)
1276−res1,res2,top=T.testC("testudata -1 xuxu1
1277− testudata 2 xuxu1
1278− gettop
1279− return 3",x)
1154+res1,res2,top=T.testC("\116\101\115\116\117\100\97\116\97\32\45\49\32\120\117\120\117\49\10\9\9\9\32\32\32\32\116\101\115\116\117\100\97\116\97\32\50\32\120\117\120\117\49\10\9\9\9\32\32\32\32\103\101\116\116\111\112\10\9\9\9\32\32\32\32\114\101\116\117\114\110\32\51",x)
12801155assert(not res1 and not res2 and top == 4)
1281−res1,res2,top=T.testC("testudata -1 xuxu2
1282− testudata 2 xuxu2
1283− gettop
1284− return 3",x)
1156+res1,res2,top=T.testC("\116\101\115\116\117\100\97\116\97\32\45\49\32\120\117\120\117\50\10\9\9\9\32\32\32\32\116\101\115\116\117\100\97\116\97\32\50\32\120\117\120\117\50\10\9\9\9\32\32\32\32\103\101\116\116\111\112\10\9\9\9\32\32\32\32\114\101\116\117\114\110\32\51",x)
12851157assert(not res1 and not res2 and top == 4)
1286−res1,res2,top=T.testC("testudata -1 xuxu
1287− testudata 2 xuxu
1288− gettop
1289− return 3",y)
1158+res1,res2,top=T.testC("\116\101\115\116\117\100\97\116\97\32\45\49\32\120\117\120\117\10\9\9\9\32\32\32\32\116\101\115\116\117\100\97\116\97\32\50\32\120\117\120\117\10\9\9\9\32\32\32\32\103\101\116\116\111\112\10\9\9\9\32\32\32\32\114\101\116\117\114\110\32\51",y)
12901159assert(not res1 and not res2 and top == 4)
1160+do
12911161local r = debug.getregistry()
12921162assert(r.xuxu == mt_xuxu and r.xuxu1 == d)
12931163r.xuxu=nil
12941164;
12951165r.xuxu1=nil
1296−print("OK")
1166+end
1167+print("\79\75")