Skip to content

Commit 2ed45eb

Browse files
authored
Make loadConfig available from NimScript (#24840)
fixes #24837 I really wanted to name the variable just `stream` and leave `defer: ...` and `result =...` out, but the compiler says the variable is redefined, so this is the form.
1 parent 73aeac8 commit 2ed45eb

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lib/pure/parsecfg.nim

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -540,10 +540,17 @@ proc loadConfig*(stream: Stream, filename: string = "[stream]"): Config =
540540

541541
proc loadConfig*(filename: string): Config =
542542
## Loads the specified configuration file into a new Config instance.
543-
let file = open(filename, fmRead)
544-
let fileStream = newFileStream(file)
545-
defer: fileStream.close()
546-
result = fileStream.loadConfig(filename)
543+
when nimvm:
544+
# HACK: As a workaround,
545+
# since open() using {.importc.} is not available on NimScript.
546+
let stringStream = newStringStream(readFile(filename))
547+
defer: stringStream.close()
548+
result = stringStream.loadConfig(filename)
549+
else:
550+
let file = open(filename, fmRead)
551+
let fileStream = newFileStream(file)
552+
defer: fileStream.close()
553+
result = fileStream.loadConfig(filename)
547554

548555
proc replace(s: string): string =
549556
var d = ""

0 commit comments

Comments
 (0)