aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
Diffstat (limited to 'testes')
-rw-r--r--testes/calls.lua23
1 files changed, 20 insertions, 3 deletions
diff --git a/testes/calls.lua b/testes/calls.lua
index 409a275d..12312d60 100644
--- a/testes/calls.lua
+++ b/testes/calls.lua
@@ -178,7 +178,7 @@ do -- tail calls x chain of __call
178 end 178 end
179 179
180 -- build a chain of __call metamethods ending in function 'foo' 180 -- build a chain of __call metamethods ending in function 'foo'
181 for i = 1, 100 do 181 for i = 1, 15 do
182 foo = setmetatable({}, {__call = foo}) 182 foo = setmetatable({}, {__call = foo})
183 end 183 end
184 184
@@ -190,8 +190,8 @@ end
190print('+') 190print('+')
191 191
192 192
193do -- testing chains of '__call' 193do print"testing chains of '__call'"
194 local N = 20 194 local N = 15
195 local u = table.pack 195 local u = table.pack
196 for i = 1, N do 196 for i = 1, N do
197 u = setmetatable({i}, {__call = u}) 197 u = setmetatable({i}, {__call = u})
@@ -207,6 +207,23 @@ do -- testing chains of '__call'
207end 207end
208 208
209 209
210do -- testing chains too long
211 local a = {}
212 for i = 1, 16 do -- one too many
213 a = setmetatable({}, {__call = a})
214 end
215 local status, msg = pcall(a)
216 assert(not status and string.find(msg, "too long"))
217
218 setmetatable(a, {__call = a}) -- infinite chain
219 local status, msg = pcall(a)
220 assert(not status and string.find(msg, "too long"))
221
222 -- again, with a tail call
223 local status, msg = pcall(function () return a() end)
224 assert(not status and string.find(msg, "too long"))
225end
226
210a = nil 227a = nil
211(function (x) a=x end)(23) 228(function (x) a=x end)(23)
212assert(a == 23 and (function (x) return x*2 end)(20) == 40) 229assert(a == 23 and (function (x) return x*2 end)(20) == 40)