fix some error for embedded environment by run BridgeNetTest · Drake53/CSharp.lua@bc1a740 · GitHub
Skip to content

Commit bc1a740

Browse files
committed
fix some error for embedded environment by run BridgeNetTest
1 parent 3b3bb86 commit bc1a740

19 files changed

Lines changed: 274 additions & 121 deletions

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

Lines changed: 8 additions & 4 deletions

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ local compareObj = System.compareObj
2222
local ArgumentException = System.ArgumentException
2323
local ArgumentNullException = System.ArgumentNullException
2424

25+
local type = type
26+
2527
local EqualityComparer
2628
EqualityComparer = define("System.EqualityComparer", function (T)
2729
local equals
@@ -37,6 +39,12 @@ EqualityComparer = define("System.EqualityComparer", function (T)
3739
else
3840
equals = equalsObj
3941
end
42+
local function getHashCode(x)
43+
if type(x) == "table" then
44+
return x:GetHashCode()
45+
end
46+
return x
47+
end
4048
local defaultComparer
4149
return {
4250
__genericT__ = T,
@@ -59,11 +67,11 @@ EqualityComparer = define("System.EqualityComparer", function (T)
5967
end,
6068
GetHashCodeOf = function (this, obj)
6169
if obj == nil then return 0 end
62-
return obj:GetHashCode()
70+
return getHashCode(obj)
6371
end,
6472
GetHashCodeObjOf = function (this, obj)
6573
if obj == nil then return 0 end
66-
if System.is(obj, T) then return obj:GetHashCode() end
74+
if System.is(obj, T) then return getHashCode(obj) end
6775
throw(ArgumentException("Type of argument is not compatible with the generic comparer."))
6876
return false
6977
end,

‎CSharp.lua/CoreSystem.Lua/CoreSystem/Convert.lua‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ local trunc = System.trunc
2222
local define = System.define
2323
local identityFn = System.identityFn
2424
local IConvertible = System.IConvertible
25+
local systemToString = System.toString
2526

2627
local OverflowException = System.OverflowException
2728
local FormatException = System.FormatException
@@ -368,15 +369,15 @@ local function toString(value, toBaseOrProvider, cast)
368369
elseif toBaseOrProvider == 8 then
369370
return ("%o"):format(value)
370371
elseif toBaseOrProvider == 10 then
371-
return value:ToString()
372+
return value .. ""
372373
elseif toBaseOrProvider == 16 then
373374
return ("%x"):format(value)
374375
else
375376
throw(ArgumentException())
376377
end
377378
end
378379
end
379-
return value:ToString()
380+
return systemToString(value)
380381
end
381382

382383
define("System.Convert", {

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

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,9 @@ if prevSystem then
444444
end
445445
global.System = System
446446

447+
local debugsetmetatable = debug and debug.setmetatable
448+
System.debugsetmetatable = debugsetmetatable
449+
447450
local _, _, version = sfind(_VERSION, "^Lua (.*)$")
448451
version = tonumber(version)
449452
System.luaVersion = version
@@ -521,9 +524,7 @@ if version < 5.3 then
521524
end
522525

523526
function System.divOfNull(x, y)
524-
if x == nil or y == nil then
525-
return nil
526-
end
527+
if x == nil or y == nil then return nil end
527528
if y == 0 then throw(System.DivideByZeroException(), 1) end
528529
return trunc(x / y)
529530
end
@@ -537,6 +538,18 @@ if version < 5.3 then
537538
return v
538539
end
539540

541+
if debugsetmetatable then
542+
function System.modOfNull(x, y)
543+
if x == nil or y == nil then return nil end
544+
if y == 0 then throw(System.DivideByZeroException(), 1) end
545+
local v = x % y
546+
if v ~= 0 and x * y < 0 then
547+
return v - y
548+
end
549+
return v
550+
end
551+
end
552+
540553
function System.toUInt(v, max, mask, checked)
541554
if v >= 0 and v <= max then
542555
return v
@@ -719,6 +732,7 @@ else
719732
local System = System
720733
local throw = System.throw
721734
local trunc = System.trunc
735+
local debugsetmetatable = System.debugsetmetatable
722736
723737
function System.bnot(x) return ~x end
724738
function System.band(x, y) return x & y end
@@ -727,15 +741,36 @@ else
727741
function System.sl(x, y) return x << y end
728742
function System.sr(x, y) return x >> y end
729743
function System.div(x, y) if x ~ y < 0 then return -(-x // y) end return x // y end
730-
744+
731745
function System.mod(x, y)
732746
local v = x % y
733747
if v ~= 0 and 1.0 * x * y < 0 then
734748
return v - y
735749
end
736750
return v
737751
end
738-
752+
753+
if not debugsetmetatable then
754+
function System.bnotOfNull(x) if x == nil then return nil end return ~x end
755+
function System.bandOfNull(x, y) if x == nil or y == nil then return nil end return x & y end
756+
function System.borOfNull(x, y) if x == nil or y == nil then return nil end return x | y end
757+
function System.xorOfNull(x, y) if x == nil or y == nil then return nil end return x ~ y end
758+
function System.slOfNull(x, y) if x == nil or y == nil then return nil end return x << y end
759+
function System.srOfNull(x, y) if x == nil or y == nil then return nil end return x >> y end
760+
function System.divOfNull(x, y) if x == nil or y == nil then return nil end if x ~ y < 0 then return -(-x // y) end return x // y end
761+
762+
function System.modOfNull(x, y)
763+
if x == nil or y == nil then
764+
return nil
765+
end
766+
local v = x % y
767+
if v ~= 0 and 1.0 * x * y < 0 then
768+
return v - y
769+
end
770+
return v
771+
end
772+
end
773+
739774
local function toUInt (v, max, mask, checked)
740775
if v >= 0 and v <= max then
741776
return v
@@ -1013,9 +1048,6 @@ function System.base(this)
10131048
return getmetatable(getmetatable(this))
10141049
end
10151050

1016-
local debugsetmetatable = debug and debug.setmetatable
1017-
System.debugsetmetatable = debugsetmetatable
1018-
10191051
local equalsObj, compareObj
10201052
if debugsetmetatable then
10211053
equalsObj = function (x, y)
@@ -1151,14 +1183,28 @@ else
11511183
if obj == nil then return "" end
11521184
local t = type(obj)
11531185
if t == "table" then
1154-
return t:ToString()
1186+
return obj:ToString()
11551187
elseif t == "boolean" then
1156-
return t and "True" or "False"
1188+
return obj and "True" or "False"
11571189
elseif t == "function" then
11581190
return "System.Delegate"
11591191
end
11601192
return tostring(obj)
11611193
end
1194+
1195+
function System.addOfNull(x, y)
1196+
if x == nil or y == nil then
1197+
return nil
1198+
end
1199+
return x + y
1200+
end
1201+
1202+
function System.subOfNull(x, y)
1203+
if x == nil or y == nil then
1204+
return nil
1205+
end
1206+
return x - y
1207+
end
11621208
end
11631209

11641210
System.equalsObj = equalsObj
@@ -1360,7 +1406,10 @@ local Nullable = {
13601406
return this:GetHashCode()
13611407
end,
13621408
clone = function (t)
1363-
return t and t:__clone__()
1409+
if type(t) == "table" then
1410+
return t:__clone__()
1411+
end
1412+
return t
13641413
end
13651414
}
13661415

‎CSharp.lua/CoreSystem.Lua/CoreSystem/Delegate.lua‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ local delegateMetaTable = setmetatable({ __index = Object, __call = makeGenericT
180180
setmetatable(Delegate, delegateMetaTable)
181181
if debugsetmetatable then
182182
debugsetmetatable(System.emptyFn, Delegate)
183+
else
184+
System.DelegateCombine = combine
185+
System.DelegateRemove = remove
183186
end
184187

185188
multicast = setmetatable({
@@ -196,7 +199,7 @@ multicast = setmetatable({
196199
__eq = function (fn1, fn2)
197200
local len1, len2 = #fn1, #fn2
198201
if len1 ~= len2 then
199-
return false
202+
return false
200203
end
201204
for i = 1, len1 do
202205
if fn1[i] ~= fn2[i] then

‎CSharp.lua/CoreSystem.Lua/CoreSystem/IO/File.lua‎

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

1717
local io = io
18-
if not io then
19-
return
20-
end
18+
if io then
2119

2220
local System = System
2321
local define = System.define
@@ -101,3 +99,5 @@ define("System.IO.File", {
10199
end
102100
end
103101
})
102+
103+
end

‎CSharp.lua/CoreSystem.Lua/CoreSystem/Number.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ if not debugsetmetatable then
413413
elseif t == "boolean" then
414414
return System.Boolean.Equals(this, other)
415415
end
416-
return this:CompareTo(other)
416+
return this:Equals(other)
417417
end
418418
end
419419

‎CSharp.lua/CoreSystem.Lua/CoreSystem/Type.lua‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,11 @@ else
419419
end
420420

421421
is = function (obj, T)
422-
return checks[getBase(obj)](obj, T)
422+
local base = getBase(obj)
423+
if base then
424+
return checks[base](obj, T)
425+
end
426+
return false
423427
end
424428
end
425429

‎CSharp.lua/LuaAst/LuaIdentifierNameSyntax.cs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,9 @@ public class LuaIdentifierNameSyntax : LuaExpressionSyntax {
6262
public static readonly LuaIdentifierNameSyntax EnumToString = "EnumToString";
6363
public static readonly LuaIdentifierNameSyntax DelegateMake = "System.fn";
6464
public static readonly LuaIdentifierNameSyntax DelegateBind = "System.bind";
65-
public static readonly LuaIdentifierNameSyntax DelegateCombine = "System.Delegate.Combine";
66-
public static readonly LuaIdentifierNameSyntax DelegateRemove = "System.Delegate.Remove";
65+
public static readonly LuaIdentifierNameSyntax DelegateCombine = "System.DelegateCombine";
66+
public static readonly LuaIdentifierNameSyntax DelegateRemove = "System.DelegateRemove";
6767
public static readonly LuaIdentifierNameSyntax IntegerDiv = "System.div";
68-
public static readonly LuaIdentifierNameSyntax IntegerDivOfNull = "System.divOfNull";
6968
public static readonly LuaIdentifierNameSyntax IntegerMod = "System.mod";
7069
public static readonly LuaIdentifierNameSyntax BitNot = "System.bnot";
7170
public static readonly LuaIdentifierNameSyntax BitNotOfNull = "System.bnotOfNull";
@@ -79,6 +78,8 @@ public class LuaIdentifierNameSyntax : LuaExpressionSyntax {
7978
public static readonly LuaIdentifierNameSyntax ShiftRightOfNull = "System.srOfNull";
8079
public static readonly LuaIdentifierNameSyntax ShiftLeft = "System.sl";
8180
public static readonly LuaIdentifierNameSyntax ShiftLeftOfNull = "System.slOfNull";
81+
public static readonly LuaIdentifierNameSyntax AddOfNull = "System.addOfNull";
82+
public static readonly LuaIdentifierNameSyntax SubOfNull = "System.subOfNull";
8283
public static readonly LuaIdentifierNameSyntax BoolOrOfNull = "System.orOfNull";
8384
public static readonly LuaIdentifierNameSyntax BoolAndOfNull = "System.andOfNull";
8485
public static readonly LuaIdentifierNameSyntax BoolXorOfNull = "System.xorOfBoolNull";

‎CSharp.lua/LuaSyntaxNodeTransform.Helper.cs‎

Lines changed: 9 additions & 1 deletion

0 commit comments

Comments
 (0)