Skip to content

Commit

Permalink
Memory import boolean in inspection
Browse files Browse the repository at this point in the history
Closes #66
  • Loading branch information
ashtonmeuser committed Jun 13, 2024
1 parent 1ec8f3b commit 0e221fb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/wasm-test/TestImports.gd
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func test_inspect():
"min": 0,
"max": PAGES_MAX,
"current": 0,
"import": false,
}
}
expect_eq(inspect, expected)
Expand Down
2 changes: 2 additions & 0 deletions examples/wasm-test/TestMemory.gd
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func test_inspect_memory():
var expected = {
"min": PAGE_SIZE,
"max": PAGES_MAX,
"import": false,
}
expect_eq(inspect.get("memory"), expected)
# Exported memory post-instantiation
Expand All @@ -43,6 +44,7 @@ func test_inspect_memory():
"min": PAGE_SIZE,
"max": PAGES_MAX,
"current": PAGE_SIZE,
"import": false,
}
expect_eq(inspect.get("memory"), expected)

Expand Down
29 changes: 29 additions & 0 deletions examples/wasm-test/TestMemoryImport.gd
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,35 @@ func test_module_memory():
expect(wasm.memory is StreamPeer)
expect_empty()

func test_inspect_memory_import():
# Imported memory pre-instantiation
var wasm = Wasm.new()
var buffer = read_file("memory-import")
var error = wasm.compile(buffer)
expect_eq(error, OK)
var inspect = wasm.inspect()
var expected = {
"min": PAGE_SIZE * 100,
"max": PAGES_MAX,
"import": true,
}
expect_eq(inspect.get("memory"), expected)
# Imported memory post-instantiation
var memory = WasmMemory.new()
error = memory.grow(100)
expect_eq(error, OK)
var imports = { "memory": memory }
error = wasm.instantiate(imports)
expect_eq(error, OK)
inspect = wasm.inspect()
expected = {
"min": PAGE_SIZE * 100,
"max": PAGES_MAX,
"current": PAGE_SIZE * 100,
"import": true,
}
expect_eq(inspect.get("memory"), expected)

func test_memory_import():
var memory = WasmMemory.new()
var error = memory.grow(100)
Expand Down
4 changes: 3 additions & 1 deletion src/wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,9 @@ namespace godot {
dict["import_functions"] = import_func_sigs;
dict["export_globals"] = export_global_sigs;
dict["export_functions"] = export_func_sigs;
dict["memory"] = memory != NULL && memory->get_memory() ? memory->inspect() : get_memory_limits(module, memory_context);
Dictionary dict_memory = memory != NULL && memory->get_memory() ? memory->inspect() : get_memory_limits(module, memory_context);
if (memory_context != NULL) dict_memory["import"] = memory_context->import;
dict["memory"] = dict_memory;
return dict;
}

Expand Down

0 comments on commit 0e221fb

Please sign in to comment.