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.
This commit is contained in:
la.panon.
2025-04-03 22:54:39 +09:00
committed by GitHub
parent 73aeac81d1
commit 2ed45eb848

View File

@@ -540,10 +540,17 @@ proc loadConfig*(stream: Stream, filename: string = "[stream]"): Config =
proc loadConfig*(filename: string): Config =
## Loads the specified configuration file into a new Config instance.
let file = open(filename, fmRead)
let fileStream = newFileStream(file)
defer: fileStream.close()
result = fileStream.loadConfig(filename)
when nimvm:
# HACK: As a workaround,
# since open() using {.importc.} is not available on NimScript.
let stringStream = newStringStream(readFile(filename))
defer: stringStream.close()
result = stringStream.loadConfig(filename)
else:
let file = open(filename, fmRead)
let fileStream = newFileStream(file)
defer: fileStream.close()
result = fileStream.loadConfig(filename)
proc replace(s: string): string =
var d = ""