Skip to content

Commit

Permalink
...memmove, we meet again
Browse files Browse the repository at this point in the history
  • Loading branch information
sliemeobn committed Oct 8, 2024
1 parent 26b7a8e commit b010624
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,14 @@ func strlen(_ s: UnsafePointer<Int8>) -> Int {
}
return p - s
}

// 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
@_cdecl("memmove")
func memmove(_ dest: UnsafeMutableRawPointer, _ src: UnsafeRawPointer, _ n: Int) -> UnsafeMutableRawPointer {
let d = dest.assumingMemoryBound(to: UInt8.self)
let s = src.assumingMemoryBound(to: UInt8.self)
for i in 0..<n {
d[i] = s[i]
}
return dest
}
11 changes: 7 additions & 4 deletions Examples/Embedded/Sources/EmbeddedApp/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ import JavaScriptKit
let alert = JSObject.global.alert.function!
let document = JSObject.global.document

print("Document title: \(document.title.string ?? "")")
print("Hello from WASM, document title: \(document.title.string ?? "")")

var count = 0

var divElement = document.createElement("div")
divElement.innerText = "Hello, world 2"
divElement.innerText = .string("Count \(count)")
_ = document.body.appendChild(divElement)

var buttonElement = document.createElement("button")
buttonElement.innerText = "Alert demo"
buttonElement.innerText = "Click me"
buttonElement.onclick = JSValue.object(JSClosure { _ in
divElement.innerText = "Hello, world 3"
count += 1
divElement.innerText = .string("Count \(count)")
return .undefined
})

Expand Down

0 comments on commit b010624

Please sign in to comment.