Re: Render SVG To Display And Update Periodically

2016-10-22 Thread Jason C. Wells via Digitalmars-d-learn

On Saturday, 22 October 2016 at 06:18:13 UTC, Mike Parker wrote:
I think I can confidently assure you that you aren't running 
into any bugs here.


Thanks for the confirmation. It helps me to learn.

You've dived right into a multi-module projects without a full 
understanding of imports and linking. I suggest you back up a 
bit and get familiar with the process before tackling ketmar 
and Adam's stuff. If they used dub, it would be a very easy 
process. Since they don't, and you have to manage it all 
manually, you need a solid understanding of how DMD handles 
this stuff and why you are getting the error messages you see.


I'm used to compiling stuff in FreeBSD land. They have a group of 
people who take care to manage the build process (the dub part, i 
presume). What you say above is correct. I don't understand 
imports and linking. I can read the docs and they make sense, but 
I don't quite get it yet.


Thanks for writing up that simple exercise. That's next.

I was able to compile a working executable by specifying almost 
all *.d files on the command line. It didn't render an image, but 
it did pop up a window with an error message saying it couldn't 
load an image. I'm calling that victory.


Regards,
Jason


Re: Real Simple Question?

2016-10-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, October 22, 2016 21:34:36 WhatMeWorry via Digitalmars-d-learn 
wrote:
> Ok, but now I'm getting these error in my new
> mypackage/constants.d
>
> ..\common\vertex_data.d(5,15): Error: undefined identifier
> 'GLfloat'
> ..\common\vertex_data.d(53,12): Error: undefined identifier 'vec3'

mypackage/constants.d needs to import the modules for any of the types it's
using, otherwise it doesn't know about them. Modules are not textually
included like header files are in C++ (compilation times would be _way_
worse if they were), so a module only has access to what it imports, and
it's not affected by anything that imports it.

> Is there a way to just suck in the text from say a .txt file that
> would not be compiled before inclusion in main.d?

String imports is a feature, but then you end up with multiple copies of the
array in your program instead of one, and string imports are almost always
the wrong solution.

- Jonathan M Davis



Re: Dustmite can't handle my memory segfault

2016-10-22 Thread Anonymouse via Digitalmars-d-learn

On Friday, 21 October 2016 at 10:13:23 UTC, Nordlöw wrote:

#!/usr/bin/env python3

import sys
import pty

stat = pty.spawn(sys.argv[1:])
if stat == 256:
exit(42)# remap to 42
else:
exit(stat)



Assuming you want to remap 134 to 0 (success):

#!/bin/bash

cmd="$1"
shift 2>/dev/null

$cmd "$@"
[ $? = 134 ] && exit 0 || exit 1


Re: Real Simple Question?

2016-10-22 Thread WhatMeWorry via Digitalmars-d-learn
On Saturday, 22 October 2016 at 20:51:14 UTC, Jonathan M Davis 
wrote:
On Saturday, October 22, 2016 20:35:27 WhatMeWorry via 
Digitalmars-d-learn wrote:

[...]


Just put it in a separate module and then import it. e.g.

file: mypackage/constants.d
==
module mypackage.constants;

GLfloat[] vertices =
[
  // Positions  // Texture Coords
  -0.5f, -0.5f, -0.5f,  0.0f, 0.0f,
   0.5f, -0.5f, -0.5f,  1.0f, 0.0f,
   .
   (lots and lots of values)
   .
];
==

file: main.d
==
import mypackage.constants;

void main()
{
auto v = vertices;
}
==

Probably the key thing to remember is that when you compile 
your program, all of the modules that are part of your program 
rather than a separate library need to be compiled into it. 
Simply importing them isn't enough - though using either rdmd 
or dub make that easier.


This is the official documentation's page on modules:

http://dlang.org/spec/module.html

This is the chapter from Al's book that covers modules:

http://ddili.org/ders/d.en/modules.html

And you'd almost certainly benefit from simply reading Ali's 
book as a whole:


http://ddili.org/ders/d.en/index.html

- Jonathan M Davis


Ok, but now I'm getting these error in my new 
mypackage/constants.d


..\common\vertex_data.d(5,15): Error: undefined identifier 
'GLfloat'

..\common\vertex_data.d(53,12): Error: undefined identifier 'vec3'

Is there a way to just suck in the text from say a .txt file that 
would not be compiled before inclusion in main.d?







Re: Real Simple Question?

2016-10-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, October 22, 2016 20:35:27 WhatMeWorry via Digitalmars-d-learn 
wrote:
> This is probably so simple that there's no example anywhere.
>
> Basically, I've got a huge array definition (see below) which I
> reuse over and over again in different projects.
>
> GLfloat[] vertices =
> [
>  // Positions  // Texture Coords
>  -0.5f, -0.5f, -0.5f,  0.0f, 0.0f,
>   0.5f, -0.5f, -0.5f,  1.0f, 0.0f,
>   .
>   (lots and lots of values)
>   .
>
> I'd like to place this one array into a separate file and just
> include it with a one line statement in many projects.  I'm
> thinking mixins and/or imports but then if I knew how to do this,
> I wouldn't be asking.
>
> Thanks in advance.

Just put it in a separate module and then import it. e.g.

file: mypackage/constants.d
==
module mypackage.constants;

GLfloat[] vertices =
[
  // Positions  // Texture Coords
  -0.5f, -0.5f, -0.5f,  0.0f, 0.0f,
   0.5f, -0.5f, -0.5f,  1.0f, 0.0f,
   .
   (lots and lots of values)
   .
];
==

file: main.d
==
import mypackage.constants;

void main()
{
auto v = vertices;
}
==

Probably the key thing to remember is that when you compile your program,
all of the modules that are part of your program rather than a separate
library need to be compiled into it. Simply importing them isn't enough -
though using either rdmd or dub make that easier.

This is the official documentation's page on modules:

http://dlang.org/spec/module.html

This is the chapter from Al's book that covers modules:

http://ddili.org/ders/d.en/modules.html

And you'd almost certainly benefit from simply reading Ali's book as a
whole:

http://ddili.org/ders/d.en/index.html

- Jonathan M Davis



Real Simple Question?

2016-10-22 Thread WhatMeWorry via Digitalmars-d-learn

This is probably so simple that there's no example anywhere.

Basically, I've got a huge array definition (see below) which I 
reuse over and over again in different projects.


GLfloat[] vertices =
[
// Positions  // Texture Coords
-0.5f, -0.5f, -0.5f,  0.0f, 0.0f,
 0.5f, -0.5f, -0.5f,  1.0f, 0.0f,
 .
 (lots and lots of values)
 .

I'd like to place this one array into a separate file and just 
include it with a one line statement in many projects.  I'm 
thinking mixins and/or imports but then if I knew how to do this, 
I wouldn't be asking.


Thanks in advance.




Re: getting started with web server - vibe.d dub giving link error

2016-10-22 Thread Karabuta via Digitalmars-d-learn

On Saturday, 22 October 2016 at 17:21:45 UTC, Karabuta wrote:

On Saturday, 22 October 2016 at 14:50:14 UTC, aman wrote:


I just started on vibe.d on fedora and the experience is not 
pretty getting hello-world running. Please help. Below are the 
details.


[...]


I wrote a blog post at https://aberba.gtihub.io which has 
Fedora users covered. But somehow GitHub pages is not working 
so you can find it here too 
https://github.com/aberba/aberba.github.io/blob/master/_posts/2016-08-20-hello-world-app-with-the-vibe.d-web-framework.md


Sorry for the typo, blog link is rather 
https://aberba.github.io/#blog


Re: getting started with web server - vibe.d dub giving link error

2016-10-22 Thread Karabuta via Digitalmars-d-learn

On Saturday, 22 October 2016 at 14:50:14 UTC, aman wrote:


I just started on vibe.d on fedora and the experience is not 
pretty getting hello-world running. Please help. Below are the 
details.


[...]


I wrote a blog post at https://aberba.gtihub.io which has Fedora 
users covered. But somehow GitHub pages is not working so you can 
find it here too 
https://github.com/aberba/aberba.github.io/blob/master/_posts/2016-08-20-hello-world-app-with-the-vibe.d-web-framework.md


Re: Render SVG To Display And Update Periodically

2016-10-22 Thread Jason C. Wells via Digitalmars-d-learn

Now I think I finally see where my hang up is.

If B imports C, and A imports B and C, you still have to tell A 
where to find C. C doesn't go along for the ride with B. Stated 
another way, A doesn't look inside B to find C. Stated yet 
another way, B does not expose C to A.


The statement above that I did not include nanovg.d on the 
command line finally clued me in. The statement that I was being 
"picky" about what to compile similarly helped.


sh$> dmd $(find . -name "*.d") <== a joke, sort of.

Eager to make the next try. Gotta run for a bit.



getting started with web server - vibe.d dub giving link error

2016-10-22 Thread aman via Digitalmars-d-learn


I just started on vibe.d on fedora and the experience is not 
pretty getting hello-world running. Please help. Below are the 
details.


setup the env via yum (I have installed ldc).


dub init test -t vibe.d

(go ahead with default options)

cd test
dub


Performing "debug" build using ldc2 for x86_64.
vibe-d:utils 0.7.29: target for configuration "library" is up to 
date.
vibe-d:data 0.7.29: target for configuration "library" is up to 
date.
vibe-d:core 0.7.29: target for configuration "libevent" is up to 
date.
vibe-d:http 0.7.29: target for configuration "library" is up to 
date.
vibe-d:diet 0.7.29: target for configuration "library" is up to 
date.
vibe-d:mail 0.7.29: target for configuration "library" is up to 
date.
vibe-d:mongodb 0.7.29: target for configuration "library" is up 
to date.
vibe-d:redis 0.7.29: target for configuration "library" is up to 
date.
vibe-d:web 0.7.29: target for configuration "library" is up to 
date.

vibe-d 0.7.29: target for configuration "libevent" is up to date.
test ~master: building configuration "application"...
.dub/obj/app.o: In function 
`_D3std6digest3sha20__T3SHAVii512Vii160Z3SHA21_sharedStaticCtor3644FNbNiNfZv':
/usr/include/d/std/digest/sha.d:224: undefined reference to 
`_D3std8internal6digest9sha_SSSE314transformSSSE3FNaNbNiPG5kPxG64hZv'
../.dub/packages/vibe-d-0.7.29/vibe-d/libvibe-d.a(vibe.vibe.o): 
In function 
`_D3std6digest3sha20__T3SHAVii512Vii160Z3SHA21_sharedStaticCtor3643FNbNiNfZv':
/usr/include/d/std/digest/sha.d:224: undefined reference to 
`_D3std8internal6digest9sha_SSSE314transformSSSE3FNaNbNiPG5kPxG64hZv'

../.dub/packages/vibe-d-0.7.29/vibe-d/libvibe-d_redis.a(vibe.db.redis.sessionstore.o):
 In function 
`_D3std6digest3sha20__T3SHAVii512Vii160Z3SHA21_sharedStaticCtor3125FNbNiNfZv':
/usr/include/d/std/digest/sha.d:224: undefined reference to 
`_D3std8internal6digest9sha_SSSE314transformSSSE3FNaNbNiPG5kPxG64hZv'

../.dub/packages/vibe-d-0.7.29/vibe-d/libvibe-d_web.a(vibe.web.common.o): In 
function 
`_D3std6digest3sha20__T3SHAVii512Vii160Z3SHA21_sharedStaticCtor3291FNbNiNfZv':
/usr/include/d/std/digest/sha.d:224: undefined reference to 
`_D3std8internal6digest9sha_SSSE314transformSSSE3FNaNbNiPG5kPxG64hZv'

../.dub/packages/vibe-d-0.7.29/vibe-d/libvibe-d_diet.a(vibe.templ.utils.o): In 
function 
`_D3std6digest3sha20__T3SHAVii512Vii160Z3SHA21_sharedStaticCtor3140FNbNiNfZv':
/usr/include/d/std/digest/sha.d:224: undefined reference to 
`_D3std8internal6digest9sha_SSSE314transformSSSE3FNaNbNiPG5kPxG64hZv'

../.dub/packages/vibe-d-0.7.29/vibe-d/libvibe-d_http.a(vibe.http.session.o):/usr/include/d/std/digest/sha.d:224:
 more undefined references to 
`_D3std8internal6digest9sha_SSSE314transformSSSE3FNaNbNiPG5kPxG64hZv' follow
collect2: error: ld returned 1 exit status
Error: /usr/bin/gcc failed with status: 1


Re: Render SVG To Display And Update Periodically

2016-10-22 Thread ketmar via Digitalmars-d-learn
On Saturday, 22 October 2016 at 03:59:16 UTC, Jason C. Wells 
wrote:
  nanovg_demo>dmd example.d iv\arsd\color.d 
iv\arsd\simpledisplay.d iv\perf.d


  iv\perf.d(41): Error: module iv.nanovg.nanovg from file 
iv\nanovg.d must be

  imported with 'import iv.nanovg.nanovg;'

  demo.d(6): Error: module iv.nanovg.nanovg from file 
iv\nanovg.d must be

  imported with 'import iv.nanovg.nanovg;'

iv/nanovg/nanovg does not exist in the source code zip files. 
(I was reluctant to duplicate nanonvg into iv\nanovg because 
somewhere I learned that copy-pasting code is a bad idea.)


it's way easier, actually. first, you don't have to place files 
into correct directories if you are passing all of them (files) 
as arguments to dmd. they don't even have to have correct names. 
"correct" file placement is required only if dmd should search 
for modules on his own.


second: you simply didn't pass all the required modules. perf.d 
depends on core nanovg engine, but you didn't passed that to dmd.


the easiest way is just pall *all* *.d files you have to dmd. 
don't try to be picky ;-), dmd is fast enougth that you can 
safely pass alot of sources to it. and there is no harm in 
providing dmd with "extra" modules.



as for "correct" placement (if you want it), it should be like 
that:


dmd -Imodroot main.d
main.d is your main D file, modroot is dir where all modules will 
be. it should be like that:


modroot/arsd/color.d
modroot/arsd/
modroot/iv/nanovg/nanovg.d
modroot/iv/nanovg/


also, pref.d module is completely unnecessary, it is just utility 
thingy to show FPS counter. ;-)



p.s. you will also need stb_ttf port, arsd repo has it under the 
name "ttf.d".


p.p.s. the easiest way to do everything is this:
mkdir modroot
cd modroot
git clone git://repo.or.cz/iv.d.git iv
git clone https://github.com/adamdruppe/arsd.git arsd
cd ..
rdmd -Imodroot main.d

;-)


Re: Reflection: Order of fields guaranteed?

2016-10-22 Thread Michael Coulombe via Digitalmars-d-learn

On Friday, 21 October 2016 at 01:51:44 UTC, Stefan Koch wrote:
On Friday, 21 October 2016 at 01:34:44 UTC, Nick Sabalausky 
wrote:
When using reflection to obtain the fields of a class/struct, 
is there any guarantee that the order is the same as the order 
the fields are defined?


Yes they should always come in lexical order.


For classes, the spec disagrees, even though it might be true 
using current compilers.


https://dlang.org/spec/class.html#fields

"The D compiler is free to rearrange the order of fields in a 
class to optimally pack them in an implementation-defined manner. 
... Explicit control of field layout is provided by struct/union 
types, not classes."


Re: Phobos lacks a particular family of range functions...

2016-10-22 Thread Basile B. via Digitalmars-d-learn

On Friday, 21 October 2016 at 19:41:00 UTC, Basile B. wrote:

They would have for constraint

  `if (isInputRange!Range && isInputRange!(ElementType!Range))`

In case you wouldn't see directly what would they be used for, 
it's for tree-like structures. Each element in a Range is also 
an input range.


I see 3 obvious functions/templates

- the most important, make an input range from a tree-like 
range, e.g `auto treeRange(Range, DepthMode mode)(Range range) `


- a second version for bidir ranges, e.g `reverseTreeRange`

- a functional iteration algorithm: auto `deepIterate(alias 
Fun, DepthMode mode, Range, A...)(Range range, auto ref A a)`, 
which applies Fun to each element with the ability for Fun to 
act as a predicates to stop the iteration. Actually I have this 
one in my user library (this is also the reason why I post this 
today).


Unless I'm blind I cannot see anything that handles trees with 
a range interface in phobos.


If you want to get the spirit see: 
https://github.com/BBasile/iz/blob/master/import/iz/sugar.d#L1214


Now a few hours later I wonder if it could be a ndSlice job ? I 
haven't used it so far, so I ask.


Re: New to D

2016-10-22 Thread Mike Parker via Digitalmars-d-learn

On Saturday, 22 October 2016 at 08:05:12 UTC, Daniel Kozak wrote:


uint[string] dictionary;
should be
uint[size_t] dictionary;

because size_t is 32bit on x86 system and 64bit on x86_64
and you are trying to put array length to dictionary which is 
size_t


I believe you meant:

size_t[string];


Re: New to D

2016-10-22 Thread Daniel Kozak via Digitalmars-d-learn

Dne 22.10.2016 v 07:41 Mark via Digitalmars-d-learn napsal(a):


Thanks for the fast reply.

That did work. But now the error is on the line:

 dictionary[word] = newId;

I changed the value to 10, still errors. ??


everything else is as before.

thanks.

uint[string] dictionary;
should be
uint[size_t] dictionary;

because size_t is 32bit on x86 system and 64bit on x86_64
and you are trying to put array length to dictionary which is size_t


Re: Render SVG To Display And Update Periodically

2016-10-22 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 22 October 2016 at 03:59:16 UTC, Jason C. Wells 
wrote:
First, thank you for taking the time to help me with something 
that should be trivial.


I've done the above listing of file on the command line but I'm 
still stuck. I'm starting to think that I might actually be 
tripping over bugs, but I'm not confident enough to believe 
that without some confirmation.


I think I can confidently assure you that you aren't running into 
any bugs here.




I have the following directory structure from the zipfiles 
found in the repositories posted by ketmar.


nanovg_demo
- iv (was renamed from nanovg based on dmd error messages)
-- arsd (was renamed from arsd-master based on dmd error 
messages)


To proceed, I would attempt a compile. Then I would add the 
file that was producing an error to the command line and try 
again. I got this far.


Via cmd.exe:

  nanovg_demo>dmd example.d iv\arsd\color.d 
iv\arsd\simpledisplay.d iv\perf.d


  iv\perf.d(41): Error: module iv.nanovg.nanovg from file 
iv\nanovg.d must be

  imported with 'import iv.nanovg.nanovg;'

  demo.d(6): Error: module iv.nanovg.nanovg from file 
iv\nanovg.d must be

  imported with 'import iv.nanovg.nanovg;'

iv/nanovg/nanovg does not exist in the source code zip files. 
(I was reluctant to duplicate nanonvg into iv\nanovg because 
somewhere I learned that copy-pasting code is a bad idea.)


looking at kemar's repository, the nanovg.d module belongs to the 
iv.nanovg package. I don't know what the zip directory tree looks 
like, but you should have this:


- iv
-- nanovg
--- fui
--- nanovg.d
--- oui
--- package.d
--- perf.d
--- svg.d

As for the asrd stuff, it shouldn't bee in the iv tree at all. 
You should do something like this:


- import
-- iv
-- arsd

Both iv and arsd are top-level packages, so they ought to be 
independent of each other.




  demo.d(7): Error: module oui is in file 'iv\nanovg\oui.d' 
which cannot be read


oui.d does not exist anywhere. There is, however, a oui 
directory.


If you look at the source for demo.d, you'll see that it makes 
use of the oui package. That means the everything there also 
needs to be compiled and linked into the binary, but you haven't 
given those files to the compiler.





As a side note, I did have some success. I am able to compile 
nanovg.lib quite easily (from tips provided a few messages 
ago). It's when I try to compile the demo that I get stuck.


Which files did you add into nanovg.lib? Everything in the 
iv.nanovg packages and subpackages, or just the ones you use 
directly? It's best to compile all of them into the lib, then any 
that are used indirectly by each other are also available.


You've dived right into a multi-module projects without a full 
understanding of imports and linking. I suggest you back up a bit 
and get familiar with the process before tackling ketmar and 
Adam's stuff. If they used dub, it would be a very easy process. 
Since they don't, and you have to manage it all manually, you 
need a solid understanding of how DMD handles this stuff and why 
you are getting the error messages you see.


Try playing around with simple single-function modules, starting 
with something like this:


io.d:
```
void print(string s)
{
   import std.stdio : writeln;
   writeln(s);
}
```

main.d:
```
import io;
void main() { print("Hello, D!"); }
```

Compile both:
dmd main.d io.d

Compile separately:
dmd -c io.d
dmd main.d io.obj


Move the io.d module into a package, mylib.io:

- main.d
-- mylib
--- io.d

Add a module statement to the top of io.d:
```
module mylib.io;
```

Change the import in main.d:

```
import mylib.io;
```

Try again compiling together, then separately. Then move the 
mylib directory:


- main.d
-- lib
--- mylib
 io.d

Then compile together and separately again. Try with and without 
-Ilib in both cases and see what happens. Add another 
single-function module into the mix. Compile mylib as a library 
and try again.


Just keep experimenting like this until you've worked out exactly 
what's going on and what the error messages mean. Then you can 
tackle the naonvg and arsd.