quick and dirty pure lua webassembly interpreter
1local memory = {}
2
3local constants = require("constants")
4
5memory.Memory = {
6 pages = 0,
7 maxpages = -1,
8}
9
10function memory.Memory:new(pages)
11 local m = {}
12 setmetatable(m, {__index = self})
13 m:grow(pages)
14 return m
15end
16
17function memory.Memory:grow(pages)
18 local initStart = self.pages * constants.WASM_PAGE_SIZE
19 local initEnd = ((self.pages + pages) * constants.WASM_PAGE_SIZE) - 1
20 for i = initStart, initEnd do
21 self[i] = 0
22 end
23 self.pages = self.pages + pages
24end
25
26return memory