-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathluaRunner.ts
35 lines (31 loc) · 899 Bytes
/
luaRunner.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { initWasmModule } from './webassem'
/**
* Runs the actual code in webassembly
* @param code
* code to be run
* @returns
* the result of running the code as a promise string
*/
export const runner = (code: string): Promise<string> => {
let output: string
// configuration for wasm
let config = {
print: (function () {
return function (text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
// console.log(text);
if (text != "emsc") {
output += `${text}\n`
}
};
})(),
}
// returns the promise
return initWasmModule(config).then(Module => {
Module.ccall("run_lua", 'number', ['string'], [code])
}).then(()=> {
return output
}).catch(()=> {
return "Error"
})
}