Skip to content

Commit b010624

Browse files
committed
...memmove, we meet again
1 parent 26b7a8e commit b010624

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

Diff for: Examples/Embedded/Sources/EmbeddedApp/_thingsThatShouldNotBeNeeded.swift

+11
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,14 @@ func strlen(_ s: UnsafePointer<Int8>) -> Int {
1616
}
1717
return p - s
1818
}
19+
20+
// TODO: why do I need this? and surely this is not ideal... figure this out, or at least have this come from a C lib
21+
@_cdecl("memmove")
22+
func memmove(_ dest: UnsafeMutableRawPointer, _ src: UnsafeRawPointer, _ n: Int) -> UnsafeMutableRawPointer {
23+
let d = dest.assumingMemoryBound(to: UInt8.self)
24+
let s = src.assumingMemoryBound(to: UInt8.self)
25+
for i in 0..<n {
26+
d[i] = s[i]
27+
}
28+
return dest
29+
}

Diff for: Examples/Embedded/Sources/EmbeddedApp/main.swift

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@ import JavaScriptKit
33
let alert = JSObject.global.alert.function!
44
let document = JSObject.global.document
55

6-
print("Document title: \(document.title.string ?? "")")
6+
print("Hello from WASM, document title: \(document.title.string ?? "")")
7+
8+
var count = 0
79

810
var divElement = document.createElement("div")
9-
divElement.innerText = "Hello, world 2"
11+
divElement.innerText = .string("Count \(count)")
1012
_ = document.body.appendChild(divElement)
1113

1214
var buttonElement = document.createElement("button")
13-
buttonElement.innerText = "Alert demo"
15+
buttonElement.innerText = "Click me"
1416
buttonElement.onclick = JSValue.object(JSClosure { _ in
15-
divElement.innerText = "Hello, world 3"
17+
count += 1
18+
divElement.innerText = .string("Count \(count)")
1619
return .undefined
1720
})
1821

0 commit comments

Comments
 (0)