@@ -88,6 +88,7 @@ public struct LuaTableRef {
88
88
}
89
89
}
90
90
91
+ // ElementType will only ever be Any or AnyHashable (needed when resolving Dictionary keys)
91
92
private func doResolveArray< ElementType> ( test: ( Array < ElementType > ) -> Bool ) -> Array < ElementType > ? {
92
93
var testArray = Array < ElementType > ( )
93
94
func good( _ val: Any ) -> Bool {
@@ -119,7 +120,11 @@ public struct LuaTableRef {
119
120
elementType = . rawpointer
120
121
acceptsAny = false
121
122
} else {
123
+ #if LUASWIFT_ANYHASHABLE_BROKEN
124
+ elementType = TypeConstraint ( intTest: good)
125
+ #else
122
126
elementType = nil
127
+ #endif
123
128
acceptsAny = false
124
129
}
125
130
@@ -162,6 +167,10 @@ public struct LuaTableRef {
162
167
result. append ( ref. guessType ( ) ) // as per tovalue() docs
163
168
case . dict, . array, . hashableDict, . hashableArray, . direct, . rawpointer: // None of these are applicable for TypeConstraint(stringTest:)
164
169
fatalError ( )
170
+ #if LUASWIFT_ANYHASHABLE_BROKEN
171
+ case . int, . int8, . int16, . int32, . int64, . uint, . uint8, . uint16, . uint32, . uint64: // Ditto
172
+ fatalError ( )
173
+ #endif
165
174
case . none: // TypeConstraint(stringTest:) failed to find any compatible type
166
175
return nil
167
176
}
@@ -193,10 +202,14 @@ public struct LuaTableRef {
193
202
resolvedVal = nil
194
203
}
195
204
case . string, . bytes, . direct, . rawpointer: // None of these are applicable for TypeConstraint(tableTest:)
196
- return nil
205
+ fatalError ( )
206
+ #if LUASWIFT_ANYHASHABLE_BROKEN
207
+ case . int, . int8, . int16, . int32, . int64, . uint, . uint8, . uint16, . uint32, . uint64: // Ditto
208
+ fatalError ( )
209
+ #endif
197
210
#if !LUASWIFT_NO_FOUNDATION
198
211
case . data: // ditto
199
- return nil
212
+ fatalError ( )
200
213
#endif
201
214
case . none: // TypeConstraint(tableTest:) failed to find any compatible type
202
215
return nil
@@ -211,6 +224,19 @@ public struct LuaTableRef {
211
224
} else if elementType == . rawpointer, let mut = value as? UnsafeMutableRawPointer {
212
225
result. append ( UnsafeRawPointer ( mut) )
213
226
} else {
227
+ #if LUASWIFT_ANYHASHABLE_BROKEN
228
+ if let elementType {
229
+ switch elementType {
230
+ case . int, . int8, . int16, . int32, . int64, . uint, . uint8, . uint16, . uint32, . uint64:
231
+ // Reuse PossibleValue's actualValue cos I'm lazy (L isn't actually used but must be specified...)
232
+ result. append ( PossibleValue ( type: elementType, testValue: value) . actualValue ( L, 0 , value) !)
233
+ continue
234
+ default :
235
+ break
236
+ }
237
+
238
+ }
239
+ #endif
214
240
// Nothing from toany has made T happy, give up
215
241
return nil
216
242
}
@@ -330,6 +356,10 @@ public struct LuaTableRef {
330
356
case . data: self . testValue = emptyData
331
357
#endif
332
358
case . direct: self . testValue = testValue!
359
+ #if LUASWIFT_ANYHASHABLE_BROKEN
360
+ case . int, . int8, . int16, . int32, . int64, . uint, . uint8, . uint16, . uint32, . uint64:
361
+ self . testValue = testValue!
362
+ #endif
333
363
case . luavalue: self . testValue = LuaValue . nilValue
334
364
case . anyhashable: self . testValue = opaqueHashable
335
365
case . rawpointer: self . testValue = dummyRawPtr
@@ -346,6 +376,18 @@ public struct LuaTableRef {
346
376
case . array, . hashableArray: fatalError ( " Can't call actualValue on an array " )
347
377
case . dict, . hashableDict: fatalError ( " Can't call actualValue on a dict " )
348
378
case . direct: return anyVal
379
+ #if LUASWIFT_ANYHASHABLE_BROKEN
380
+ case . int: return Int ( exactly: anyVal as! lua_Integer )
381
+ case . int8: return Int8 ( exactly: anyVal as! lua_Integer )
382
+ case . int16: return Int16 ( exactly: anyVal as! lua_Integer )
383
+ case . int32: return Int32 ( exactly: anyVal as! lua_Integer )
384
+ case . int64: return Int64 ( exactly: anyVal as! lua_Integer )
385
+ case . uint: return UInt ( exactly: anyVal as! lua_Integer )
386
+ case . uint8: return UInt8 ( exactly: anyVal as! lua_Integer )
387
+ case . uint16: return UInt16 ( exactly: anyVal as! lua_Integer )
388
+ case . uint32: return UInt32 ( exactly: anyVal as! lua_Integer )
389
+ case . uint64: return UInt64 ( exactly: anyVal as! lua_Integer )
390
+ #endif
349
391
case . luavalue: return L . ref ( index: index)
350
392
case . anyhashable:
351
393
if let stringRef {
@@ -416,6 +458,46 @@ public struct LuaTableRef {
416
458
if type == nil || type == . direct {
417
459
result. append ( PossibleValue ( type: . direct, testValue: value) )
418
460
}
461
+ #if LUASWIFT_ANYHASHABLE_BROKEN
462
+ if value is lua_Integer {
463
+ if type == nil || type == . int {
464
+ result. append ( PossibleValue ( type: . int, testValue: 0 as Int ) )
465
+ }
466
+ if type == nil || type == . int8 {
467
+ result. append ( PossibleValue ( type: . int8, testValue: 0 as Int8 ) )
468
+ }
469
+ if type == nil || type == . int16 {
470
+ result. append ( PossibleValue ( type: . int16, testValue: 0 as Int16 ) )
471
+ }
472
+ if type == nil || type == . int16 {
473
+ result. append ( PossibleValue ( type: . int16, testValue: 0 as Int16 ) )
474
+ }
475
+ if type == nil || type == . int32 {
476
+ result. append ( PossibleValue ( type: . int32, testValue: 0 as Int32 ) )
477
+ }
478
+ if type == nil || type == . int64 {
479
+ result. append ( PossibleValue ( type: . int64, testValue: 0 as Int64 ) )
480
+ }
481
+ if type == nil || type == . uint {
482
+ result. append ( PossibleValue ( type: . uint, testValue: 0 as UInt ) )
483
+ }
484
+ if type == nil || type == . uint8 {
485
+ result. append ( PossibleValue ( type: . uint8, testValue: 0 as UInt8 ) )
486
+ }
487
+ if type == nil || type == . uint16 {
488
+ result. append ( PossibleValue ( type: . uint16, testValue: 0 as UInt16 ) )
489
+ }
490
+ if type == nil || type == . uint16 {
491
+ result. append ( PossibleValue ( type: . uint16, testValue: 0 as UInt16 ) )
492
+ }
493
+ if type == nil || type == . uint32 {
494
+ result. append ( PossibleValue ( type: . uint32, testValue: 0 as UInt32 ) )
495
+ }
496
+ if type == nil || type == . uint64 {
497
+ result. append ( PossibleValue ( type: . uint64, testValue: 0 as UInt64 ) )
498
+ }
499
+ }
500
+ #endif
419
501
if type == nil || type == . rawpointer {
420
502
result. append ( PossibleValue ( type: . rawpointer) )
421
503
}
@@ -462,6 +544,18 @@ enum TypeConstraint {
462
544
case anyhashable // AnyHashable (or Any, in some contexts)
463
545
case luavalue
464
546
case rawpointer // UnsafeRawPointer (relevant when we have UnsafeMutableRawPointer from a [light]userdata)
547
+ #if LUASWIFT_ANYHASHABLE_BROKEN
548
+ case int
549
+ case int8
550
+ case int16
551
+ case int32
552
+ case int64
553
+ case uint
554
+ case uint8
555
+ case uint16
556
+ case uint32
557
+ case uint64
558
+ #endif
465
559
}
466
560
467
561
extension TypeConstraint {
@@ -495,6 +589,34 @@ extension TypeConstraint {
495
589
return nil
496
590
}
497
591
}
592
+
593
+ #if LUASWIFT_ANYHASHABLE_BROKEN
594
+ init ? ( intTest test: ( Any ) -> Bool ) {
595
+ if test ( 0 as Int ) {
596
+ self = . int
597
+ } else if test ( 0 as Int8 ) {
598
+ self = . int8
599
+ } else if test ( 0 as Int16 ) {
600
+ self = . int16
601
+ } else if test ( 0 as Int32 ) {
602
+ self = . int32
603
+ } else if test ( 0 as Int64 ) {
604
+ self = . int64
605
+ } else if test ( 0 as UInt ) {
606
+ self = . uint
607
+ } else if test ( 0 as UInt8 ) {
608
+ self = . uint8
609
+ } else if test ( 0 as UInt16 ) {
610
+ self = . uint16
611
+ } else if test ( 0 as UInt32 ) {
612
+ self = . uint32
613
+ } else if test ( 0 as UInt64 ) {
614
+ self = . uint64
615
+ } else {
616
+ return nil
617
+ }
618
+ }
619
+ #endif
498
620
}
499
621
500
622
fileprivate func isArrayType< T> ( _: T ? ) -> Bool {
@@ -517,9 +639,9 @@ extension Dictionary where Key == AnyHashable, Value == Any {
517
639
///
518
640
/// This function is also defined on `Dictionary<AnyHashable, AnyHashable>`, see ``luaTableToArray()-3ngmn``.
519
641
public func luaTableToArray( ) -> [ Any ] ? {
520
- var intKeys : [ Int ] = [ ]
642
+ var intKeys : [ lua_Integer ] = [ ]
521
643
for (k, _) in self {
522
- if let intKey = k as? Int , intKey > 0 {
644
+ if let intKey = k as? lua_Integer , intKey > 0 {
523
645
intKeys. append ( intKey)
524
646
} else {
525
647
// Non integer key found, doom
@@ -530,9 +652,9 @@ extension Dictionary where Key == AnyHashable, Value == Any {
530
652
// Now check all those integer keys are a sequence and build the result
531
653
intKeys. sort ( )
532
654
var result : [ Any ] = [ ]
533
- var i = 1
655
+ var i : lua_Integer = 1
534
656
while i <= intKeys. count {
535
- if intKeys [ i- 1 ] == i {
657
+ if intKeys [ Int ( i- 1 ) ] == i {
536
658
result. append ( self [ i] !)
537
659
i = i + 1
538
660
} else {
@@ -557,9 +679,9 @@ extension Dictionary where Key == AnyHashable, Value == AnyHashable {
557
679
///
558
680
/// This function is also defined on `Dictionary<AnyHashable, Any>`, see ``luaTableToArray()-7jqqs``.
559
681
public func luaTableToArray( ) -> [ AnyHashable ] ? {
560
- var intKeys : [ Int ] = [ ]
682
+ var intKeys : [ lua_Integer ] = [ ]
561
683
for (k, _) in self {
562
- if let intKey = k as? Int , intKey > 0 {
684
+ if let intKey = k as? lua_Integer , intKey > 0 {
563
685
intKeys. append ( intKey)
564
686
} else {
565
687
// Non integer key found, doom
@@ -570,9 +692,9 @@ extension Dictionary where Key == AnyHashable, Value == AnyHashable {
570
692
// Now check all those integer keys are a sequence and build the result
571
693
intKeys. sort ( )
572
694
var result : [ AnyHashable ] = [ ]
573
- var i = 1
695
+ var i : lua_Integer = 1
574
696
while i <= intKeys. count {
575
- if intKeys [ i- 1 ] == i {
697
+ if intKeys [ Int ( i- 1 ) ] == i {
576
698
result. append ( self [ i] !)
577
699
i = i + 1
578
700
} else {
0 commit comments