I'm following the examples of c++iface in the folder $NIM_HOME/examples and irrlicht tutorial 01. The interfacing (mainly) worked fine but not in the function that need type wchar_t. I'm already used WideCString but the compiler gave me those error.
The workaround was by replacing every function call that need wchar_t * with emit pragma, but is there any better way to do it?
nim snippet
...
device.setWindowCaption(newWideCString("Hello world! - Irrlicht Engine Demo"))
gui.addStaticText(newWideCString("Hello world! This is Irrlicht software engine!"),
rect(10, 10, 200, 22), true)
...
I changed it with
{.emit:
[device, """->setWindowCaption(L"Hello world! - Irrlich Engine Demo");
""", gui, """->addStaticText(L"Hello world! This Irrlicht software engine!",
irr::core::rect<irr::s32>(10, 10, 200, 22), true);
"""].}
Also, the opposite was error too (when calling driver.getName(), the c++ returned a wchar_t * too but cannot be cast to NimStringDesc, NCString, or NI16)
compiler that I used is cl
$ cl /?
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24213.1 for x64
...
Thanks.
Dunno, maybe something like
type
wchar_t {.importc.} = object
template abom(x: untyped): untyped = cast[ptr wchar_t](x)
device.setWindowCaption(abom newWideCString("Hello world! - Irrlicht Engine Demo"))
Thanks, it's more idiomatic than emit pragma.
I'm not sure if the error happened only for this compiler or not, I'll try some simple example later for interfacing with c for this wide char type.