aboutsummaryrefslogtreecommitdiff
path: root/testes/api.lua
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-01-15 11:31:49 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-01-15 11:31:49 -0300
commit17e0c29d9b435392016b707309ed51409b0aea12 (patch)
treec7178cf68fac2f1f9c3b22ce50be29b67f416cc0 /testes/api.lua
parent8eb0abc9db4d47db5192bed18565e3d1aa53566d (diff)
downloadlua-17e0c29d9b435392016b707309ed51409b0aea12.tar.gz
lua-17e0c29d9b435392016b707309ed51409b0aea12.tar.bz2
lua-17e0c29d9b435392016b707309ed51409b0aea12.zip
Clear interface between references and predefines
The reference system has a defined way to add initial values to the table where it operates.
Diffstat (limited to 'testes/api.lua')
-rw-r--r--testes/api.lua37
1 files changed, 27 insertions, 10 deletions
diff --git a/testes/api.lua b/testes/api.lua
index 85dadb69..ca4b3fb4 100644
--- a/testes/api.lua
+++ b/testes/api.lua
@@ -467,7 +467,7 @@ for i = 1,lim do
467 prog[#prog + 1] = "pushnum " .. i * 10 467 prog[#prog + 1] = "pushnum " .. i * 10
468end 468end
469 469
470prog[#prog + 1] = "rawgeti R 2" -- get global table in registry 470prog[#prog + 1] = "rawgeti R !G" -- get global table in registry
471prog[#prog + 1] = "insert " .. -(2*lim + 2) 471prog[#prog + 1] = "insert " .. -(2*lim + 2)
472 472
473for i = 1,lim do 473for i = 1,lim do
@@ -930,28 +930,30 @@ checkerr("FILE%* expected, got userdata", io.input, x)
930 930
931assert(debug.getmetatable(x) == nil and debug.getmetatable(y) == nil) 931assert(debug.getmetatable(x) == nil and debug.getmetatable(y) == nil)
932 932
933local d = T.ref(a); 933-- Test references in an arbitrary table
934local e = T.ref(b); 934local reftable = {}
935local f = T.ref(c); 935local d = T.ref(a, reftable);
936t = {T.getref(d), T.getref(e), T.getref(f)} 936local e = T.ref(b, reftable);
937local f = T.ref(c, reftable);
938t = {T.getref(d, reftable), T.getref(e, reftable), T.getref(f, reftable)}
937assert(t[1] == a and t[2] == b and t[3] == c) 939assert(t[1] == a and t[2] == b and t[3] == c)
938 940
939t=nil; a=nil; c=nil; 941t=nil; a=nil; c=nil;
940T.unref(e); T.unref(f) 942T.unref(e, reftable); T.unref(f, reftable)
941 943
942collectgarbage() 944collectgarbage()
943 945
944-- check that unref objects have been collected 946-- check that unref objects have been collected
945assert(#cl == 1 and cl[1] == nc) 947assert(#cl == 1 and cl[1] == nc)
946 948
947x = T.getref(d) 949x = T.getref(d, reftable)
948assert(type(x) == 'userdata' and debug.getmetatable(x) == tt) 950assert(type(x) == 'userdata' and debug.getmetatable(x) == tt)
949x =nil 951x =nil
950tt.b = b -- create cycle 952tt.b = b -- create cycle
951tt=nil -- frees tt for GC 953tt=nil -- frees tt for GC
952A = nil 954A = nil
953b = nil 955b = nil
954T.unref(d); 956T.unref(d, reftable);
955local n5 = T.newuserdata(0) 957local n5 = T.newuserdata(0)
956debug.setmetatable(n5, {__gc=F}) 958debug.setmetatable(n5, {__gc=F})
957n5 = T.udataval(n5) 959n5 = T.udataval(n5)
@@ -960,6 +962,21 @@ assert(#cl == 4)
960-- check order of collection 962-- check order of collection
961assert(cl[2] == n5 and cl[3] == nb and cl[4] == na) 963assert(cl[2] == n5 and cl[3] == nb and cl[4] == na)
962 964
965-- reuse a reference in 'reftable'
966T.unref(T.ref(23, reftable), reftable)
967
968do -- check reftable
969 local count = 0
970 local i = 1
971 while reftable[i] ~= 0 do
972 i = reftable[i] -- traverse linked list of free references
973 count = count + 1
974 end
975 -- maximum number of simultaneously locked objects was 3
976 assert(count == 3 and #reftable == 3 + 1) -- +1 for reserved [1]
977end
978
979
963collectgarbage"restart" 980collectgarbage"restart"
964 981
965 982
@@ -1363,8 +1380,8 @@ end)
1363 1380
1364-- testing threads 1381-- testing threads
1365 1382
1366-- get main thread from registry (at index LUA_RIDX_MAINTHREAD == 1) 1383-- get main thread from registry
1367local mt = T.testC("rawgeti R 1; return 1") 1384local mt = T.testC("rawgeti R !M; return 1")
1368assert(type(mt) == "thread" and coroutine.running() == mt) 1385assert(type(mt) == "thread" and coroutine.running() == mt)
1369 1386
1370 1387