@jyapayne Thank you for detailing all that! I had been using 0.18.0 because I'm
on Win and that was the version available to download in zipped binary format.
But apparently this requires new fixes in latest devel, as 0.18.1 worked nicely.
Oops, I didn't see that you changed the source. It should still work though,
but let me check.
@gibson, here's what seemed to work for me.
I changed `mylib.nim` to be like this, but I only did so to get rid of the
duplicate name:
import strutils, sequtils, os, parsecsv, streams, future
proc parseCSVListLine*(str: cstring): cstringArray {.exportc.} =
var ss =
@jyapayne I think "can easily extend the example to c++" is giving me too much
credit as I don't often deal with FFI scenarios. Does anyone have an example
where this has been done? Either wrapping a nim->c library in c++, or wrapping
a nim->c++ library in c++?
> For a library, when you need to build a heterogeneous collection of objects
> with types that can be user defined.
Why don't object variants work here, instead of OOP? I don't see the need to
introduce method for this case.
The only thing OO provides is open recursion, which I haven't needed
Here is your example translated to Nim using a method for "cry".
type
Animal* = ref object of RootObj
weightOfAnimal*: int
method cry(x: Animal) {.base.} =
echo "Animal is crying..."
type Dog* = ref object of Animal
name*: string
Sorry it should have been methods instead of proc. But seems like conversion
doesn't work.
@mratsim, Error: attempting to call undeclared routine: 'base'
You need to use procCall. It was recently document in the dev doc:
[https://github.com/nim-lang/Nim/commit/4ae9198493d85382c80a5c9436b86c5a6f3483c1](https://github.com/nim-lang/Nim/commit/4ae9198493d85382c80a5c9436b86c5a6f3483c1)
You can convert before calling:
type
Animal = ref object of RootObj
Dog = ref object of Animal
proc cry(x: Animal) {.base.} = echo "Foobar"
proc cry(x: Dog) = echo "Bark"
let x = Dog()
x.cry
x.Animal.cry
Run
I'm bumping this to keep it visible for couple of more weeks
sleep(0) won, with other mods. thanks for visiting github, made a lot of
progress lately - still no docs, but you are welcomed :)
This may happen if nim GC loses track of your json objects, "deallocates" them,
and later reuses their memory for something else. As a test, patch `json.nim`
by adding a finalizer to all allocated JsonNodes, and see if it is getting
called when it's not supposed to. Revealing your source code
jlp765, I think that link and your post is not that helpful for his question.
I think question is more related to "super" methods as it is called for example
in Ruby.
For Nim we have the procCall defined in module system, I think it may be
applied for this case, but I have never tried, as I
> But I got error message
That one is fixed.
Now regarding your first question. When calling nim function from a foreign
runtime you have to make sure that nim's GC is configured properly. Quick way
to check it is to do `GC_disable()` as the very first operation of your
externally called
15 matches
Mail list logo