diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-05-13 11:43:10 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-05-13 11:43:10 -0300 |
| commit | 3b9dd52be02fd43c598f4adb6fa7844e6a573923 (patch) | |
| tree | 8f858942f5db0e3d9d7cad503b59ee1541a60aa6 /testes/calls.lua | |
| parent | 7dc6aae29057c9dc4588f780c7abd72a62ff4c8e (diff) | |
| download | lua-3b9dd52be02fd43c598f4adb6fa7844e6a573923.tar.gz lua-3b9dd52be02fd43c598f4adb6fa7844e6a573923.tar.bz2 lua-3b9dd52be02fd43c598f4adb6fa7844e6a573923.zip | |
Collective declaration for globals ('global *')
Diffstat (limited to 'testes/calls.lua')
| -rw-r--r-- | testes/calls.lua | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/testes/calls.lua b/testes/calls.lua index 942fad72..0ea1c4ab 100644 --- a/testes/calls.lua +++ b/testes/calls.lua | |||
| @@ -1,6 +1,8 @@ | |||
| 1 | -- $Id: testes/calls.lua $ | 1 | -- $Id: testes/calls.lua $ |
| 2 | -- See Copyright Notice in file lua.h | 2 | -- See Copyright Notice in file lua.h |
| 3 | 3 | ||
| 4 | global * <const> | ||
| 5 | |||
| 4 | print("testing functions and calls") | 6 | print("testing functions and calls") |
| 5 | 7 | ||
| 6 | local debug = require "debug" | 8 | local debug = require "debug" |
| @@ -22,7 +24,7 @@ assert(not pcall(type)) | |||
| 22 | 24 | ||
| 23 | 25 | ||
| 24 | -- testing local-function recursion | 26 | -- testing local-function recursion |
| 25 | fact = false | 27 | global fact; fact = false |
| 26 | do | 28 | do |
| 27 | local res = 1 | 29 | local res = 1 |
| 28 | local function fact (n) | 30 | local function fact (n) |
| @@ -63,7 +65,7 @@ a.b.c:f2('k', 12); assert(a.b.c.k == 12) | |||
| 63 | 65 | ||
| 64 | print('+') | 66 | print('+') |
| 65 | 67 | ||
| 66 | t = nil -- 'declare' t | 68 | global t; t = nil -- 'declare' t |
| 67 | function f(a,b,c) local d = 'a'; t={a,b,c,d} end | 69 | function f(a,b,c) local d = 'a'; t={a,b,c,d} end |
| 68 | 70 | ||
| 69 | f( -- this line change must be valid | 71 | f( -- this line change must be valid |
| @@ -75,7 +77,7 @@ assert(t[1] == 1 and t[2] == 2 and t[3] == 3 and t[4] == 'a') | |||
| 75 | 77 | ||
| 76 | t = nil -- delete 't' | 78 | t = nil -- delete 't' |
| 77 | 79 | ||
| 78 | function fat(x) | 80 | global function fat(x) |
| 79 | if x <= 1 then return 1 | 81 | if x <= 1 then return 1 |
| 80 | else return x*load("return fat(" .. x-1 .. ")", "")() | 82 | else return x*load("return fat(" .. x-1 .. ")", "")() |
| 81 | end | 83 | end |
| @@ -107,7 +109,7 @@ end | |||
| 107 | 109 | ||
| 108 | _G.deep = nil -- "declaration" (used by 'all.lua') | 110 | _G.deep = nil -- "declaration" (used by 'all.lua') |
| 109 | 111 | ||
| 110 | function deep (n) | 112 | global function deep (n) |
| 111 | if n>0 then deep(n-1) end | 113 | if n>0 then deep(n-1) end |
| 112 | end | 114 | end |
| 113 | deep(10) | 115 | deep(10) |
| @@ -352,7 +354,7 @@ assert(not load(function () return true end)) | |||
| 352 | 354 | ||
| 353 | -- small bug | 355 | -- small bug |
| 354 | local t = {nil, "return ", "3"} | 356 | local t = {nil, "return ", "3"} |
| 355 | f, msg = load(function () return table.remove(t, 1) end) | 357 | local f, msg = load(function () return table.remove(t, 1) end) |
| 356 | assert(f() == nil) -- should read the empty chunk | 358 | assert(f() == nil) -- should read the empty chunk |
| 357 | 359 | ||
| 358 | -- another small bug (in 5.2.1) | 360 | -- another small bug (in 5.2.1) |
| @@ -388,7 +390,8 @@ assert(load("return _ENV", nil, nil, 123)() == 123) | |||
| 388 | 390 | ||
| 389 | 391 | ||
| 390 | -- load when _ENV is not first upvalue | 392 | -- load when _ENV is not first upvalue |
| 391 | local x; XX = 123 | 393 | global XX; local x |
| 394 | XX = 123 | ||
| 392 | local function h () | 395 | local function h () |
| 393 | local y=x -- use 'x', so that it becomes 1st upvalue | 396 | local y=x -- use 'x', so that it becomes 1st upvalue |
| 394 | return XX -- global name | 397 | return XX -- global name |
