forked from yanghuan/CSharp.lua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvert.lua
More file actions
790 lines (716 loc) · 20.9 KB
/
Copy pathConvert.lua
File metadata and controls
790 lines (716 loc) · 20.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
--[[
Copyright 2017 YANG Huan (sy.yanghuan@gmail.com).
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--]]
local System = System
local throw = System.throw
local cast = System.cast
local as = System.as
local trunc = System.trunc
local define = System.define
local identityFn = System.identityFn
local IConvertible = System.IConvertible
local systemToString = System.toString
local OverflowException = System.OverflowException
local FormatException = System.FormatException
local ArgumentException = System.ArgumentException
local ArgumentOutOfRangeException = System.ArgumentOutOfRangeException
local ArgumentNullException = System.ArgumentNullException
local InvalidCastException = System.InvalidCastException
local SByte = System.SByte
local Byte = System.Byte
local Int16 = System.Int16
local UInt16 = System.UInt16
local Int32 = System.Int32
local UInt32 = System.UInt32
local Int64 = System.Int64
local UInt64 = System.UInt64
local Single = System.Single
local Double = System.Double
local Boolean = System.Boolean
local Char = System.Char
local DateTime = System.DateTime
local String = System.String
local Object = System.Object
local ParseSByte = SByte.Parse
local ParseByte = Byte.Parse
local ParseInt16 = Int16.Parse
local ParseUInt16 = UInt16.Parse
local ParseInt32 = Int32.Parse
local ParseUInt32 = UInt32.Parse
local ParseInt64 = Int64.Parse
local ParseUInt64 = UInt64.Parse
local ParseSingle = Single.Parse
local ParseDouble = Double.Parse
local ParseBoolean = Boolean.Parse
local type = type
local string = string
local sbyte = string.byte
local math = math
local floor = math.floor
local tconcat = table.concat
local getmetatable = getmetatable
local tonumber = tonumber
local function toBoolean(value)
if value == nil then return false end
local typename = type(value)
if typename == "number" then
return value ~= 0
elseif typename == "string" then
return ParseBoolean(value)
elseif typename == "boolean" then
return value
else
return cast(IConvertible, value):ToBoolean()
end
end
local function toChar(value)
if value == nil then return 0 end
local typename = type(value)
if typename == "number" then
if value ~= floor(value) or value > 9223372036854775807 or value < -9223372036854775808 then
throw(InvalidCastException("InvalidCast_FromTo_Char"))
end
if value < 0 or value > 65535 then
throw(OverflowException("Overflow_Char"))
end
return value
elseif typename == "string" then
if #value ~= 1 then
throw(FormatException("Format_NeedSingleChar"))
end
return sbyte(value)
else
return cast(IConvertible, value):ToChar()
end
end
local function parseBits(s, p, n)
local i, j, v = s:find(p)
if not i then
throw(FormatException())
end
v = tonumber(v)
for i = j + 1, #s do
local ch = sbyte(s, i)
local b = ch - 48
if b < 0 or b >= n then
if not s:find("^%s*$", i) then
throw(FormatException())
end
break
end
v = v * n + b
end
return v
end
local function parseNumberFromBase(value, fromBase, min, max)
if fromBase == 2 then
value = parseBits(value, "^%s*([01])", fromBase)
elseif fromBase == 8 then
value = parseBits(value, "^%s*([0-7])", fromBase)
elseif fromBase == 16 then
local _, _, v = value:find("^%s*(%w+)%s*$")
if not v then
throw(ArgumentException("String cannot contain a minus sign if the base is not 10."))
end
local ch = sbyte(v, 2)
if ch == 120 or ch == 88 then
else
v = "0x" .. v
end
value = tonumber(v)
if value == nil then
throw(FormatException())
end
else
throw(ArgumentException("fromBase"))
end
if max == 127 and value <= 255 then
return System.toSByte(value)
end
if max == 32767 and value <= 65535 then
return System.toInt16(value)
end
if max == 2147483647 and value <= 4294967295 then
return System.toInt32(value)
end
if value < min or value > max then
throw(OverflowException())
end
return value
end
local function toNumber(value, min, max, parse, objectTo, sign)
if value == nil then return 0 end
local typename = type(value)
if typename == "number" then
if sign == false then
value = System.ToSingle(value * 1.0)
elseif sign == true then
value = value * 1.0
else
local i = value
value = trunc(value)
if value ~= i then
local dif = i - value
if value >= 0 then
if dif > 0.5 or (dif == 0.5 and value % 2 ~= 0) then
value = value + 1
end
else
if dif < -0.5 or (dif == -0.5 and value % 2 ~= 0) then
value = value - 1
end
end
end
if value < min or value > max then
throw(OverflowException())
end
end
return value
elseif typename == "string" then
if sign and sign ~= 10 and type(sign) == "number" then
return parseNumberFromBase(value, sign, min, max)
end
return parse(value)
elseif typename == "boolean" then
return value and 1 or 0
else
return objectTo(value)
end
end
local function objectToSByte(value)
return cast(IConvertible, value):ToSByte()
end
local function toSByte(value, fromBase)
return toNumber(value, -128, 127, ParseSByte, objectToSByte, fromBase)
end
local function objectToByte(value)
return cast(IConvertible, value):ToByte()
end
local function toByte(value, fromBase)
return toNumber(value, 0, 255, ParseByte, objectToByte, fromBase)
end
local function objectToInt16(value)
return cast(IConvertible, value):ToInt16()
end
local function toInt16(value, fromBase)
return toNumber(value, -32768, 32767, ParseInt16, objectToInt16, fromBase)
end
local function objectToUInt16(value)
return cast(IConvertible, value):ToUInt16()
end
local function toUInt16(value, fromBase)
return toNumber(value, 0, 65535, ParseUInt16, objectToUInt16, fromBase)
end
local function objectToInt32(value)
return cast(IConvertible, value):ToInt32()
end
local function toInt32(value, fromBase)
return toNumber(value, -2147483648, 2147483647, ParseInt32, objectToInt32, fromBase)
end
local function objectToUInt32(value)
return cast(IConvertible, value):ToUInt32()
end
local function toUInt32(value, fromBase)
return toNumber(value, 0, 4294967295, ParseUInt32, objectToUInt32, fromBase)
end
local function objectToInt64(value)
return cast(IConvertible, value):ToInt64()
end
local function toInt64(value, fromBase)
return toNumber(value, -9223372036854775808, 9223372036854775807, ParseInt64, objectToInt64, fromBase)
end
local function objectToUInt64(value)
return cast(IConvertible, value):ToUInt64()
end
local function toUInt64(value, fromBase)
return toNumber(value, 0, 18446744073709551615.0, ParseUInt64, objectToUInt64, fromBase)
end
local function objectToSingle(value)
return cast(IConvertible, value):ToSingle()
end
local function toSingle(value)
return toNumber(value, nil, nil, ParseSingle, objectToSingle, false)
end
local function objectToDouble(value)
return cast(IConvertible, value):ToDouble()
end
local function toDouble(value)
return toNumber(value, nil, nil, ParseDouble, objectToDouble, true)
end
local function toDateTime(value)
if value == nil then return DateTime.MinValue end
if getmetatable(value) == DateTime then return value end
if type(value) == "string" then return DateTime.Parse(value) end
return cast(IConvertible, value):ToDateTime()
end
local function toBaseType(ic, targetType)
local cls = targetType[1]
if cls == Boolean then return ic:ToBoolean() end
if cls == Char then return ic:ToChar() end
if cls == SByte then return ic:ToSByte() end
if cls == Byte then return ic:ToByte() end
if cls == Int16 then return ic:ToInt16() end
if cls == UInt16 then return ic:ToUInt16() end
if cls == Int32 then return ic:ToInt32() end
if cls == UInt32 then return ic:ToUInt32() end
if cls == Int64 then return ic:ToInt64() end
if cls == UInt64 then return ic:ToUInt64() end
if cls == Single then return ic:ToSingle() end
if cls == Double then return ic:ToDouble() end
if cls == DateTime then return ic:ToDateTime() end
if cls == String then return ic:ToString() end
if cls == Object then return value end
end
local function defaultToType(value, targetType)
if targetType == nil then throw(ArgumentNullException("targetType")) end
if value:GetType() == targetType then return value end
local v = toBaseType(value, targetType)
if v ~= nil then
return v
end
throw(InvalidCastException())
end
local function changeType(value, conversionType)
if conversionType == nil then
throw(ArgumentNullException("conversionType"))
end
if value == nil then
if conversionType:getIsValueType() then
throw(InvalidCastException("InvalidCast_CannotCastNullToValueType"))
end
return nil
end
local ic = as(value, IConvertible)
if ic == nil then
if value:GetType() == conversionType then
return value
end
throw(InvalidCastException("InvalidCast_IConvertible"))
end
local v = toBaseType(ic, conversionType)
if v ~= nil then
return v
end
return ic.ToType(conversionType)
end
local function toBits(num, bits)
-- returns a table of bits, most significant first.
bits = bits or math.max(1, select(2, math.frexp(num)))
local t = {} -- will contain the bits
for b = bits, 1, -1 do
local i = num % 2
t[b] = i
num = System.div(num - i, 2)
end
if bits == 64 and t[1] == 0 then
return tconcat(t, nil, 2, bits)
end
return tconcat(t)
end
local function toString(value, toBaseOrProvider, cast)
if value == nil then
return ""
end
if toBaseOrProvider then
if type(toBaseOrProvider) == "number" then
if toBaseOrProvider ~= 10 then
if cast and value < 0 then
value = cast(value)
end
end
if toBaseOrProvider == 2 then
return toBits(value)
elseif toBaseOrProvider == 8 then
return ("%o"):format(value)
elseif toBaseOrProvider == 10 then
return value .. ""
elseif toBaseOrProvider == 16 then
return ("%x"):format(value)
else
throw(ArgumentException())
end
end
end
return systemToString(value)
end
define("System.Convert", {
ToBoolean = toBoolean,
ToChar = toChar,
ToSByte = toSByte,
ToByte = toByte,
ToInt16 = toInt16,
ToUInt16 = toUInt16,
ToInt32 = toInt32,
ToUInt32 = toUInt32,
ToInt64 = toInt64,
ToUInt64 = toUInt64,
ToSingle = toSingle,
ToDouble = toDouble,
ToDateTime = toDateTime,
ChangeType = changeType,
ToString = toString,
ToStringFromChar = string.char
})
String.ToBoolean = toBoolean
String.ToChar = toChar
String.ToSByte = toSByte
String.ToByte = toByte
String.ToInt16 = toInt16
String.ToUInt16 = toUInt16
String.ToInt32 = toInt32
String.ToUInt32 = toUInt32
String.ToInt64 = toInt64
String.ToUInt64 = toUInt64
String.ToSingle = identityFn
String.ToDouble = toDouble
String.ToDateTime = toDateTime
String.ToType = defaultToType
local function throwInvalidCastException()
throw(InvalidCastException())
end
local Number = System.Number
Number.ToBoolean = toBoolean
Number.ToChar = toChar
Number.ToSByte = toSByte
Number.ToByte = toByte
Number.ToInt16 = toInt16
Number.ToUInt16 = toUInt16
Number.ToInt32 = toInt32
Number.ToUInt32 = toUInt32
Number.ToInt64 = toInt64
Number.ToUInt64 = toUInt64
Number.ToSingle = toSingle
Number.ToDouble = toDouble
Number.ToDateTime = throwInvalidCastException
Number.ToType = defaultToType
Boolean.ToBoolean = identityFn
Boolean.ToChar = throwInvalidCastException
Boolean.ToSByte = toSByte
Boolean.ToByte = toByte
Boolean.ToInt16 = toInt16
Boolean.ToUInt16 = toUInt16
Boolean.ToInt32 = toInt32
Boolean.ToUInt32 = toUInt32
Boolean.ToInt64 = toInt64
Boolean.ToUInt64 = toUInt64
Boolean.ToSingle = toSingle
Boolean.ToDouble = toDouble
Boolean.ToDateTime = throwInvalidCastException
Boolean.ToType = defaultToType
DateTime.ToBoolean = throwInvalidCastException
DateTime.ToChar = throwInvalidCastException
DateTime.ToSByte = throwInvalidCastException
DateTime.ToByte = throwInvalidCastException
DateTime.ToInt16 = throwInvalidCastException
DateTime.ToUInt16 = throwInvalidCastException
DateTime.ToInt32 = throwInvalidCastException
DateTime.ToUInt32 = throwInvalidCastException
DateTime.ToInt64 = throwInvalidCastException
DateTime.ToUInt64 = throwInvalidCastException
DateTime.ToSingle = throwInvalidCastException
DateTime.ToDouble = throwInvalidCastException
DateTime.ToDateTime = identityFn
DateTime.ToType = defaultToType
-- BitConverter
local band = System.band
local bor = System.bor
local sl = System.sl
local sr = System.sr
local div = System.div
local global = System.global
local systemToInt16 = System.toInt16
local systemToInt32 = System.toInt32
local systemToUInt64 = System.toUInt64
local arrayFromTable = System.arrayFromTable
local NotSupportedException = System.NotSupportedException
local assert = assert
local rawget = rawget
local unpack = table.unpack
local schar = string.char
-- https://github.com/ToxicFrog/vstruct/blob/master/io/endianness.lua#L30
local isLittleEndian = true
if rawget(global, "jit") then
if require("ffi").abi("be") then
isLittleEndian = false
end
else
local dump = string.dump
if dump and sbyte(dump(System.emptyFn, 7)) == 0x00 then
isLittleEndian = false
end
end
local function bytes(t)
return arrayFromTable(t, Byte)
end
local function checkIndex(value, startIndex, count)
if value == nil then throw(ArgumentNullException("value")) end
local len = #value
if startIndex < 0 or startIndex >= len then
throw(ArgumentOutOfRangeException("startIndex"))
end
if startIndex > len - count then
throw(ArgumentException())
end
end
local spack, sunpack, getBytesFromInt64, toInt64
if System.luaVersion < 5.3 then
local struct = rawget(global, "struct")
if struct then
spack, sunpack = struct.pack, struct.upack
end
if not spack then
spack = function ()
throw(NotSupportedException("not found struct"), 1)
end
sunpack = spack
end
getBytesFromInt64 = function (value)
if value <= -2147483647 or value >= 2147483647 then
local s = spack("i8", value)
return bytes({
sbyte(s, 1),
sbyte(s, 2),
sbyte(s, 3),
sbyte(s, 4),
sbyte(s, 5),
sbyte(s, 6),
sbyte(s, 7),
sbyte(s, 8)
})
end
return bytes({
band(value, 0xff),
band(sr(value, 8), 0xff),
band(sr(value, 16), 0xff),
band(sr(value, 24), 0xff),
0,
0,
0,
0
})
end
toInt64 = function (value, startIndex)
checkIndex(value, startIndex, 8)
if value <= -2147483647 or value >= 2147483647 then
throw(System.NotSupportedException())
end
if isLittleEndian then
local i = value[startIndex + 1]
i = bor(i, sl(value[startIndex + 2], 8))
i = bor(i, sl(value[startIndex + 3], 16))
i = bor(i, sl(value[startIndex + 4], 24))
return i
else
local i = value[startIndex + 8]
i = bor(i, sl(value[startIndex + 7], 8))
i = bor(i, sl(value[startIndex + 6], 16))
i = bor(i, sl(value[startIndex + 5], 24))
return i
end
end
else
spack, sunpack = string.pack, string.unpack
getBytesFromInt64 = function (value)
return bytes({
band(value, 0xff),
band(sr(value, 8), 0xff),
band(sr(value, 16), 0xff),
band(sr(value, 24), 0xff),
band(sr(value, 32), 0xff),
band(sr(value, 40), 0xff),
band(sr(value, 48), 0xff),
band(sr(value, 56), 0xff)
})
end
toInt64 = function (value, startIndex)
checkIndex(value, startIndex, 8)
if isLittleEndian then
local i = value[startIndex + 1]
i = bor(i, sl(value[startIndex + 2], 8))
i = bor(i, sl(value[startIndex + 3], 16))
i = bor(i, sl(value[startIndex + 4], 24))
i = bor(i, sl(value[startIndex + 5], 32))
i = bor(i, sl(value[startIndex + 6], 40))
i = bor(i, sl(value[startIndex + 7], 48))
i = bor(i, sl(value[startIndex + 8], 56))
return i
else
local i = value[startIndex + 8]
i = bor(i, sl(value[startIndex + 7], 8))
i = bor(i, sl(value[startIndex + 6], 16))
i = bor(i, sl(value[startIndex + 5], 24))
i = bor(i, sl(value[startIndex + 4], 32))
i = bor(i, sl(value[startIndex + 3], 40))
i = bor(i, sl(value[startIndex + 2], 48))
i = bor(i, sl(value[startIndex + 1], 56))
return i
end
end
end
local function getBytesFromBoolean(value)
return bytes({ value and 1 or 0 })
end
local function getBytesFromInt16(value)
return bytes({
band(value, 0xff),
band(sr(value, 8), 0xff),
})
end
local function getBytesFromInt32(value)
return bytes({
band(value, 0xff),
band(sr(value, 8), 0xff),
band(sr(value, 16), 0xff),
band(sr(value, 24), 0xff)
})
end
local function getBytesFromFloat(value)
local s = spack("f", value)
return bytes({
sbyte(s, 1),
sbyte(s, 2),
sbyte(s, 3),
sbyte(s, 4)
})
end
local function getBytesFromDouble(value)
local s = spack("d", value)
return bytes({
sbyte(s, 1),
sbyte(s, 2),
sbyte(s, 3),
sbyte(s, 4),
sbyte(s, 5),
sbyte(s, 6),
sbyte(s, 7),
sbyte(s, 8)
})
end
local function toBoolean(value, startIndex)
checkIndex(value, startIndex, 1)
return value[startIndex + 1] ~= 0 and true or false
end
local function toUInt16(value, startIndex)
checkIndex(value, startIndex, 2)
if isLittleEndian then
value = bor(value[startIndex + 1], sl(value[startIndex + 2], 8))
else
value = bor(sl(value[startIndex + 1], 8), value[startIndex + 2])
end
return value
end
local function toInt16(value, startIndex)
value = toUInt16(value, startIndex)
return systemToInt16(value)
end
local function toUInt32(value, startIndex)
checkIndex(value, startIndex, 4)
local i
if isLittleEndian then
i = value[startIndex + 1]
i = bor(i, sl(value[startIndex + 2], 8))
i = bor(i, sl(value[startIndex + 3], 16))
i = bor(i, sl(value[startIndex + 4], 24))
else
local i = value[startIndex + 4]
i = bor(i, sl(value[startIndex + 3], 8))
i = bor(i, sl(value[startIndex + 2], 16))
i = bor(i, sl(value[startIndex + 1], 24))
end
return i
end
local function toInt32(value, startIndex)
value = toUInt32(value, startIndex)
return systemToInt32(value)
end
local function toUInt64(value, startIndex)
value = toInt64(value, startIndex)
return systemToUInt64(value)
end
local function toSingle(value, startIndex)
checkIndex(value, startIndex, 4)
return sunpack("f", schar(unpack(value, startIndex + 1)))
end
local function toDouble(value, startIndex)
checkIndex(value, startIndex, 8)
return sunpack("d", schar(unpack(value, startIndex + 1)))
end
local function getHexValue(i)
assert(i >= 0 and i < 16, "i is out of range.")
if i < 10 then
return i + 48
end
return i - 10 + 65
end
local function toString(value, startIndex, length)
if value == nil then throw(ArgumentNullException("value")) end
local len = #value
if not startIndex then
startIndex, length = 0, #value
elseif not length then
length = len - startIndex
end
if startIndex < 0 or (startIndex >= len and startIndex > 0) then
throw(ArgumentOutOfRangeException("startIndex"))
end
if length < 0 then
throw(ArgumentOutOfRangeException("length"))
end
if startIndex + length > len then
throw(ArgumentException())
end
if length == 0 then
return ""
end
local t = {}
local len = 1
for i = startIndex + 1, startIndex + length do
local b = value[i]
t[len] = getHexValue(div(b, 16))
t[len + 1] = getHexValue(b % 16)
t[len + 2] = 45
len = len + 3
end
return schar(unpack(t, 1, len - 2))
end
local function doubleToInt64Bits(value)
assert(isLittleEndian, "This method is implemented assuming little endian with an ambiguous spec.")
local s = spack("d", value)
return (sunpack("i8", s))
end
local function int64BitsToDouble(value)
assert(isLittleEndian, "This method is implemented assuming little endian with an ambiguous spec.")
local s = spack("i8", value)
return (sunpack("d", s))
end
define("System.BitConverter", {
IsLittleEndian = isLittleEndian,
GetBytesFromBoolean = getBytesFromBoolean,
GetBytesFromInt16 = getBytesFromInt16,
GetBytesFromInt32 = getBytesFromInt32,
GetBytesFromInt64 = getBytesFromInt64,
GetBytesFromFloat = getBytesFromFloat,
GetBytesFromDouble = getBytesFromDouble,
ToBoolean = toBoolean,
ToChar = toUInt16,
ToInt16 = toInt16,
ToUInt16 = toUInt16,
ToInt32 = toInt32,
ToUInt32 = toUInt32,
ToInt64 = toInt64,
ToUInt64 = toUInt64,
ToSingle = toSingle,
ToDouble = toDouble,
ToString = toString,
DoubleToInt64Bits = doubleToInt64Bits,
Int64BitsToDouble = int64BitsToDouble
})