diff options
Diffstat (limited to '')
-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..0dacb85a 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 = 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 = 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 |