Re: Seq with custom fields

2017-01-04 Thread Stefan_Salewski
Thanks for that example! I think I have seen code somewhere where someone has used templates for something similar, but i can not find it currently. But I also think that inline procs should be fine. Well, for inline procs to work over module boundaries we may need link time optimization enable

Re: Seq with custom fields

2017-01-04 Thread def_pri_pub
You will need to add this proc for the add: proc add*(es: var ExtSeq; x: int) {.inline.}= es.s.add(x) The inline pragma isn't necessary, but it speeds things up a little. For using the index tokens ([ and ]), you just need to override that proc too: # Get

Seq with custom fields

2017-01-04 Thread Stefan_Salewski
I think I have still not really learned that. I think I may write something like type ExtSeq = object s: seq[int] timestamp: string var es: ExtSeq # init es.s.add(7) echo es.s[0] echo es.timestamp But I would

Re: How to compile a shared library for JNI?

2017-01-04 Thread Krux02
just when I thought, that there won't be an error anymore, I got an error, but the stacktrace is weird: > last compile:run [debug] javaOptions: List(-Djava.library.path=src/native) [info] Running scalanim.Main java.lang.RuntimeException: Nonzero exit code returned from ru

Re: How to compile a shared library for JNI?

2017-01-04 Thread bluenote
I'm on Ubuntu 14.04, but with a more recent JVM (1.8.0_74-b02). Nim version is the last tagged release 0.15.2. Regarding the repeating: You could simply use that other `run.sh` script and replace the java command by `sbt run`. Or if you want to avoid the load up time: Add `addSbtPlugin("com.git

Re: How to compile a shared library for JNI?

2017-01-04 Thread Krux02
I tried the sbt task, and no crash after more than 20 times running the `run` task. I simply cannot reproduce the error. I would like to have a run script for that task, too. Btw, what is your current platform? I am on Arch Linux, and I am on the latest development branch of Nim at the time of

Re: better example code for tutorial partI Iterators

2017-01-04 Thread bluenote
You can: * Fork the Nim repository on Github: [https://github.com/nim-lang/Nim](https://github.com/nim-lang/Nim) * Edit the file doc/tut1.rst to your liking * Use "create pull request" to contribute your modification

Re: Macros and imports

2017-01-04 Thread LeuGim
@Krux02 Thanks, I'm not against if it's really worth it. Though if it's not covered in tutorials, it is probably just too specific for tutorials: as I understand, they are for quick introduction, and the manual - for learning the language. In the manual "bind", "mixin" and "bindSym" are mentione

Re: How to compile a shared library for JNI?

2017-01-04 Thread bluenote
It varies a lot: When running the Scala example from the SBT shell it is maybe 1 out of 5. For the Java example on the debug branch I'm using the `run.sh` which simply performs 1000 iterations and terminates on a crash. I'm usually crashing within <200 iterations, sometimes in the first 10, max

Re: better example code for tutorial partI Iterators

2017-01-04 Thread Allosteric
Thank you for the reply! Just that, I'm very new here and I am not quite sure what submit a PR means. Would you mind telling me?

Re: How to compile a shared library for JNI?

2017-01-04 Thread Krux02
how often do I need to execute run from sbt? Every time I tried it, it just worked.

Re: How to compile a shared library for JNI?

2017-01-04 Thread bluenote
Good idea to emit `NimMain();`, but unfortunately it still crashes. I was wondering if it is due to either the function signature or maybe the `printf`. But using exactly your function does also crash (with a lower probability though, requires >> 100 iterations).

Re: How to compile a shared library for JNI?

2017-01-04 Thread 6in
Hi, I wrote JNI sample code. Try this. import jnim import dynlib proc Java_HelloJNI_hello*(env: JNIEnvPtr, me:jobject, arg:jstring ): jstring {.cdecl,exportc,dynlib.} = if theEnv == nil : {.emit: """ NimMain(); """.} theEnv =

Re: Why do custom types need to be reference counted objects for dynamic dispatch to work.

2017-01-04 Thread def_pri_pub
Wow. Thanks for that post. I think this belongs in the docs somewhere or on a wiki. I came across this issue when I was change the prototype of a base method but forgot to change one of the child objects. So for that specific child object it was using the base method. Would using the base pragm

Re: Why do custom types need to be reference counted objects for dynamic dispatch to work.

2017-01-04 Thread Varriount
Yes, objects need to be reference counted for methods to work. This is because only reference types can point to variable-length memory regions. Take the below code: type Animal = ref object of RootObj name: string Dog = ref object of Animal breed

Why do custom types need to be reference counted objects for dynamic dispatch to work.

2017-01-04 Thread def_pri_pub
Let's have a code example. When I'm using ref object of ... This code: type Animal = ref object of RootObj name: string method makeNoise(this: Animal) {.base.} = echo "..." type Human = ref object of Animal Dog = ref object of Ani

Nim threads vs Pthreads

2017-01-04 Thread sheosi
So I'm working with threads, and I've found the Nim threads to be somewhat limitating. Now, I'm wondering what differences are between those two? My main question is: do I get the GC for posix threads too, or I need to set up it by myself?

Re: How to compile a shared library for JNI?

2017-01-04 Thread bluenote
@Krux02: Everything prepared here: [https://github.com/bluenote10/JniScalaNimExample](https://github.com/bluenote10/JniScalaNimExample) The master branch contains a SBT + Scala setup, including a customized build task (coupled to "compile") and source monitoring so that ~test / ~compile / ~run