aboutsummaryrefslogtreecommitdiff
path: root/testes/calls.lua
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--testes/calls.lua15
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
4global <const> *
5
4print("testing functions and calls") 6print("testing functions and calls")
5 7
6local debug = require "debug" 8local 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
25fact = false 27global fact = false
26do 28do
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
64print('+') 66print('+')
65 67
66t = nil -- 'declare' t 68global t = nil -- 'declare' t
67function f(a,b,c) local d = 'a'; t={a,b,c,d} end 69function f(a,b,c) local d = 'a'; t={a,b,c,d} end
68 70
69f( -- this line change must be valid 71f( -- 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
76t = nil -- delete 't' 78t = nil -- delete 't'
77 79
78function fat(x) 80global 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
110function deep (n) 112global function deep (n)
111 if n>0 then deep(n-1) end 113 if n>0 then deep(n-1) end
112end 114end
113deep(10) 115deep(10)
@@ -352,7 +354,7 @@ assert(not load(function () return true end))
352 354
353-- small bug 355-- small bug
354local t = {nil, "return ", "3"} 356local t = {nil, "return ", "3"}
355f, msg = load(function () return table.remove(t, 1) end) 357local f, msg = load(function () return table.remove(t, 1) end)
356assert(f() == nil) -- should read the empty chunk 358assert(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
391local x; XX = 123 393global XX; local x
394XX = 123
392local function h () 395local 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