aboutsummaryrefslogtreecommitdiff
path: root/testes/goto.lua
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2025-06-18 16:45:55 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2025-06-18 16:45:55 -0300
commit07b009c3712c062957593d0a4fa82e0fe9023024 (patch)
tree1628514f820fdbf452d6e9c524a22d3dd14198b2 /testes/goto.lua
parentf71156744851701b5d5fabdda5061b31e53f8f14 (diff)
downloadlua-07b009c3712c062957593d0a4fa82e0fe9023024.tar.gz
lua-07b009c3712c062957593d0a4fa82e0fe9023024.tar.bz2
lua-07b009c3712c062957593d0a4fa82e0fe9023024.zip
No need to limit variable declarations to 250
Only local variables, which use registers, need this low limit.
Diffstat (limited to 'testes/goto.lua')
-rw-r--r--testes/goto.lua38
1 files changed, 33 insertions, 5 deletions
diff --git a/testes/goto.lua b/testes/goto.lua
index 7e40fc4f..3519e75d 100644
--- a/testes/goto.lua
+++ b/testes/goto.lua
@@ -293,14 +293,14 @@ end
293foo() 293foo()
294-------------------------------------------------------------------------- 294--------------------------------------------------------------------------
295 295
296local function checkerr (code, err)
297 local st, msg = load(code)
298 assert(not st and string.find(msg, err))
299end
300
296do 301do
297 global T<const> 302 global T<const>
298 303
299 local function checkerr (code, err)
300 local st, msg = load(code)
301 assert(not st and string.find(msg, err))
302 end
303
304 -- globals must be declared, after a global declaration 304 -- globals must be declared, after a global declaration
305 checkerr("global none; X = 1", "variable 'X'") 305 checkerr("global none; X = 1", "variable 'X'")
306 checkerr("global none; function XX() end", "variable 'XX'") 306 checkerr("global none; function XX() end", "variable 'XX'")
@@ -383,5 +383,33 @@ do
383 383
384end 384end
385 385
386
387do -- Ok to declare hundreds of globals
388 global table
389 local code = {}
390 for i = 1, 1000 do
391 code[#code + 1] = ";global x" .. i
392 end
393 code[#code + 1] = "; return x990"
394 code = table.concat(code)
395 _ENV.x990 = 11
396 assert(load(code)() == 11)
397 _ENV.x990 = nil
398end
399
400do -- mixing lots of global/local declarations
401 global table
402 local code = {}
403 for i = 1, 200 do
404 code[#code + 1] = ";global x" .. i
405 code[#code + 1] = ";local y" .. i .. "=" .. (2*i)
406 end
407 code[#code + 1] = "; return x200 + y200"
408 code = table.concat(code)
409 _ENV.x200 = 11
410 assert(assert(load(code))() == 2*200 + 11)
411 _ENV.x200 = nil
412end
413
386print'OK' 414print'OK'
387 415