In an external file I have a JavaScript function like this:
function getInfo(){
return {data : "Hallo", code : 42};
}
How can I call the object attributes/keys data and code in Nim? I tried the dot operator from jsffi:
import jsffi
proc getInfo(): JsObject {.importc.}
let kvRes = getInfo()
echo kvRes.data
but I always get a compile error "_Error: type mismatch: got <JsObject> but expected one of:..._".
Do I somehow have to tell Nim what attributes/keys the JsObject has? And how can I do this? Theer must be a way via jsffi...
I don't think the issue is the fact that Is doesn't have that key as it's getting a type mismatch.
Can you post the rest of the error message? Which part of the code is erroring?
type InfoObject = ref object # ref object mirrors JS object semantics
data: cstring
code: int
proc getInfo(): InfoObject {.importc.}
let kvRes = getInfo()
echo $kvRes.data