diff options
Diffstat (limited to 'testes')
-rw-r--r-- | testes/closure.lua | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/testes/closure.lua b/testes/closure.lua index 5d090d91..cdeaebaa 100644 --- a/testes/closure.lua +++ b/testes/closure.lua | |||
@@ -44,18 +44,17 @@ assert(B.g == 19) | |||
44 | 44 | ||
45 | -- testing equality | 45 | -- testing equality |
46 | a = {} | 46 | a = {} |
47 | collectgarbage"stop" | ||
48 | for i = 1, 5 do a[i] = function (x) return x + a + _ENV end end | ||
49 | collectgarbage"restart" | ||
50 | assert(a[3] == a[4] and a[4] == a[5]) | ||
51 | 47 | ||
52 | for i = 1, 5 do a[i] = function (x) return i + a + _ENV end end | 48 | for i = 1, 5 do a[i] = function (x) return i + a + _ENV end end |
53 | assert(a[3] ~= a[4] and a[4] ~= a[5]) | 49 | assert(a[3] ~= a[4] and a[4] ~= a[5]) |
54 | 50 | ||
55 | local function f() | 51 | do |
56 | return function (x) return math.sin(_ENV[x]) end | 52 | local a = function (x) return math.sin(_ENV[x]) end |
53 | local function f() | ||
54 | return a | ||
55 | end | ||
56 | assert(f() == f()) | ||
57 | end | 57 | end |
58 | assert(f() == f()) | ||
59 | 58 | ||
60 | 59 | ||
61 | -- testing closures with 'for' control variable | 60 | -- testing closures with 'for' control variable |