Skip to content

Commit b2100ff

Browse files
committed
Fix *Array.__newindex parameters (#10)
1 parent b35420c commit b2100ff

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/godot_array_commons.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ local function array_generate__index(methods)
6868
end
6969
end
7070

71-
local function array__newindex(methods)
71+
local function array__newindex(self, index, value)
7272
array_safe_set(self, index - 1, value)
7373
end
7474

src/test/array.lua

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
local lu = require "luaunit"
2+
3+
local Test = {}
4+
5+
function Test:test_array_index()
6+
local arr = Array(1, 3.14, 'hello!')
7+
lu.assert_nil(arr[0])
8+
lu.assert_equals(1, arr[1])
9+
lu.assert_equals(3.14, arr[2])
10+
lu.assert_equals(String 'hello!', arr[3])
11+
lu.assert_nil(arr[4])
12+
end
13+
14+
function Test:test_array_newindex()
15+
local arr = Array()
16+
arr[1] = 1
17+
arr[2] = '2'
18+
19+
lu.assert_equals(1, arr[1])
20+
lu.assert_equals(String '2', arr[2])
21+
lu.assert_equals(2, #arr)
22+
23+
arr[1] = 2
24+
arr[2] = '3'
25+
26+
lu.assert_equals(2, arr[1])
27+
lu.assert_equals(String '3', arr[2])
28+
lu.assert_equals(2, #arr)
29+
end
30+
31+
return Test

0 commit comments

Comments
 (0)