diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-07-08 13:33:57 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-07-08 13:33:57 -0300 |
| commit | 942c10a5e33811a08a290ec15031c950a6d17c99 (patch) | |
| tree | 114395a69857609bdd6c220f85476812f0fd5fb1 /testes/goto.lua | |
| parent | 848568790826b7e201f84682185b5b605c473016 (diff) | |
| download | lua-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.lua | 23 |
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 | |
| 384 | end | 384 | end |
| 385 | 385 | ||
| 386 | 386 | ||
| @@ -411,5 +411,26 @@ do -- mixing lots of global/local declarations | |||
| 411 | _ENV.x200 = nil | 411 | _ENV.x200 = nil |
| 412 | end | 412 | end |
| 413 | 413 | ||
| 414 | do 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 | ||
| 433 | end | ||
| 434 | |||
| 414 | print'OK' | 435 | print'OK' |
| 415 | 436 | ||
