Skip to content

Commit

Permalink
Memory string test
Browse files Browse the repository at this point in the history
  • Loading branch information
ashtonmeuser committed Sep 13, 2023
1 parent 2632a11 commit c3839a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions examples/wasm-test/TestMemory.gd
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ func test_memory_marshal():
var result = wasm.memory.seek(offset).get_var()
expect_eq(result, data)

func test_ascii_sum():
var wasm = load_wasm("memory")
var offset = wasm.global("offset")
var string = "test_string" # String to store in Wasm memory
var sum = 0 # Sum of ASCII character values
for c in string.to_ascii_buffer(): sum += c
# Write string to memory using StreamPeer interface
# Note that Godot string marshalling prepends 32-bit string length
# See https://docs.godotengine.org/en/stable/classes/class_streampeer.html#class-streampeer-method-put-string
wasm.memory.seek(offset).put_string(string)
var result = wasm.function("ascii_sum", [])
expect_eq(result, sum)

func test_resize():
var wasm = load_wasm("memory")
var memory = wasm.inspect().get("memory").get("current")
Expand Down
Binary file modified examples/wasm-test/wasm/memory.wasm
Binary file not shown.

0 comments on commit c3839a6

Please sign in to comment.