diff options
Diffstat (limited to 'testes/api.lua')
-rw-r--r-- | testes/api.lua | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/testes/api.lua b/testes/api.lua index fb7e7085..c1bcb4b7 100644 --- a/testes/api.lua +++ b/testes/api.lua | |||
@@ -1130,7 +1130,7 @@ do | |||
1130 | -- closing resources with 'closeslot' | 1130 | -- closing resources with 'closeslot' |
1131 | _ENV.xxx = true | 1131 | _ENV.xxx = true |
1132 | local a = T.testC([[ | 1132 | local a = T.testC([[ |
1133 | pushvalue 2 # stack: S, NR, CH | 1133 | pushvalue 2 # stack: S, NR, CH, NR |
1134 | call 0 1 # create resource; stack: S, NR, CH, R | 1134 | call 0 1 # create resource; stack: S, NR, CH, R |
1135 | toclose -1 # mark it to be closed | 1135 | toclose -1 # mark it to be closed |
1136 | pushvalue 2 # stack: S, NR, CH, R, NR | 1136 | pushvalue 2 # stack: S, NR, CH, R, NR |
@@ -1151,6 +1151,30 @@ do | |||
1151 | ]], newresource, check) | 1151 | ]], newresource, check) |
1152 | assert(a == 3 and _ENV.xxx == nil) -- no extra items left in the stack | 1152 | assert(a == 3 and _ENV.xxx == nil) -- no extra items left in the stack |
1153 | 1153 | ||
1154 | -- closing resources with 'pop' | ||
1155 | local a = T.testC([[ | ||
1156 | pushvalue 2 # stack: S, NR, CH, NR | ||
1157 | call 0 1 # create resource; stack: S, NR, CH, R | ||
1158 | toclose -1 # mark it to be closed | ||
1159 | pushvalue 2 # stack: S, NR, CH, R, NR | ||
1160 | call 0 1 # create another resource; stack: S, NR, CH, R, R | ||
1161 | toclose -1 # mark it to be closed | ||
1162 | pushvalue 3 # stack: S, NR, CH, R, R, CH | ||
1163 | pushint 2 # there should be two open resources | ||
1164 | call 1 0 # stack: S, NR, CH, R, R | ||
1165 | pop 1 # pop second resource | ||
1166 | pushvalue 3 # stack: S, NR, CH, R, CH | ||
1167 | pushint 1 # there should be one open resource | ||
1168 | call 1 0 # stack: S, NR, CH, R | ||
1169 | pop 1 # pop other resource from the stack | ||
1170 | pushvalue 3 # stack: S, NR, CH, CH | ||
1171 | pushint 0 # there should be no open resources | ||
1172 | call 1 0 # stack: S, NR, CH | ||
1173 | pushint * | ||
1174 | return 1 # return stack size | ||
1175 | ]], newresource, check) | ||
1176 | assert(a == 3) -- no extra items left in the stack | ||
1177 | |||
1154 | -- non-closable value | 1178 | -- non-closable value |
1155 | local a, b = pcall(T.makeCfunc[[ | 1179 | local a, b = pcall(T.makeCfunc[[ |
1156 | pushint 32 | 1180 | pushint 32 |