MCPcopy Create free account
hub / github.com/ceifa/wasmoon / callByteCode

Method callByteCode

src/engine.ts:100–117  ·  view source on GitHub ↗
(loader: (thread: Thread) => void)

Source from the content-addressed store, hash-verified

98
99 // WARNING: It will not wait for open handles and can potentially cause bugs if JS code tries to reference Lua after executed
100 private async callByteCode(loader: (thread: Thread) => void): Promise<any> {
101 const thread = this.global.newThread()
102 const threadIndex = this.global.getTop()
103 try {
104 loader(thread)
105 const result = await thread.run(0)
106 if (result.length > 0) {
107 // The shenanigans here are to return the first result value on the stack.
108 // Say there's 2 values at stack indexes 1 and 2. Then top is 2, result.length is 2.
109 // That's why there's a + 1 sitting at the end.
110 return thread.getValue(thread.getTop() - result.length + 1)
111 }
112 return undefined
113 } finally {
114 // Pop the read on success or failure
115 this.global.remove(threadIndex)
116 }
117 }
118}

Callers 2

doStringMethod · 0.95
doFileMethod · 0.95

Calls 5

newThreadMethod · 0.80
getTopMethod · 0.80
runMethod · 0.80
removeMethod · 0.80
getValueMethod · 0.45

Tested by

no test coverage detected