Re: Nim GDB Youtube Video

2019-01-24 Thread Araq
Sorry no, we release articles and videos but the contents hardly overlap.


Using Shared Libraries written in Nim via FFI

2019-01-24 Thread b6d
Hello Nim community,

I'm enjoying Nim a great deal, but coming from a scripting language background, 
I'm having trouble figuring out some 
compiling-and-dynamic-linking-and-memory-related things on my own. Maybe you 
can help me?

I have a Linux system, on which I've written a simple library in Nim:


# mylib.nim
func fib*(a: cint): cint {.exportc, cdecl, dynlib.} =
  if a <= 0: 0 elif a == 1: 1 else: fib(a - 1) + fib(a - 2)

Run

I compile this library like so:

`nim compile --define:release --app:lib --noMain --out:mylib.so mylib.nim`

Because of reasons, I'd like to call functions in this library from within Perl 
5.

Perl lets me use shared libraries via `libffi` (Perl Package 
[FFI::Platypus](https://metacpan.org/pod/FFI::Platypus)), and the following 
seems to work:


# myprog.pl
use FFI::Platypus;
my $ffi = FFI::Platypus->new(lib=>'./mylib.so');
my $fib = $ffi->function(fib=>['int'] => 'int');
print $fib->call(10);  # prints 55

Run

However, based on my understanding of Nim's documentation I highly doubt that 
this will work in nontrivial situations, and I lack the skills to debug memory 
leaks and segfaults.

I'm wondering:

  * Do I have to call `NimMain()` first when interfacing with a shared library 
written in Nim?
  * If yes, do I have to compile and load `nimrtl` and call `nimrtl.NimMain()` 
when interfacing with more than one shared library written in Nim?
  * Do I have to protect strings returned by Nim functions from the Garbage 
Collector (by copying them before the GC can get them)?
  * Are there any other pitfalls I should be aware of?



Kind regards,

Bernhard


Nim GDB Youtube Video

2019-01-24 Thread tzekid
Link to video: 
[https://www.youtube.com/watch?v=DmYOPkI_LzU](https://www.youtube.com/watch?v=DmYOPkI_LzU)

The video is awesome - props to Arne Döring and Andres Rumpf!

Do you guys plan to release this tutorial in article form?


Re: Nim nightly builds

2019-01-24 Thread demotomohiro
Thank you!

I can download latest devel release with following command:


curl -s https://api.github.com/repos/nim-lang/nightlies/releases | grep -m 
1 "\"browser_download_url\": 
\"https://github.com/nim-lang/nightlies/releases/download/devel-.*-linux\.tar\.xz\";
 | sed -E 's/.*"browser_download_url\": \"([^"]+)\"/\1/' | wget -qi - -O 
nim.tar.xz

Run

I fixed the script that download and build nighly release Nim.

[https://github.com/demotomohiro/wandbox-builder/blob/fixnimhead/build/nim-head/install.sh](https://github.com/demotomohiro/wandbox-builder/blob/fixnimhead/build/nim-head/install.sh)

I will send PR of this fix to wandbox after testing this for few days.

I thought GitHub GraphQL API is better than REST API because I can minimize 
amount of data receive from GitHub. But GraphQL API require an OAuth token and 
putting it on public repository is not a good idea.