Skip to content

Commit e6c615c

Browse files
committed
fix some luacheck warning
1 parent 5f19a1f commit e6c615c

4 files changed

Lines changed: 56 additions & 86 deletions

File tree

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ if coroutine ~= nil then
5959
cyield = coroutine.yield
6060
end
6161

62-
local null = {}
62+
local null = { GetHashCode = System.zeroFn }
6363
local arrayEnumerator
6464
local arrayFromTable
6565

@@ -527,9 +527,8 @@ end
527527
local function checkOrderUniqueAndUnfoundElements(t, n, comparer, other, returnIfUnfound)
528528
if n == 0 then
529529
local numElementsInOther = 0
530-
for _, v in each(other) do
531-
numElementsInOther = numElementsInOther + 1
532-
break
530+
if other:GetEnumerator():MoveNext() then
531+
numElementsInOther = 1
533532
end
534533
return 0, numElementsInOther
535534
end

‎CSharp.lua/CoreSystem.Lua/CoreSystem/Collections/Linq.lua‎

Lines changed: 43 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
--]]
1616

17-
local System = System
17+
local System = _G.System
1818
local define = System.define
1919
local throw = System.throw
2020
local each = System.each
@@ -38,18 +38,15 @@ local Comparer_1 = System.Comparer_1
3838
local Empty = System.Array.Empty
3939

4040
local IEnumerable_1 = System.IEnumerable_1
41-
local IEnumerable = System.IEnumerable
4241
local IEnumerator_1 = System.IEnumerator_1
43-
local IEnumerator = System.IEnumerator
4442

4543
local assert = assert
46-
local getmetatable = getmetatable
4744
local setmetatable = setmetatable
4845
local select = select
4946
local pairs = pairs
5047
local tsort = table.sort
5148

52-
local InternalEnumerable = define("System.Linq.InternalEnumerable", function(T)
49+
local InternalEnumerable = define("System.Linq.InternalEnumerable", function(T)
5350
return {
5451
base = { IEnumerable_1(T) }
5552
}
@@ -60,7 +57,7 @@ local function createEnumerable(T, GetEnumerator)
6057
return setmetatable({ __genericT__ = T, GetEnumerator = GetEnumerator }, InternalEnumerable(T))
6158
end
6259

63-
local InternalEnumerator = define("System.Linq.InternalEnumerator", function(T)
60+
local InternalEnumerator = define("System.Linq.InternalEnumerator", function(T)
6461
return {
6562
base = { IEnumerator_1(T) }
6663
}
@@ -76,10 +73,10 @@ local function createEnumerator(T, source, tryGetNext, init)
7673
if state == 1 then
7774
state = 2
7875
if source then
79-
en = source:GetEnumerator()
76+
en = source:GetEnumerator()
8077
end
8178
if init then
82-
init(en)
79+
init(en)
8380
end
8481
end
8582
if state == 2 then
@@ -91,7 +88,7 @@ local function createEnumerator(T, source, tryGetNext, init)
9188
local dispose = en.Dispose
9289
if dispose then
9390
dispose(en)
94-
end
91+
end
9592
end
9693
end
9794
return false
@@ -109,7 +106,7 @@ function Enumerable.Where(source, predicate)
109106
if source == nil then throw(ArgumentNullException("source")) end
110107
if predicate == nil then throw(ArgumentNullException("predicate")) end
111108
local T = source.__genericT__
112-
return createEnumerable(T, function()
109+
return createEnumerable(T, function()
113110
local index = -1
114111
return createEnumerator(T, source, function(en)
115112
while en:MoveNext() do
@@ -118,7 +115,7 @@ function Enumerable.Where(source, predicate)
118115
if predicate(current, index) then
119116
return true, current
120117
end
121-
end
118+
end
122119
return false
123120
end)
124121
end)
@@ -129,7 +126,7 @@ function Enumerable.Select(source, selector, T)
129126
if selector == nil then throw(ArgumentNullException("selector")) end
130127
return createEnumerable(T, function()
131128
local index = -1
132-
return createEnumerator(T, source, function(en)
129+
return createEnumerator(T, source, function(en)
133130
if en:MoveNext() then
134131
index = index + 1
135132
return true, selector(en:getCurrent(), index)
@@ -165,7 +162,7 @@ local function selectMany(source, collectionSelector, resultSelector, T)
165162
end)
166163
end
167164

168-
local function identityFnOfSelectMany(s, x)
165+
local function identityFnOfSelectMany(_, x)
169166
return x
170167
end
171168

@@ -295,9 +292,13 @@ local function getGrouping(this, key, create)
295292
return nil
296293
end
297294

295+
local function getComparer(source, comparer)
296+
return comparer or EqualityComparer(source.__genericT__).getDefault()
297+
end
298+
298299
local Lookup = {
299300
__ctor__ = function (this, comparer)
300-
this.comparer = comparer or EqualityComparer(this.__genericTKey__).getDefault()
301+
this.comparer = getComparer(this, comparer)
301302
end,
302303
get = function (this, key)
303304
local grouping = getGrouping(this, key)
@@ -604,7 +605,7 @@ function Enumerable.Concat(first, second)
604605
end)
605606
end
606607

607-
function Enumerable.Zip(first, second, resultSelector, TResult)
608+
function Enumerable.Zip(first, second, resultSelector, TResult)
608609
if first == nil then throw(ArgumentNullException("first")) end
609610
if second == nil then throw(ArgumentNullException("second")) end
610611
if resultSelector == nil then throw(ArgumentNullException("resultSelector")) end
@@ -621,39 +622,15 @@ function Enumerable.Zip(first, second, resultSelector, TResult)
621622
end)
622623
end
623624

624-
local function addToSet(set, v, getHashCode, comparer)
625-
local hashCode = getHashCode(comparer, v)
626-
if set[hashCode] == nil then
627-
set[hashCode] = true
628-
return true
629-
end
630-
return false
631-
end
632-
633-
local function removeFromSet(set, v, getHashCode, comparer)
634-
local hashCode = getHashCode(comparer, v)
635-
if set[hashCode] ~= nil then
636-
set[hashCode] = nil
637-
return true
638-
end
639-
return false
640-
end
641-
642-
local function getComparer(source, comparer)
643-
return comparer or EqualityComparer(source.__genericT__).getDefault()
644-
end
645-
646625
function Enumerable.Distinct(source, comparer)
647626
if source == nil then throw(ArgumentNullException("source")) end
648627
local T = source.__genericT__
649628
return createEnumerable(T, function()
650-
local set = {}
651-
comparer = getComparer(source, comparer)
652-
local getHashCode = comparer.GetHashCodeOf
629+
local set = System.HashSet(T)(comparer)
653630
return createEnumerator(T, source, function(en)
654631
while en:MoveNext() do
655632
local current = en:getCurrent()
656-
if addToSet(set, current, getHashCode, comparer) then
633+
if set:Add(current) then
657634
return true, current
658635
end
659636
end
@@ -667,23 +644,21 @@ function Enumerable.Union(first, second, comparer)
667644
if second == nil then throw(ArgumentNullException("second")) end
668645
local T = first.__genericT__
669646
return createEnumerable(T, function()
670-
local set = {}
671-
comparer = getComparer(first, comparer)
672-
local getHashCode = comparer.GetHashCodeOf
647+
local set = System.HashSet(T)(comparer)
673648
local secondEn
674649
return createEnumerator(T, first, function(en)
675650
if secondEn == nil then
676651
while en:MoveNext() do
677652
local current = en:getCurrent()
678-
if addToSet(set, current, getHashCode, comparer) then
653+
if set:Add(current) then
679654
return true, current
680655
end
681656
end
682657
secondEn = second:GetEnumerator()
683658
end
684659
while secondEn:MoveNext() do
685660
local current = secondEn:getCurrent()
686-
if addToSet(set, current, getHashCode, comparer) then
661+
if set:Add(current) then
687662
return true, current
688663
end
689664
end
@@ -697,46 +672,42 @@ function Enumerable.Intersect(first, second, comparer)
697672
if second == nil then throw(ArgumentNullException("second")) end
698673
local T = first.__genericT__
699674
return createEnumerable(T, function()
700-
local set = {}
701-
comparer = getComparer(first, comparer)
702-
local getHashCode = comparer.GetHashCodeOf
675+
local set = System.HashSet(T)(comparer)
703676
return createEnumerator(T, first, function(en)
704677
while en:MoveNext() do
705678
local current = en:getCurrent()
706-
if removeFromSet(set, current, getHashCode, comparer) then
679+
if set:Remove(current) then
707680
return true, current
708681
end
709682
end
710683
return false
711684
end,
712685
function()
713686
for _, v in each(second) do
714-
addToSet(set, v, getHashCode, comparer)
687+
set:Add(v)
715688
end
716689
end)
717-
end)
690+
end)
718691
end
719692

720693
function Enumerable.Except(first, second, comparer)
721694
if first == nil then throw(ArgumentNullException("first")) end
722695
if second == nil then throw(ArgumentNullException("second")) end
723696
local T = first.__genericT__
724697
return createEnumerable(T, function()
725-
local set = {}
726-
comparer = getComparer(first, comparer)
727-
local getHashCode = comparer.GetHashCodeOf
698+
local set = System.HashSet(T)(comparer)
728699
return createEnumerator(T, first, function(en)
729700
while en:MoveNext() do
730701
local current = en:getCurrent()
731-
if addToSet(set, current, getHashCode, comparer) then
702+
if set:Add(current) then
732703
return true, current
733704
end
734705
end
735706
return false
736707
end,
737708
function()
738709
for _, v in each(second) do
739-
addToSet(set, v, getHashCode, comparer)
710+
set:Add(v)
740711
end
741712
end)
742713
end)
@@ -843,7 +814,7 @@ end
843814
function Enumerable.DefaultIfEmpty(source)
844815
if source == nil then throw(ArgumentNullException("source")) end
845816
local T = source.__genericT__
846-
local state
817+
local state
847818
return createEnumerable(T, function()
848819
return createEnumerator(T, source, function(en)
849820
if not state then
@@ -866,7 +837,7 @@ end
866837
function Enumerable.OfType(source, T)
867838
if source == nil then throw(ArgumentNullException("source")) end
868839
return createEnumerable(T, function()
869-
return createEnumerator(T, source, function(en)
840+
return createEnumerator(T, source, function(en)
870841
while en:MoveNext() do
871842
local current = en:getCurrent()
872843
if is(current, T) then
@@ -882,7 +853,7 @@ function Enumerable.Cast(source, T)
882853
if source == nil then throw(ArgumentNullException("source")) end
883854
if is(source, IEnumerable_1(T)) then return source end
884855
return createEnumerable(T, function()
885-
return createEnumerator(T, source, function(en)
856+
return createEnumerator(T, source, function(en)
886857
if en:MoveNext() then
887858
return true, cast(T, en:getCurrent())
888859
end
@@ -907,7 +878,7 @@ local function first(source, ...)
907878
end
908879
else
909880
local en = source:GetEnumerator()
910-
if en:MoveNext() then
881+
if en:MoveNext() then
911882
return true, en:getCurrent()
912883
end
913884
end
@@ -916,7 +887,7 @@ local function first(source, ...)
916887
local predicate = ...
917888
if predicate == nil then throw(ArgumentNullException("predicate")) end
918889
for _, v in each(source) do
919-
if predicate(v) then
890+
if predicate(v) then
920891
return true, v
921892
end
922893
end
@@ -949,7 +920,7 @@ local function last(source, ...)
949920
end
950921
else
951922
local en = source:GetEnumerator()
952-
if en:MoveNext() then
923+
if en:MoveNext() then
953924
local result
954925
repeat
955926
result = en:getCurrent()
@@ -967,7 +938,7 @@ local function last(source, ...)
967938
result = v
968939
found = true
969940
end
970-
end
941+
end
971942
if found then return true, result end
972943
return false, 1
973944
end
@@ -1020,8 +991,8 @@ local function single(source, ...)
1020991
found = true
1021992
end
1022993
end
1023-
if found then return true, result end
1024-
return false, 0
994+
if found then return true, result end
995+
return false, 0
1025996
end
1026997
end
1027998

@@ -1077,7 +1048,7 @@ function Enumerable.Range(start, count)
10771048
return createEnumerator(Int32, nil, function()
10781049
index = index + 1
10791050
if index < count then
1080-
return true, start + index
1051+
return true, start + index
10811052
end
10821053
return false
10831054
end)
@@ -1091,7 +1062,7 @@ function Enumerable.Repeat(element, count, T)
10911062
return createEnumerator(T, nil, function()
10921063
index = index + 1
10931064
if index < count then
1094-
return true, element
1065+
return true, element
10951066
end
10961067
return false
10971068
end)
@@ -1136,8 +1107,8 @@ function Enumerable.Count(source, ...)
11361107
end
11371108
local count = 0
11381109
local en = source:GetEnumerator()
1139-
while en:MoveNext() do
1140-
count = count + 1
1110+
while en:MoveNext() do
1111+
count = count + 1
11411112
end
11421113
return count
11431114
else
@@ -1221,7 +1192,7 @@ end
12211192
local function minOrMax(compareFn, source, ...)
12221193
if source == nil then throw(ArgumentNullException("source")) end
12231194
local len = select("#", ...)
1224-
local selector, T
1195+
local selector, T
12251196
if len == 0 then
12261197
selector, T = identityFn, source.__genericT__
12271198
else
@@ -1236,7 +1207,7 @@ local function minOrMax(compareFn, source, ...)
12361207
x = selector(x)
12371208
if x ~= nil and (value == nil or compareFn(compare, comparer, x, value)) then
12381209
value = x
1239-
end
1210+
end
12401211
end
12411212
return value
12421213
else

‎CSharp.lua/CoreSystem.Lua/CoreSystem/Core.lua‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ local function xpcallErr(e)
7979
return e
8080
end
8181

82-
local function try(try, catch, finally)
83-
local ok, status, result = xpcall(try, xpcallErr)
82+
local function try(tryFn, catch, finally)
83+
local ok, status, result = xpcall(tryFn, xpcallErr)
8484
if not ok then
8585
if catch then
8686
if finally then

0 commit comments

Comments
 (0)