Passing JsonNode from Nimscript to host proc

2021-12-17 Thread enthus1ast
@Araq can we have native PNode to NimNode conversion :)

Passing JsonNode from Nimscript to host proc

2021-12-17 Thread dPixie
I looked at your code quite a lot when I did my implementation. If you had had the new version back then I would probably have used it, but at this point I'm pretty much where I need to be with my own implementation so it makes less sense to replace it. But I will pilfer more ideas from your ne

Passing JsonNode from Nimscript to host proc

2021-10-03 Thread ElegantBeef
To reduce the boiler plate I highly suggest looking into my rewrite of Nimscripter(it's still not pushed as the master branch due to some bug on the Nim -> Nimscript front, but the code works for interop). A simple example is as follows: # Nim import std/json import nimscr

Passing JsonNode from Nimscript to host proc

2021-09-29 Thread dPixie
That worked out well. A bit of a hassle to do all the manual translation, but the resulting client API is clean at least so I'm fine with it :)

Passing JsonNode from Nimscript to host proc

2021-09-10 Thread Araq
To use overloading use something like: proc aInt(x: int) = discard "VM implements it" proc aString(x: string) = discard "VM implements it" proc a(x: int) = aInt(x) proc a(x: string) = aString(x) Run

Passing JsonNode from Nimscript to host proc

2021-09-10 Thread dPixie
Would you suggest that I marshal and unmarshal via string instead? I mean it is straightforward, but it takes a lot of boilerplate code on both sides. I don't mind the boilerplate on the host side, but the script side I would like to keep as clean as possible ... Can you do type overloading on

Passing JsonNode from Nimscript to host proc

2021-09-10 Thread Araq
I don't know why you don't get a compile-time error for `value: any` but it's not supported. If you want to `cast` (and you shouldn't) cast the address of the JsonNode to `int` (but `GC_Ref` it first) and use `PNode(kind: nkIntLit, intVal: address)`. And in the VM don't forget to `GC_unref` it.

Passing JsonNode from Nimscript to host proc

2021-09-10 Thread dPixie
Could I for example consider VMArgs as just bits and tell Nim that I want it to cast bit x..^1 as a JsonNode?

Passing JsonNode from Nimscript to host proc

2021-09-10 Thread dPixie
Hi @araq. Yes that is ofc one way to do it :) In fact that was basically what I was doing, I had ´setInContext( "some.dot.path", $node )´ in the script call, `proc setInContext*( path: string, value: string ) = discard` in the host function declaration and `let value = args.getString( 1 )` in th

Passing JsonNode from Nimscript to host proc

2021-09-10 Thread Araq
Well the PNode does not support JSON, you should be able to pass the JSON as a string though (PNode(kind: nkStrLit, strVal: "{json_here")).

Passing JsonNode from Nimscript to host proc

2021-09-09 Thread dPixie
I'm trying to pass a JsonNode from my script into the compiled program. I can get it to work by marshalling the data and unmarshalling on the other side, but if I switch to the strategy of getting a PNode instead of a discreet value, like with VMArgs.getStr etc, I can't then get Nim to correctly