Skip to content

Commit 395cd6a

Browse files
committed
support MultiArray.GetLength
1 parent 219c06a commit 395cd6a

4 files changed

Lines changed: 31 additions & 9 deletions

File tree

‎CSharp.lua/CoreSystem.Lua/CoreSystem/Array.lua‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ limitations under the License.
1515
--]]
1616

1717
local System = System
18+
local throw = System.throw
1819
local Collection = System.Collection
1920
local buildArray = Collection.buildArray
2021
local getArray = Collection.getArray
2122
local setArray = Collection.setArray
22-
local checkIndex = Collection.checkIndex
2323
local arrayEnumerator = Collection.arrayEnumerator
2424
local findAll = Collection.findAllOfArray
2525

26+
local IndexOutOfRangeException = System.IndexOutOfRangeException
27+
2628
local assert = assert
2729
local select = select
2830
local setmetatable = setmetatable
@@ -49,6 +51,13 @@ function Array.getLength(this)
4951
return #this
5052
end
5153

54+
function Array.GetLength(this, dimension)
55+
if dimension ~= 0 then
56+
throw(IndexOutOfRangeException())
57+
end
58+
return #this
59+
end
60+
5261
function Array.getCount(this)
5362
return #this
5463
end
@@ -141,13 +150,16 @@ function MultiArray.get(this, ...)
141150
return getArray(this, index)
142151
end
143152

144-
function MultiArray.getLength(this, dimension)
145-
if dimension == nil then
146-
return #this
147-
end
153+
function MultiArray.getLength(this)
154+
return #this
155+
end
156+
157+
function MultiArray.GetLength(this, dimension)
148158
local rank = this.__rank__
149-
checkIndex(rank, dimension)
150-
return this.__rank__[dimension + 1]
159+
if dimension < 0 or dimension >= #rank then
160+
throw(IndexOutOfRangeException())
161+
end
162+
return rank[dimension + 1]
151163
end
152164

153165
function MultiArray.getRank(this)

‎CSharp.lua/CoreSystem.Lua/CoreSystem/Exception.lua‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,16 @@ define("System.ArgumentOutOfRangeException", {
118118
end,
119119

120120
getActualValue = function(this)
121-
return this.actualValue
121+
return this.actualValue
122+
end
123+
})
124+
125+
define("System.IndexOutOfRangeException", {
126+
__tostring = toString,
127+
__inherits__ = { Exception },
128+
129+
__ctor__ = function (this, message, innerException)
130+
Exception.__ctor__(this, message or "Index was outside the bounds of the array.", innerException)
122131
end
123132
})
124133

‎CSharp.lua/CoreSystem.Lua/CoreSystem/String.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ String.ToString = tostring
142142

143143
function String.get(this, index)
144144
if index < 0 or index >= #this then
145-
throw(IndexOutOfRangeException())
145+
throw(IndexOutOfRangeException())
146146
end
147147
return sbyte(this, index + 1)
148148
end

‎CSharp.lua/CoreSystem.Lua/Sample/test.lua‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,4 @@ test(testStringBuilder, "StringBuilder")
372372
test(testIO, "IO")
373373
--test(testConsole, "Console")
374374
--test(testAsync, "Async")
375+

0 commit comments

Comments
 (0)