diff --git a/Swiftlog/Procedure.swift b/Swiftlog/Procedure.swift index 0cf7cdd..b58c482 100644 --- a/Swiftlog/Procedure.swift +++ b/Swiftlog/Procedure.swift @@ -101,7 +101,7 @@ public class Procedure let pointers = self.name.cPointer self.cNameSize = pointers.elementCount self.cNamePointer = pointers.mutable - self.store.tfname = pointers.literal + self.store.tfname = pointers.cLiteral self.store.type = PLI_INT32(self.type.rawValue) self.store.compiletf = { diff --git a/Swiftlog/Swiftlog.swift b/Swiftlog/Swiftlog.swift index 6a894ef..f04fb1b 100644 --- a/Swiftlog/Swiftlog.swift +++ b/Swiftlog/Swiftlog.swift @@ -12,9 +12,10 @@ func startup() //Register Function "$hello_world" var helloWorld = s_vpi_systf_data() helloWorld.type = vpiSysTask - helloWorld.tfname = "$hello_world".cPointer.literal + helloWorld.tfname = "$hello_world".cPointer.cLiteral helloWorld.calltf = { (user_data: UnsafeMutablePointer?) -> Int32 in + print(user_data?.pointee) print("...and Hello from Swift!") return 0 } @@ -23,13 +24,13 @@ func startup() return 0 } helloWorld.sizetf = nil - helloWorld.user_data = nil + helloWorld.user_data = "scrambld, egge".cPointer.cMutable vpi_register_systf(&helloWorld); //Register Function "$hello_world" var showResult = s_vpi_systf_data(); showResult.type = vpiSysTask - showResult.tfname = "$show_result".cPointer.literal + showResult.tfname = "$show_result".cPointer.cLiteral showResult.compiletf = { (user_data: UnsafeMutablePointer?) -> Int32 in diff --git a/Swiftlog/Utils.swift b/Swiftlog/Utils.swift index 3c2992e..9f84b73 100644 --- a/Swiftlog/Utils.swift +++ b/Swiftlog/Utils.swift @@ -11,12 +11,13 @@ class Control extension String { - var cPointer: (literal: UnsafePointer, mutable: UnsafeMutablePointer, elementCount: Int) + var cPointer: (cLiteral: UnsafePointer, cMutable: UnsafeMutablePointer, mutable: UnsafeMutablePointer, elementCount: Int) { let utf8Representation = Array(self.utf8) let mutablePointer = UnsafeMutablePointer.allocate(capacity: utf8Representation.count) + let cMutablePointer = UnsafeMutableRawPointer(mutablePointer).bindMemory(to: CChar.self, capacity: utf8Representation.count) let immutablePointer = UnsafeRawPointer(mutablePointer).bindMemory(to: CChar.self, capacity: utf8Representation.count) let _ = UnsafeMutableBufferPointer(start: mutablePointer, count: utf8Representation.count).initialize(from: utf8Representation) - return (literal: immutablePointer, mutable: mutablePointer, elementCount: utf8Representation.count) + return (cLiteral: immutablePointer, cMutable: cMutablePointer, mutable: mutablePointer, elementCount: utf8Representation.count) } } \ No newline at end of file