Wrapping the following function with c2nim:
void Write(const std::string& filename);
I get:
proc Write*(this: var ExtendedSTEPExporter; filename: string) {.importcpp: "Write",
header: "ExtendedSTEP.hxx".}
But when I use it:
stepExporter.Write("cubo.step")
I get the following error:
/home/jose/.cache/nim/ex01_d/@mex01.nim.cpp: En la función ‘void main__jNQRsZhfn9aPRyM8xvupJjw()’:
/home/jose/.cache/nim/ex01_d/@mex01.nim.cpp:131:29: error: cannot convert ‘NimStringDesc*’ to ‘const string&’ {aka ‘const std::__cxx11::basic_string<char>&’}
131 | stepExporter.Write(((NimStringDesc*) &TM__Q55yN9bJXgSKXDokIgC9bbkA_2));
| ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| NimStringDesc*
En el fichero incluido desde /home/jose/.cache/nim/ex01_d/@mex01.nim.cpp:16:
/usr/local/include/occutils/ExtendedSTEP.hxx:35:47: nota: argumento de inicialización 1 de ‘void OCCUtils::STEP::ExtendedSTEPExporter::Write(const string&)’
35 | void Write(const std::string& filename);
| ~~~~~~~~~~~~~~~~~~~^~~~~~~~
How should I interop properly with std::string?
If you don't want to wrap std::string yourself you can use one of the C++ standard library wrappers like https://github.com/sinkingsugar/nimline#standard-library-helpers
You would need to explicitly convert nim string "cubo.step" in your code into StdString object.