From 975e8576ec8fcabfdfd5307c6c19a879fcf8795f Mon Sep 17 00:00:00 2001 From: "la.panon." Date: Thu, 3 Apr 2025 22:54:39 +0900 Subject: [PATCH] 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 2ed45eb848cbd4d9f88602adf9baf4c7b0d70961) --- lib/pure/parsecfg.nim | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/pure/parsecfg.nim b/lib/pure/parsecfg.nim index 0744d94a69..99b1c9a41e 100644 --- a/lib/pure/parsecfg.nim +++ b/lib/pure/parsecfg.nim @@ -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 = ""