[release]binding for FLTK C dynamic library

2019-01-15 Thread oyster
[https://github.com/retsyo/FLTK_nim](https://github.com/retsyo/FLTK_nim)/

As all my released projects, it needs more works to finish. I do hope someone, 
who knows nimlang well, can join or give suggestions


import fltk_main

proc ButtonClick (button: ptr FL_WIDGET, arg: pointer):cint {.cdecl.} =
  Fl_WidgetCopyLabel(button, "do it again")

var Win = Fl_WindowNew(320, 200, "What a shiny Window :-)")
var Btn = Fl_ButtonNew(10, 10, 120, 32, "click me")
Fl_WidgetSetCallback(Btn, ButtonClick)
Fl_WindowShow(Win)
Fl_Run()


Run

p.s. In case someone asks, 


# why not to use
1. [FreeBasic[(http://freebasic.net/)? because I need to handle many text 
in my work, but I hate to write such in any BASIC
2. [nfltk](https://github.com/Skrylar/nfltk). because I can't compile it in 
my MSYS2+MingW64 on Windows 7
3. wxWidgets? because I can't compile it in my MSYS2+MingW32 on Windows 7
3. QT? because I don't know how to compile it in my MSYS2+MingW64/32 on 
Windows 7
4. [ui](https://github.com/nim-lang/ui)? because I needs widgets to write 
spreedsheet app
5. web engine and HTML/js? I don't know how to do that. But I do find 
http://tabulator.info is pretty
6. Python + QT/wxWidgets? Yes I do use them. But I find that some app built 
with py2exe/pyinstaller does not run on any Windows version.
7. 2 space for indentation? Well, this project is opensourced, please give 
you effort to it

# why the EXE file is big?
I don't know

# how to do static link?
I don't know how to do that in nimlang and FreeBasic. Do we need to supply 
another binding?
BTW, `static link` is allowed by FLTK, and you do not need to opensource 
your code.

# why do you always test/bind blaah blaah libraries
In fact, I don't mean to do that  but I can't find a ready-to-use binding.

# License
I choose [FLTK's lincense](https://www.fltk.org/COPYING.php). But a note in 
your appliaction such as "FLTK_nim is used" is appreciated.



Run


Re: Nim and Project Euler

2019-01-15 Thread cantanima
> > What does it means? Firstly, that Nim is not popular at all. Secondly, it 
> > shows that Nim has not found an audience with people fond of mathematical 
> > and programming challenges.
> 
> Ok. Any ideas how to make it more popular? :-)

Adding a link to [Project Euler](https://projecteuler.net/) might help. :-)

(Yes, I know that DuckDuckGo is my friend, but sometimes it's the little things 
that count.)


Re: Read gzip-compressed file line by line

2019-01-15 Thread dom96
This might help: 
[https://github.com/nim-lang/zip/issues/23](https://github.com/nim-lang/zip/issues/23)


My feelings on Python and Nim

2019-01-15 Thread liwt31
Just some personal feelings on what I'm actually doing when I'm working with 
Python and Nim:

Python:

Nim:

Python is no doubt quick to write, but debugging is very painful even with 
various powerful testing and debugging tools. Nim requires me to think a lot 
about how to design my code, probably due to the almighty macro system. I 
seldom doing more than `echo` in debugging. When it compiles, I'm almost 
confident it's basically correct.

I'd say designing and writing code are the most interesting parts of 
programming. The next in line is googling language features. I think nobody 
want to spend a whole day (or week) writing tests or debugging. So it's clear 
which of the two languages is my preference.

And C BTW. I don't write a lot of C code, but It's hard to forget all those 
time I spent with GDB.

C:

The pie charts don't show total amount of time required to achieve the same 
functionality, or expressiveness, or speed, so again they are just personal 
feelings and have nothing to do with language rankings.


Re: Python Modules & why Python is better

2019-01-15 Thread dom96
It's a clickbait title, people are unlikely to only read it and be convinced 
that "okay, Nim is worse than Python".


Re: Is it possible get the export flag of a type symbol

2019-01-15 Thread slangmgh
The macro will executed in scope which define the type symbol, so the when 
compiles will be always true.


Re: Is it possible get the export flag of a type symbol

2019-01-15 Thread kaushalmodi
You can use `when compiles(TYPE SYMBOL):`.


Re: Nim nightly builds

2019-01-15 Thread kaushalmodi
> to extract tar.xz archives that don't come with mac by default.

I am taking `tar xf anything.anyarchive` taken for granted on my GNU/Linux 
system.

Doesn't that work on macOS? 


Is it possible get the export flag of a type symbol

2019-01-15 Thread slangmgh
I am writing a macro which need to know if a type symbol is exported or not. 
But the getImpl doesn't contain export flag. The following code: 


import macros
type
   T1* = object

macro m1(t: typed): untyped =
   echo t.getImpl.treeRepr

m1(T1)


Run

The result is: 


TypeDef
  Sym "T1"
  Empty
  ObjectTy
Empty
Empty
Empty


Run

Is there any way to get the export flag or other way to check if the symbol is 
exported or not? Thanks.


Re: Any advice on doing composition well in Nim

2019-01-15 Thread zetashift
Refactorings done for now, everything is working again! This is my current 
entity.nim file: 
[https://ghostbin.com/paste/s8u9k](https://ghostbin.com/paste/s8u9k) Only thing 
is that in my 


(self: Entity, target: Entity)

Run

proc I need to coerce it to 


Run

, all the time. However all is well now and I can go on to add an inventory :D.


Re: Any advice on doing composition well in Nim

2019-01-15 Thread zetashift
The error was something along the line with 


 expected seq[Entity] but got seq[Player]

Run

because my newEntity proc is something along the line


func newEntity*[T](x, y: int, chr: char, color: Color,
name: string, blocks = false, renderOrder = CORPS): T =
  result = new(T)
  result.x = x
  result.y = y
  result.chr = chr
  result.color = color
  result.name = name
  result.blocks = blocks
  result.renderOrder = renderOrder
  if T is Player: result.fighter = initFighter(12,20,30)
  if T is Orc: result.fighter = initFighter(10, 2, 3)
  if T is Kobold: result.fighter = initFighter(4, 2, 1)


Run


Re: Nim nightly builds

2019-01-15 Thread treeform
I wish Mac builds where zips just like windows. On mac double clicking a zip 
just unzips it, while you have to download special tools to extract tar.xz 
archives that don't come with mac by default.


Re: I do not perceive the advantages of Nim over C #

2019-01-15 Thread moerm
Although this thread is rather old I'll answer anyway because certain attitudes 
and questions come up again and again. It might be useful to have something to 
link to instead of saying it again and again.

Front-up: My first gut reaction to the OP was "Oh well, if he likes C# so much, 
why doesn't he just stick to it and be done". In other words: We are not 
salesmen, we love Nim and we are certainly happy if new users join but we are 
not salesmen. If you feel that language XYZ is so much better than Nim then 
simply stick to it. Simple as that. In fact, you might be perfectly right in 
thinking that XYZ is better than Nim - _for you_.

There simply is _no_ best language. A language may be the right thing for many 
users and a broad spectrum of problems but _no_ language is generally the best.

In my case (brutally compressed: reliable and safe software) I used Ada for 
quite some years and was _almost_ quite happy. In fact I've said a lot of good 
things about Ada (and still do). But there were those "buts". Nim addresses 
those. Well noted, Nim is _not_ "better than Ada". It just happens to offer a 
better trade-off for me. At least as of today Ada is (still) better in certain 
aspects but those are largely about "paranoid safety levels" (like real formal 
verifiability) and some things like much,much better docu (well, existing for 
decades that's not astonishing).

I usually do not need those "paranoid safety levels". Software is almost never 
unsafe or insecure because AES-128 was used instead of AES-256 or because it 
breaks after having ca. 2 billion users (due to signed int32), etc. Nope, stuff 
breaks due to factors like creepily lousy code, utterly lacking design (and 
care), pressure by management demanding features, features, features, and inept 
languages (often (ab)used by inept developers).

Nim addresses those issues to a large degree. And - that's very important - it 
makes it _easy, natural, and comfortable_ for the developer to write 
_considerably_ less buggy code. And by "considerably" I mean something in the 
range of 80% to 95% less bugs. In other words: Creating something like 
Heartbleed (SSL) was almost inevitable with the C code base. Creating 
Heartbleed using Nim would need a _serious_ level of carelessness or ill will.

Two other points that are relevant for quite many are:

Nim runs on quite many architectures and OSs. Unlike C# whose non-Windows 
support were ugly siblings and afterthoughts Nim wasn't designed for any 
particular architecture or OS.

Nim offers the full feature set that is needed for many applications today. 
Support for both multithreading and async/await as well as for immutable 
variables come to mind as well as many (seemingly or factually) smaller things 
like defer or a really, really nice C interface or the fact that one can target 
javascript (and end up with something that is not crappy).


Re: Any advice on doing composition well in Nim

2019-01-15 Thread nucky9
What error did you get? This code works for me: 


proc newEntity(): Entity =
  result = new Entity
  result.chr = '@'

var
  player = newEntity()
  entities: seq[Entity] = @[player]

render(entities)


Run


Re: Advent of Code 2018 megathread

2019-01-15 Thread miran
Yesterday I have sent a mail to people on our leaderboard who solved 25 tasks. 
If you're one of them and you didn't receive anything: first check your spam 
folder ;) and if there's nothing there, please contact me.

Also, even if you didn't solve all 25 tasks, but you think some solution of 
yours (or a whole repo) is very nice/elegant/fast/etc. give us a link to it and 
a short explanation why you think we should award it :)


Re: Any advice on doing composition well in Nim

2019-01-15 Thread zetashift
@nucky9 this gives me an error though I had did


var
  player = newEntity()
  entities: seq[Entity] = @[player]


Run

Error goes away if I just set it to @[] and add them manually huh


Re: Nim nightly builds

2019-01-15 Thread kaushalmodi
@araq Can you please look at this Travis failure: 
[https://travis-ci.org/nim-lang/nightlies/builds/477664313](https://travis-ci.org/nim-lang/nightlies/builds/477664313)
 (the 139.1 and 139.2 jobs)?

The windows builds are timing out even without koch testinstall running there.

Is there any possibility to trim things out of `tools/winrelease`?


Re: Nim nightly builds

2019-01-15 Thread shashlick
Looks like Windows devel jobs are timing out.

cc: @kaushalmodi


Re: Nim nightly builds

2019-01-15 Thread zolern
Very strange and sad: several last 19.9 nightlies 
([v0.19.9-9e68b2c](https://github.com/nim-lang/nightlies/releases/tag/v0.19.9-9e68b2c)
 \- 10 hours ago, 
[v0.19.9-f5cc2e2](https://github.com/nim-lang/nightlies/releases/tag/v0.19.9-f5cc2e2)
 \- two days ago, 
[v0.19.9-ab425d7](https://github.com/nim-lang/nightlies/releases/tag/v0.19.9-ab425d7)
 \- four days ago and 
[v0.19.9-11050d1](https://github.com/nim-lang/nightlies/releases/tag/v0.19.9-11050d1)
 \- five days ago) don't contain Windows assets


Re: Python Modules & why Python is better

2019-01-15 Thread liwt31
Yeah, that's my point. Maybe the `nimrtl.dll` approach should be taken for 
these python packages? I think it will probably bring back [this 
issue](https://github.com/nim-lang/Nim/issues/8405).


Re: outputHandle problem

2019-01-15 Thread herbertvwright
Thank you for sharing. :) import osproc, streams

var exeName = "sayhello"

when defined(windows):
exeName &= ".exe."

echo "exeName=",exeName

[https://www.lost-identification.com](https://www.lost-identification.com)
var tstouthdl = tstprc.outputStream()

var line = newStringOfCap(120).TaintedString

while true:


if tstouthdl.readLine(line):
echo "piped:",line

elif not running(tstprc): break


Re: Creating instance of ptr "object" from instance of "object"

2019-01-15 Thread Araq
Use `addr` or `unsafeAddr` to turn it into a `ptr`. There shouldn't be a need 
to allocate this on the heap via `alloc`.


Re: Any advice on doing composition well in Nim

2019-01-15 Thread zetashift
well in my previous iteration players,mobs,items were all entity's(with field 
of type option[Fighter]) and when rendering to screen I could just pass them 
along in one big seq: seq[Entity] the first one in that seq was the player for 
no big reason. But now I can't really put them in a seq since it wants 
specifically Entity. So my rendering code also has to change since it can't 
receive one big seq of what to draw. How could I change the rendering code to 
conform to the new style of inheritance?