英文:
Open file at compile-time [JS backend]
问题 {#heading}
我正在尝试在宏中打开文件,但我遇到了异常:
来自此处的`some`的模板/通用实例化
错误:无法在编译时"importc"变量;fopen
我的Nim代码:
import macros
macro some(): untyped =
var f = open("some.txt")
echo f.readAll()
f.close()
some()
编译命令:
nim js 文件
英文:
I'm trying open file in macro, but I got exception:
template/generic instantiation of `some` from here
Error: cannot 'importc' variable at compile time; fopen
My Nim code:
import macros
macro some(): untyped =
var f = open("some.txt")
echo f.readAll()
f.close()
some()
to compile:
nim js file
答案1 {#1}
得分: 1
使用以下代码:
staticRead("some.txt")
英文:
use
staticRead("some.txt")