aboutsummaryrefslogtreecommitdiff
path: root/wasm/wasm.go
diff options
context:
space:
mode:
authorXe Iaso <me@xeiaso.net>2025-02-28 13:27:20 -0500
committerXe Iaso <me@xeiaso.net>2025-02-28 13:27:20 -0500
commit070566bce7cc37e12d3dee13fe8334f65341f55f (patch)
tree8a045c5cf4126be1a85f80fd7d77aa54f0af6064 /wasm/wasm.go
parent68276af76b25560fbe9df0fcd15f73242f4b2fab (diff)
downloadx-070566bce7cc37e12d3dee13fe8334f65341f55f.tar.xz
x-070566bce7cc37e12d3dee13fe8334f65341f55f.zip
wasm: basic String operations
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'wasm/wasm.go')
-rw-r--r--wasm/wasm.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/wasm/wasm.go b/wasm/wasm.go
index 88c1a11..68acd17 100644
--- a/wasm/wasm.go
+++ b/wasm/wasm.go
@@ -6,12 +6,24 @@ import (
type String uint64
+func (value String) Address() uint32 {
+ return uint32(value >> 32)
+}
+
+func (value String) Length() uint32 {
+ return uint32((value << 32) >> 32)
+}
+
func FromString(value string) String {
position := uint32(uintptr(unsafe.Pointer(unsafe.StringData(value))))
bytes := uint32(len(value))
return String(uint64(position)<<32 | uint64(bytes))
}
+func (value String) String() string {
+ return unsafe.String((*byte)(unsafe.Pointer(uintptr(value.Address()))), value.Length())
+}
+
type Buffer uint64
func (buffer Buffer) Address() uint32 {