aboutsummaryrefslogtreecommitdiff
path: root/testes/goto.lua
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2025-07-08 13:33:57 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2025-07-08 13:33:57 -0300
commit942c10a5e33811a08a290ec15031c950a6d17c99 (patch)
tree114395a69857609bdd6c220f85476812f0fd5fb1 /testes/goto.lua
parent848568790826b7e201f84682185b5b605c473016 (diff)
downloadlua-942c10a5e33811a08a290ec15031c950a6d17c99.tar.gz
lua-942c10a5e33811a08a290ec15031c950a6d17c99.tar.bz2
lua-942c10a5e33811a08a290ec15031c950a6d17c99.zip
Optional initialization for global declarations
Diffstat (limited to 'testes/goto.lua')
-rw-r--r--testes/goto.lua23
1 files changed, 22 insertions, 1 deletions
diff --git a/testes/goto.lua b/testes/goto.lua
index 3519e75d..3310314d 100644
--- a/testes/goto.lua
+++ b/testes/goto.lua
@@ -380,7 +380,7 @@ do
380 global * 380 global *
381 Y = x + Y 381 Y = x + Y
382 assert(_ENV.Y == 20) 382 assert(_ENV.Y == 20)
383 383 Y = nil
384end 384end
385 385
386 386
@@ -411,5 +411,26 @@ do -- mixing lots of global/local declarations
411 _ENV.x200 = nil 411 _ENV.x200 = nil
412end 412end
413 413
414do print "testing initialization in global declarations"
415 global<const> a, b, c = 10, 20, 30
416 assert(_ENV.a == 10 and b == 20 and c == 30)
417
418 global<const> a, b, c = 10
419 assert(_ENV.a == 10 and b == nil and c == nil)
420
421 global table
422 global a, b, c, d = table.unpack{1, 2, 3, 6, 5}
423 assert(_ENV.a == 1 and b == 2 and c == 3 and d == 6)
424
425 local a, b = 100, 200
426 do
427 global a, b = a, b
428 end
429 assert(_ENV.a == 100 and _ENV.b == 200)
430
431
432 _ENV.a, _ENV.b, _ENV.c, _ENV.d = nil -- erase these globals
433end
434
414print'OK' 435print'OK'
415 436