mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 01:14:41 +00:00
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.
(cherry picked from commit 2ed45eb848)
This commit is contained in:
@@ -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 = ""
|
||||
|
||||
Reference in New Issue
Block a user