Ethosa
Ethosa

Reputation: 59

Open file at compile-time [JS backend]

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

Upvotes: 1

Views: 68

Answers (1)

enthus1ast
enthus1ast

Reputation: 2109

use

staticRead("some.txt")

Upvotes: 1

Related Questions