Add load.string to the runtime

This commit is contained in:
Rerumu
2022-08-22 21:45:48 -04:00
parent 0a9f9fd6ad
commit 9f27e956a8
2 changed files with 19 additions and 0 deletions
+13
View File
@@ -622,6 +622,7 @@ do
local math_floor = math.floor
local string_byte = string.byte
local string_char = string.char
local string_unpack = string.unpack
local reinterpret_f32_i32 = module.reinterpret.f32_i32
@@ -830,6 +831,18 @@ do
return reinterpret_f64_i64(raw)
end
function load.string(memory, addr, len)
local buffer = table.create(len)
for i = 1, len do
local raw = load_byte(memory.data, addr + i - 1)
buffer[i] = string_char(raw)
end
return table.concat(buffer)
end
function store.i32_n8(memory, addr, value)
store_byte(memory.data, addr, value)
end