我试图制作一个在Emscripten上运行的简单Nim应用程序。我还使用jsbind
来调用JavaScript函数,即console.log
。
我有以下文件test.nim
:
import jsbind
type Window* = ref object of JSObj
type Console* = ref object of JSObj
proc getConsole*(): Console {.jsimportgWithName: "function(){return console;}".}
proc log*(c: Console, a: any) {.jsimport.}
echo("Before log")
getConsole().log("Hello")
echo("After log")
我的nim.cfg
是:
@if emscripten:
cc = clang
gc = none
clang.exe = "emcc"
clang.linkerexe = "emcc"
clang.options.linker = ""
cpu = "i386"
out = "index.html"
passC = "-Iemscripten"
passL = "-Lemscripten -s TOTAL_MEMORY=335544320"
@end
然后我编译:
nim c -d:emscripten --out=index.html test.nim
当我在浏览器中打开index.html
并进入getConsole().log
调用时,我收到很多关于如何定义函数UTF8ToString
的控制台错误,程序终止:
此函数似乎是一个Emscripten前奏函数 - 我如何确保这个以及我需要的任何其他函数都包含在我的JavaScript输出中?
启用和未启用WebAssembly选项时都会发生此错误。我使用的是Nim 0.16.0和emcc 1.35.0。
这是JSFiddle of the two Emscripten output files。 (它们对于Stack Snippet来说太大了。)