|
@@ -120,6 +120,89 @@ public class XCTLRuntimeVariable: NSObject {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public func nativeValue(typeId: Character) throws -> Any {
|
|
|
+ switch typeId {
|
|
|
+ case "i":
|
|
|
+ guard let nativeValue = self.nativeValue as? Double else {
|
|
|
+ throw XCTLRuntimeError.cannotCastObjectToNativeTypeWhenSetProperty(runtimeType: typeId.description, nativeType: self.type.rawValue)
|
|
|
+ }
|
|
|
+ return Int32(nativeValue)
|
|
|
+ case "I":
|
|
|
+ guard let nativeValue = self.nativeValue as? Double else {
|
|
|
+ throw XCTLRuntimeError.cannotCastObjectToNativeTypeWhenSetProperty(runtimeType: typeId.description, nativeType: self.type.rawValue)
|
|
|
+ }
|
|
|
+ return UInt32(nativeValue)
|
|
|
+ case "s":
|
|
|
+ guard let nativeValue = self.nativeValue as? Double else {
|
|
|
+ throw XCTLRuntimeError.cannotCastObjectToNativeTypeWhenSetProperty(runtimeType: typeId.description, nativeType: self.type.rawValue)
|
|
|
+ }
|
|
|
+ return Int16(nativeValue)
|
|
|
+ case "S":
|
|
|
+ guard let nativeValue = self.nativeValue as? Double else {
|
|
|
+ throw XCTLRuntimeError.cannotCastObjectToNativeTypeWhenSetProperty(runtimeType: typeId.description, nativeType: self.type.rawValue)
|
|
|
+ }
|
|
|
+ return UInt16(nativeValue)
|
|
|
+ case "f":
|
|
|
+ guard let nativeValue = self.nativeValue as? Double else {
|
|
|
+ throw XCTLRuntimeError.cannotCastObjectToNativeTypeWhenSetProperty(runtimeType: typeId.description, nativeType: self.type.rawValue)
|
|
|
+ }
|
|
|
+ return Float(nativeValue)
|
|
|
+ case "d":
|
|
|
+ guard let nativeValue = self.nativeValue as? Double else {
|
|
|
+ throw XCTLRuntimeError.cannotCastObjectToNativeTypeWhenSetProperty(runtimeType: typeId.description, nativeType: self.type.rawValue)
|
|
|
+ }
|
|
|
+ return nativeValue
|
|
|
+ case "l":
|
|
|
+ guard let nativeValue = self.nativeValue as? Double else {
|
|
|
+ throw XCTLRuntimeError.cannotCastObjectToNativeTypeWhenSetProperty(runtimeType: typeId.description, nativeType: self.type.rawValue)
|
|
|
+ }
|
|
|
+ return Int64(nativeValue)
|
|
|
+ case "L":
|
|
|
+ guard let nativeValue = self.nativeValue as? Double else {
|
|
|
+ throw XCTLRuntimeError.cannotCastObjectToNativeTypeWhenSetProperty(runtimeType: typeId.description, nativeType: self.type.rawValue)
|
|
|
+ }
|
|
|
+ return UInt64(nativeValue)
|
|
|
+ case "q":
|
|
|
+ guard let nativeValue = self.nativeValue as? Double else {
|
|
|
+ throw XCTLRuntimeError.cannotCastObjectToNativeTypeWhenSetProperty(runtimeType: typeId.description, nativeType: self.type.rawValue)
|
|
|
+ }
|
|
|
+ return Int64(nativeValue)
|
|
|
+ case "Q":
|
|
|
+ guard let nativeValue = self.nativeValue as? Double else {
|
|
|
+ throw XCTLRuntimeError.cannotCastObjectToNativeTypeWhenSetProperty(runtimeType: typeId.description, nativeType: self.type.rawValue)
|
|
|
+ }
|
|
|
+ return UInt64(nativeValue)
|
|
|
+ case "c":
|
|
|
+ guard let nativeValue = self.nativeValue as? Double else {
|
|
|
+ guard let nativeValue = self.nativeValue as? String else {
|
|
|
+ throw XCTLRuntimeError.cannotCastObjectToNativeTypeWhenSetProperty(runtimeType: typeId.description, nativeType: self.type.rawValue)
|
|
|
+ }
|
|
|
+ return Int8((nativeValue.first ?? " ").utf8.first!)
|
|
|
+ }
|
|
|
+ return Int8(nativeValue)
|
|
|
+ case "C":
|
|
|
+ guard let nativeValue = self.nativeValue as? Double else {
|
|
|
+ guard let nativeValue = self.nativeValue as? String else {
|
|
|
+ throw XCTLRuntimeError.cannotCastObjectToNativeTypeWhenSetProperty(runtimeType: typeId.description, nativeType: self.type.rawValue)
|
|
|
+ }
|
|
|
+ return UInt8((nativeValue.first ?? " ").utf8.first!)
|
|
|
+ }
|
|
|
+ return UInt8(nativeValue)
|
|
|
+ case "b":
|
|
|
+ guard let nativeValue = self.nativeValue as? Bool else {
|
|
|
+ throw XCTLRuntimeError.cannotCastObjectToNativeTypeWhenSetProperty(runtimeType: typeId.description, nativeType: self.type.rawValue)
|
|
|
+ }
|
|
|
+ return nativeValue
|
|
|
+ case "@":
|
|
|
+ guard let nativeValue = self.nativeValue as? NSObject else {
|
|
|
+ throw XCTLRuntimeError.cannotCastObjectToNativeTypeWhenSetProperty(runtimeType: typeId.description, nativeType: self.type.rawValue)
|
|
|
+ }
|
|
|
+ return nativeValue
|
|
|
+ default:
|
|
|
+ throw XCTLRuntimeError.cannotCastObjectToNativeTypeWhenSetProperty(runtimeType: "\(typeId) (Unknown TypeId)", nativeType: self.type.rawValue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public func executeFunc(arg: [XCTLRuntimeVariable]) throws -> XCTLRuntimeVariable {
|
|
|
return try self.rawFunction!(arg)
|
|
|
}
|