Is there a way to import a file during runtime?
I'd like to do something like:
nim c -r a.nim b.nim
so that a.nim imports b.nim.
Is there a way to do this?
Nim is not a dynamic language, but a compiled one. So you can't just import a nim file at run time. But there are always other options.
Do you want to import file based on like backend or os or some thing? Using -d:useMySQL and using compile time when useMySQL: is better. It will compile to single application though without dynamic capabilities. See: https://nim-lang.org/0.20.0/manual.html#statements-and-expressions-when-statement
Do you want to add like plugins/mods to your program? Maybe using NimScript is better - its a language that looks like nim but its actually dynamic (its what the compiler uses for macros). See: https://nim-lang.org/docs/nims.html
Do you want to add like plugins/mods but also want to keep nim speed? Its better to publish an interface and have them compile a dynamic link library, which you can load dynamically. They will use nim --app:lib to build a first then run some thing like this nim c -r a.nim b.dll. See: https://nim-lang.org/0.20.0/manual.html#foreign-function-interface-dynlib-pragma-for-export
I would like to create a tool to package the FMU file. Something like:
$ genfmu model.nim
Right now, model.nim contains something like:
fmu( "inc", "{8c4e810f-3df3-4a00-8276-176fa3c9f008}"):
....
I'd like to extract "inc" in this case. It is not very important, but if I can do it I will do it.
One option would be parsing model.nim as text file. But I'd like to know if there is a better approach.