Re: isTemplate and isValue?

2015-12-12 Thread Basile B. via Digitalmars-d-learn
On Saturday, 12 December 2015 at 14:17:52 UTC, Shriramana Sharma 
wrote:
Hello. Re my posting just now re AliasSeq being able to contain 
a template identifier too, I wonder whether it is possible to 
have a std.traits template to identify whether something is a 
template or not?


In connection with this, while is() is there to determine 
whether something is a type or not, what should I use to 
determine whether something is a value or not?


These would be useful to identify the kind of a member of an 
AliasSeq...


It's already there:

http://dlang.org/spec/traits.html#isTemplate


Re: Error 42: Symbol Undefined __lseeki64

2015-12-17 Thread Basile B. via Digitalmars-d-learn

On Thursday, 17 December 2015 at 04:11:56 UTC, tcak wrote:
On Wednesday, 16 December 2015 at 18:30:41 UTC, Byron Heads 
wrote:
On Wednesday, 16 December 2015 at 18:21:33 UTC, Byron Heads 
wrote:

On Wednesday, 16 December 2015 at 18:14:35 UTC, Byron Heads
I searched the function "__lseek64" under /usr/include/dmd" 
with "grep -R __lseek64", but nothing is found. I work on Linux 
64-bit. So, I guess it is either Windows related, or 32bit dmd 
related. "lseek64" is found in "unistd.d", but this doesn't 
solve any problem.


Of course it's windows related. 'lseek' is a posix function. 
There's a version/#define somewhere that's missing, maybe in the 
C binding, because under Windows lseek is 'SetFilePointer'.


But I'm not able to find it...
:/


Re: %s not producing string representation of enum?

2015-12-10 Thread Basile B. via Digitalmars-d-learn

On Thursday, 10 December 2015 at 14:46:26 UTC, Basile B. wrote:
On Thursday, 10 December 2015 at 14:24:43 UTC, Shriramana 
Sharma wrote:
Hello. I'm using DMD 2.069.2. As per 
http://ddili.org/ders/d.en/enum.html the following code is 
supposed to output the *names* of the suits:


import std.stdio;
void main()
{
enum Suit { spades, hearts, diamonds, clubs }
foreach (suit; Suit.min .. Suit.max + 1) { writefln("%s", 
suit); }

}

But I'm getting 0 1 2 3. Kindly advise.


You should rather use std.traits.EnumMembers to iterate the


By the way I should use format() in the example, but writeln() 
use the same methods:



import std.stdio;

void main(string[] args)
{
import std.traits: EnumMembers;
enum Suit { spades = 23.2, hearts = 8.3, diamonds = 12.56, 
clubs = 1.3 }

foreach(i,member; EnumMembers!Suit)
{
writefln("%s", member);
writefln("%f", member);
writeln(i);
}
}




Re: %s not producing string representation of enum?

2015-12-10 Thread Basile B. via Digitalmars-d-learn
On Thursday, 10 December 2015 at 14:24:43 UTC, Shriramana Sharma 
wrote:
Hello. I'm using DMD 2.069.2. As per 
http://ddili.org/ders/d.en/enum.html the following code is 
supposed to output the *names* of the suits:


import std.stdio;
void main()
{
enum Suit { spades, hearts, diamonds, clubs }
foreach (suit; Suit.min .. Suit.max + 1) { writefln("%s", 
suit); }

}

But I'm getting 0 1 2 3. Kindly advise.


You should rather use std.traits.EnumMembers to iterate the 
members of an enum:



import std.stdio;

void main(string[] args)
{
import std.traits: EnumMembers;
enum Suit { spades, hearts, diamonds, clubs }
foreach(member; EnumMembers!Suit)
writeln(member);
}


it can also counts


import std.stdio;

void main(string[] args)
{
import std.traits: EnumMembers;
enum Suit { spades = 23.2, hearts, diamonds, clubs }
foreach(i,member; EnumMembers!Suit)
{
writeln(member);
writeln(i);
}
}


which is interesting to get the rank of a member, considering 
that the rank is not always the same as the value (like here, 
it's a float ;) ).


Re: GTKD Cairo get pixel color

2016-01-04 Thread Basile B. via Digitalmars-d-learn

On Friday, 1 January 2016 at 22:00:04 UTC, TheDGuy wrote:

On Friday, 1 January 2016 at 19:32:40 UTC, Basile B. wrote:
On Wednesday, 30 December 2015 at 23:20:23 UTC, Basile B. 
wrote:

On Wednesday, 30 December 2015 at 20:44:44 UTC, TheDGuy wrote:

Hello,

is there any way to get the pixel color of a single pixel by 
x and y coordinates of a context?


render to a png back buffer.

see cairo_image_surface_create_for_data

then you'll be able to access the data and, at the same time, 
to blit your buffer to screen.



Actually I was thinking to a user defined buffer type:

struct SurfaceBuffer
{
void* data; // used as param to create the surface
Rgba[] opIndex(size_t index);
Rgba[][] scanline();
}

that you would pass as data in 
cairo_image_surface_create_for_data().


But gtk certainly has pitcure classes with the typical 
scanline method and that you could use in 
cairo_image_surface_create_for_data.


Ahm, i am not quite sure if you and [Mike Wey] talk about the 
same thing. And i posted the error message in my last post when 
i try to call "cairo_image_surface_create_for_data". I still 
don't know where i am able to call the function?


I've not followed the conversation since last time, but you can 
have a look at this:


https://github.com/BBasile/kheops/blob/master/src/kheops/bitmap.d#L143

this is how I do with Cairo only (even x11 is not implied since 
it's just a bitmap).
Then I can access pixels (for example to make shadows or blurs 
etc.) and do vectorial drawings as well with a context for the 
bitmap surface.


Re: Size of Compiled Program

2016-01-04 Thread Basile B. via Digitalmars-d-learn
On Monday, 4 January 2016 at 13:49:03 UTC, Martin Tschierschke 
wrote:

When I was writing a small speed test - D versus Ruby,
calculating the first n prime numbers, I realized, that for 
small n

Ruby may be faster, than compiling and executing with D.
But for n = 1,000,000 D outperforms Ruby by app. 10x.

Looking at the size of my prime executable, it was around 800 
kB with DMD

and even with optimization and "gdc -Os" > 1 MB.
Why is such a short program resulting in a so big binary?


You have the runtime and phobos compiled with your program. But 
also:

- if debug info are generated this increases the size.
- if bounds checking is turned off there is some code generated 
for each array operation
- if contracts are not off there is a lot of assertion that will 
be generated


see also some clues here:
http://forum.dlang.org/post/mailman.20.1441974998.22025.digitalmars-d-le...@puremagic.com




Re: GTKD Cairo get pixel color

2016-01-05 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 5 January 2016 at 17:16:10 UTC, TheDGuy wrote:

On Tuesday, 5 January 2016 at 16:43:00 UTC, Basile B. wrote:

On Tuesday, 5 January 2016 at 16:25:01 UTC, TheDGuy wrote:

But how do i know which line or column my pixel is in?

- study D operator overloading, I've given you the solution.


And what is 't' in 'opIndexAssign'?
- t is what you want to assign. It can be an uint or maybe a 
float[4]. Look at my bitmap class.


Okay, but what is this?

"import iz.memory, iz.streams, iz.properties;"

I dont' understand what "MemoryStream" is?


MemoryStream is a managed pointer with methods to read and write 
at a particlular postion. In the Bitmap class I often refer to 
.memory which is just the managed pointer.


- iz.properties is used to anotate what has to be serialiazed or 
not and it's pointless here (@Set @Get).
- iz.memory is just imported because I use (construct!T) instead 
of "new" to allocate a class instance.


But these are implementation details. Just try to imagine that 
you manage the bitmap data yourself with realloc/free...


Re: GTKD Cairo get pixel color

2016-01-05 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 5 January 2016 at 15:04:57 UTC, TheDGuy wrote:
But i get "only one index allowed to index char". So it looks 
like there is no 2D array but just a char.

If i try like this:


The data is just a contiguous memory area. You have to implement 
your own opIndexAssign()/opIndex() to write/read a pixel at 
[line, column].


This is basically `dataPtr + (line * width + column) * 4`.

---
auto opIndex(size_t line, size_t column)
{
auto ptr = basePtr + (line * width + column) * 4;
// return something at "ptr".
}

void opIndexAssign(T)(auto ref T t, size_t line, size_t column)
{
auto ptr = basePtr + (line * width + column) * 4;
// assign t at "ptr".
}
---

(assuming format is ARGB, so 32bit, so "*4").


Re: GTKD Cairo get pixel color

2016-01-05 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 5 January 2016 at 16:25:01 UTC, TheDGuy wrote:

But how do i know which line or column my pixel is in?

- study D operator overloading, I've given you the solution.


And what is 't' in 'opIndexAssign'?
- t is what you want to assign. It can be an uint or maybe a 
float[4]. Look at my bitmap class.




Re: GTKD Cairo get pixel color

2016-01-05 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 5 January 2016 at 17:37:04 UTC, TheDGuy wrote:

On Tuesday, 5 January 2016 at 17:34:06 UTC, Basile B. wrote:

On Tuesday, 5 January 2016 at 17:16:10 UTC, TheDGuy wrote:

On Tuesday, 5 January 2016 at 16:43:00 UTC, Basile B. wrote:

[...]


Okay, but what is this?

"import iz.memory, iz.streams, iz.properties;"

I dont' understand what "MemoryStream" is?


MemoryStream is a managed pointer with methods to read and 
write at a particlular postion. In the Bitmap class I often 
refer to .memory which is just the managed pointer.


- iz.properties is used to anotate what has to be serialiazed 
or not and it's pointless here (@Set @Get).
- iz.memory is just imported because I use (construct!T) 
instead of "new" to allocate a class instance.


But these are implementation details. Just try to imagine that 
you manage the bitmap data yourself with realloc/free...


No offense, but why is the same thing done in 3 lines in C++ 
but needs 200 lines in D?


IDK, except D I only speek/talk Object Pascal (FPC/Delphi).


Re: GTKD Cairo get pixel color

2016-01-05 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 5 January 2016 at 18:19:08 UTC, Basile B. wrote:

On Tuesday, 5 January 2016 at 17:39:41 UTC, Basile B. wrote:

IDK, except D I only speek/talk Object Pascal (FPC/Delphi).


"I didn't know, apart D, I only speak/talk Object Pascal 
(FPC/Delphi)."

Was what I meant. ^^


https://www.youtube.com/watch?v=Mlpl-RzsCck


Re: GTKD Cairo get pixel color

2016-01-05 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 5 January 2016 at 17:39:41 UTC, Basile B. wrote:

IDK, except D I only speek/talk Object Pascal (FPC/Delphi).


"I didn't know, apart D, I only speak/talk Object Pascal 
(FPC/Delphi)."

Was what I meant. ^^




Re: Lots of D code

2016-01-05 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 23 December 2015 at 00:59:53 UTC, steven kladitis 
wrote:
I have 843 programs written in D. 805 actually create an 32 bit 
exe in windows 10. I am running the latest D.  Some just start 
to link and the linker disappears. Some just have issues I am  
not able figure out. I can attach the code and scripts I use to 
compile and run these. If anyone is willing to figure out why 
the 38 do not compile, I would appreciate code that works.  The 
execute_bf_v2.d creates an exe that is small but takes about 1 
hour to link on a 12 core processor with 64g of ram as 14tb of 
disk space. The rest link very fast.  If anyone is interested, 
let me know.  I would love to get the 38 working.  Also there 
are a few that produce incorrect answers.  The Generate_maze.d  
produces all but the last line of the maze.  I added a line 
just for it.  I do not understand why.  All of the programs are 
from RosettaCode.org. The  script to compile them generates a 
log file and you will see a few that the linker just stops 
No idea why. A few have 64K link errors no idea why.



TIA,
Steven


What's up with those 38 programs ?


Re: Convert a hex string into a ubyte[] or OutBuffer

2016-01-07 Thread Basile B. via Digitalmars-d-learn

On Thursday, 7 January 2016 at 21:00:06 UTC, zabruk70 wrote:

Hello.
In modern phobos ver 2.069.1 exists template hexString

https://dlang.org/phobos/std_conv.html#.hexString

to convert hex string to bytes.
It works in compile time only.
But what if i need it in run time?

Is the answer in this topic still best way?
Or now we have some function/template in phobos?

Thanks.


Damn, I've been trapped, thread exhumated from 2014 ...


Re: Convert a hex string into a ubyte[] or OutBuffer

2016-01-07 Thread Basile B. via Digitalmars-d-learn

On Thursday, 7 January 2016 at 21:00:06 UTC, zabruk70 wrote:

Hello.
In modern phobos ver 2.069.1 exists template hexString

https://dlang.org/phobos/std_conv.html#.hexString

to convert hex string to bytes.
It works in compile time only.
But what if i need it in run time?

Is the answer in this topic still best way?
Or now we have some function/template in phobos?

Thanks.


The original PR that proposed a template to translate x strings 
as a template contained the Run-Time version too. Archeology...


https://github.com/D-Programming-Language/phobos/pull/3058/files#diff-ebd0b0e1b0171283328bda4a570616b9R5570

But otherwise take the solution by anonymous. The thing with 
hexString is just that it handles ascii whites so it can be used 
to process hex dumps directly using the import expression:


---
static ubyte[] dumpToArray = hexString!import(dump.txt);
---

Which was maybe a "faddishness" from Walter (no offense here, but 
it's clear that D is a bit over the top as for the profusion of 
string literals: x"", r"", ``, q{}, ""w, ""d, delimited, here 
doc, ...).


:)




Re: version in enum

2016-01-09 Thread Basile B. via Digitalmars-d-learn

On Saturday, 9 January 2016 at 12:43:32 UTC, Øivind wrote:

Hi,

Why doesn't this work? Seems like it should:

enum {
A = 1,
version(xx) {
B = 2
}
}


It's not allowed in the grammar but I agree with you, it could be 
useful. Recent example where it could:


---
enum VirtualKey
{
   version(linux) VK_UP = 0;  version(Win32) VK_UP = 1,
   
}
---

a solution is to define a manifest constant depending on your 
version() and to use a ternary expression in the enum definition. 
For me then this works:


---
version(linux) enum ver = true;
else enum ver = false;

enum VirtualKey
{
   VK_UP = (ver) ? 0 : 1,
}
---

Not ideal but it works.


Re: GTKD Cairo get pixel color

2016-01-05 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 5 January 2016 at 21:24:51 UTC, Ola Fosheim Grøstad 
wrote:

On Tuesday, 5 January 2016 at 21:01:55 UTC, Basile B. wrote:

Awww... I'm so sorry.


https://youtu.be/uyMUck2RRjw


du bist normal oder idiot ?

https://www.youtube.com/watch?v=nGLwBCMSXys


Re: GTKD Cairo get pixel color

2016-01-05 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 5 January 2016 at 22:08:52 UTC, Ola Fosheim Grøstad 
wrote:

On Tuesday, 5 January 2016 at 22:02:47 UTC, Basile B. wrote:

du bist normal oder idiot ?


https://youtu.be/7kjTXMecCrM

Ding dong!


https://en.wikipedia.org/wiki/Turing_Award

Si tu crois que tu es un génie, il y a de forte chance que tu 
sois un gros bouffon.


Re: GTKD Cairo get pixel color

2016-01-05 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 5 January 2016 at 19:13:35 UTC, Basile B. wrote:

On Tuesday, 5 January 2016 at 18:19:08 UTC, Basile B. wrote:

On Tuesday, 5 January 2016 at 17:39:41 UTC, Basile B. wrote:

IDK, except D I only speek/talk Object Pascal (FPC/Delphi).


"I didn't know, apart D, I only speak/talk Object Pascal 
(FPC/Delphi)."

Was what I meant. ^^


https://www.youtube.com/watch?v=Mlpl-RzsCck


https://www.youtube.com/watch?v=ZKMc_NgzFxE

  .-. .-.
  | | | |
  | | | |
  | | | |
 _| |_   _| |_
| | | |-.   | |_| |-.
   /| ` |  / )| |_|_|
  | |   | | |-' `-^-'
  | | | ||  |
  \ / \ '   /
   |   |   |   |
   |   |   |   |


Re: GTKD Cairo get pixel color

2016-01-05 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 5 January 2016 at 19:47:02 UTC, Basile B. wrote:

On Tuesday, 5 January 2016 at 19:13:35 UTC, Basile B. wrote:

On Tuesday, 5 January 2016 at 18:19:08 UTC, Basile B. wrote:

On Tuesday, 5 January 2016 at 17:39:41 UTC, Basile B. wrote:

IDK, except D I only speek/talk Object Pascal (FPC/Delphi).


"I didn't know, apart D, I only speak/talk Object Pascal 
(FPC/Delphi)."

Was what I meant. ^^


https://www.youtube.com/watch?v=Mlpl-RzsCck


https://www.youtube.com/watch?v=ZKMc_NgzFxE

  .-. .-.
  | | | |
  | | | |
  | | | |
 _| |_   _| |_
| | | |-.   | |_| |-.
   /| ` |  / )| |_|_|
  | |   | | |-' `-^-'
  | | | ||  |
  \ / \ '   /
   |   |   |   |
   |   |   |   |


Awww... I'm so sorry.
It was the wedding of Michel...Basically I wanted to ruin the 
wedding of another person...but I don't know you...wrong ruining.


Re: GTKD Cairo get pixel color

2016-01-01 Thread Basile B. via Digitalmars-d-learn

On Wednesday, 30 December 2015 at 23:20:23 UTC, Basile B. wrote:

On Wednesday, 30 December 2015 at 20:44:44 UTC, TheDGuy wrote:

Hello,

is there any way to get the pixel color of a single pixel by x 
and y coordinates of a context?


render to a png back buffer.

see cairo_image_surface_create_for_data

then you'll be able to access the data and, at the same time, 
to blit your buffer to screen.



Actually I was thinking to a user defined buffer type:

struct SurfaceBuffer
{
void* data; // used as param to create the surface
Rgba[] opIndex(size_t index);
Rgba[][] scanline();
}

that you would pass as data in 
cairo_image_surface_create_for_data().


But gtk certainly has pitcure classes with the typical scanline 
method and that you could use in 
cairo_image_surface_create_for_data.


Re: GTKD Cairo get pixel color

2016-01-05 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 5 January 2016 at 23:36:16 UTC, Ola Fosheim Grøstad 
wrote:

On Tuesday, 5 January 2016 at 23:26:12 UTC, Basile B. wrote:

access to pix is easy...


This is the learn forum. Maybe one should be able to figure it 
out without asking, but there is nothing wrong with asking in 
depth on this forum. The threshold for asking should be low in 
here. At worst, nobody answers or as it turns out, posts a 
youtube video...


Until a certain "time" my answers were useful. But I recognize 
that after this "time" I've managed to turn the topic into 
something totally delirious because, to be honest I was completly 
sratched by alcohool. I'm sorry but life is so... I'm mostly 
serious here but sometimes I draft. Most of the time it's 
obvious...sorry if you didn't get this...IRL you directly get 
that the guy is high, on the internet it's not always so obvious.


Re: GTKD Cairo get pixel color

2016-01-05 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 5 January 2016 at 22:40:22 UTC, Basile B. wrote:
On Tuesday, 5 January 2016 at 22:08:52 UTC, Ola Fosheim Grøstad 
wrote:

On Tuesday, 5 January 2016 at 22:02:47 UTC, Basile B. wrote:

du bist normal oder idiot ?


https://youtu.be/7kjTXMecCrM

Ding dong!


https://en.wikipedia.org/wiki/Turing_Award

Si tu crois que tu es un génie, il y a de forte chance que tu 
sois un gros bouffon.


https://youtu.be/3hrfjSaW8TQ?t=7m54s

At a certain point, I hope we agree about "when good stuff are 
over the top".


access to pix is easy...


Re: Variable below zero but if statement doesn't grab?

2016-01-05 Thread Basile B. via Digitalmars-d-learn

On Monday, 28 December 2015 at 18:02:53 UTC, jkpl wrote:

On Monday, 28 December 2015 at 15:50:06 UTC, Basile B. wrote:

On Monday, 28 December 2015 at 15:07:08 UTC, jkpl wrote:

On Sunday, 27 December 2015 at 16:00:34 UTC, jkpl wrote:

On Sunday, 27 December 2015 at 15:53:55 UTC, TheDGuy wrote:

Any idea what i am doing wrong?
https://www.youtube.com/watch?v=j_VCa-5VeP8


You could post the code also, personnaly I'm always almost 
at 2 meters from my screen, with zoom, so I can't read the 
code...


I work more or less lying on a futon. Desks are so cheesy...


Anarchism is comfy...


when I'm tired with the conformism I just let my head go on the 
pillow and I sleep...

(snoring)

Even if I dont't think that you have won:
https://youtu.be/Uj_7kTwRMKE?t=2m35s


https://www.youtube.com/watch?v=YgSPaXgAdzE

I'm a loser baby, so why don't you leave me ?
You luv losers ? And you don't leave them ?
Nurse syndrom.



Re: GTKD Cairo get pixel color

2015-12-30 Thread Basile B. via Digitalmars-d-learn

On Wednesday, 30 December 2015 at 20:44:44 UTC, TheDGuy wrote:

Hello,

is there any way to get the pixel color of a single pixel by x 
and y coordinates of a context?


render to a png back buffer.

see cairo_image_surface_create_for_data

then you'll be able to access the data and, at the same time, to 
blit your buffer to screen.


Re: function without "this" cannot be const?

2015-12-20 Thread Basile B. via Digitalmars-d-learn
On Monday, 21 December 2015 at 02:03:14 UTC, Shriramana Sharma 
wrote:

I'm trying to interface to a C function:

extern(C) const char * textAttrN(const char * specString, 
size_t n);


and getting the error:

Error: function .textAttrN without 'this' cannot be const

Please advise as to what I'm doing wrong?! :-(


without the parens, 'const' means that the function doesn't 
mutate the state of the object or of the struct it's declared in. 
So it's meaningless for a global function.


To avoid the confusion, take the habit to put 'const' at the 
right of the function declaration when it's related to a member 
function and only to the left when it's related to the type, and 
then to the left <=> always with parens.


Re: argument type const char* can pass string, buf why const wchar* can not pass wstring

2015-12-26 Thread Basile B. via Digitalmars-d-learn

On Sunday, 27 December 2015 at 03:34:18 UTC, riki wrote:

void ccf(const char* str){}
void cwf(const wchar* str){}

void main()
{
ccf("aaa");//ok
cwf("xxx"w); // error and why ?
}


IDK but usually the const storage class is used for narrow 
strings because it allows to pass either `char[]` or `string[]`:


```
void ccf(const char[] str){}
void cwf(const wchar[] str){}

void main()
{
ccf("aaa");
cwf("xxx"w);
ccf("aaa".dup);
cwf("xxx"w.dup);
}
```

I'm actually surprised that one works, maybe both should fail.


Re: Scope of D packages

2015-12-19 Thread Basile B. via Digitalmars-d-learn

On Saturday, 19 December 2015 at 00:46:12 UTC, cym13 wrote:
To be exact it doesn't need the sources, it needs the function 
signatures and type definitions so the equivalent of C header 
files. If you don't want to share the full sources with your 
library you can generate those header files automatically using 
the -H flag in dmd. It will produce a "D interface" file with a 
"di" extension.


Of course. Thanks for the correction. Actually I've never seen 
anybody that uses the d interface files for this purpose, but in 
theory it would work (e.g commercial non-OSS static library).


Re: Set color to a single point in Cairo

2015-12-19 Thread Basile B. via Digitalmars-d-learn

On Saturday, 19 December 2015 at 14:16:23 UTC, TheDGuy wrote:

is it possible to set the color of a single pixel with Cairo?


Not like you would do with a classic canvas (2d grid), because 
colors are applied with `cairo_fill()` and `cairo_stroke()` on a 
particular path.


but you can define a path that represents a single pixel and fill 
it:


```
cairo_rectangle (cr, x, y, 1, 1); // 1 pix rectangle
cairo_set_source_rgba (cr, 0, 0, 0, 1); // color
cairo_fill (cr); // fill the rectangle with source rgba

```

However cairo is node made to be used like this. The workflow is 
usually more based on stacked layers (1 layer = 1 path) with 
different filling, different transparency.


Re: Can't debug my solution

2015-12-19 Thread Basile B. via Digitalmars-d-learn

On Sunday, 20 December 2015 at 01:29:59 UTC, Israel wrote:
On Saturday, 19 December 2015 at 20:52:41 UTC, Matheus Reis 
wrote:

Hello, people!

I'm Matheus, a 20 y/o game developer who wants to get started 
with D. It has really caught my attention, and I've been 
playing with it for some hours now.


I've got it all working (without some "phobos.lib", is it 
really needed?) with Xamarin Studio but I can't get it to 
debug my solution when I run it. What do I need to do?


I can run it with debugging OFF (ctrl-f5) but can't run it 
"normally". What am I missing?


Thanks in advance! :)


You dont happen to be on OSX?


He's on Windows since he mentioned "phobos.lib" and not 
"libphobos2.a"


Re: Scope of D packages

2015-12-18 Thread Basile B. via Digitalmars-d-learn

On Friday, 18 December 2015 at 23:20:34 UTC, Jakob Jenkov wrote:
I'm coming from Java where "packages" are not that much more 
than directories. Each class can be exposed or hidden inside a 
package etc.


In Java it is common that an API consists of many packages and 
subpackages. All classes are simply wrapped up in a JAR (Zip) 
file, and then they can be used as a library.


What is common in D?

Does a library have all its classes inside the same package 
(same directory) ? Or can you have multiple packages / 
subpackages inside the same library *and* same source root?


each sub directory in a package is also a package

lib/package.d : allow to put all the lib modules as public import
lib/module1.d : this is module 1 from package lib
lib/module2.d : this is module 2 from package lib
lib/sub1/package.d : allow to put all the lib.sub1 modules as 
public import

lib/sub1/module1: this is module 1 from package lib.sub1
lib/sub1/module2: this is module 2 from package lib.sub1

but when you compile 'lib' library it's a monolithic *.a or *.lib 
file, which still requires the sources.


look at https://github.com/gecko0307/dlib/tree/master/dlib 
structure for example.


Re: argument type const char* can pass string, buf why const wchar* can not pass wstring

2015-12-26 Thread Basile B. via Digitalmars-d-learn

On Sunday, 27 December 2015 at 04:54:07 UTC, Basile B. wrote:

it allows to pass either `char[]` or `string[]`:


I meant "char[]` or `string", string without square brackets of 
course...





Re: argument type const char* can pass string, buf why const wchar* can not pass wstring

2015-12-26 Thread Basile B. via Digitalmars-d-learn

On Sunday, 27 December 2015 at 05:29:44 UTC, riki wrote:

On Sunday, 27 December 2015 at 04:54:07 UTC, Basile B. wrote:

On Sunday, 27 December 2015 at 03:34:18 UTC, riki wrote:

void ccf(const char* str){}
void cwf(const wchar* str){}

void main()
{
ccf("aaa");//ok
cwf("xxx"w); // error and why ?
}


IDK but usually the const storage class is used for narrow 
strings because it allows to pass either `char[]` or 
`string[]`:


```
void ccf(const char[] str){}
void cwf(const wchar[] str){}

void main()
{
ccf("aaa");
cwf("xxx"w);
ccf("aaa".dup);
cwf("xxx"w.dup);
}
```

I'm actually surprised that one works, maybe both should fail.


windows api is use const(wchar)*, not const wchar[]


To be clear:

My remark was about how it's used in phobos.
In fact your usage is wrong since you should pass either:

"sfsdf".ptr"
"sdfsf"w.ptr

That's also why i said that I was surpsied that the first call 
didn't generate a compilation error. Anyway, it looks like there 
is an implicit convertion in this case...


Re: Lots of D code

2015-12-28 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 23 December 2015 at 00:59:53 UTC, steven kladitis 
wrote:
I have 843 programs written in D. 805 actually create an 32 bit 
exe in windows 10. I am running the latest D.  Some just start 
to link and the linker disappears. Some just have issues I am  
not able figure out. I can attach the code and scripts I use to 
compile and run these. If anyone is willing to figure out why 
the 38 do not compile, I would appreciate code that works.  The 
execute_bf_v2.d creates an exe that is small but takes about 1 
hour to link on a 12 core processor with 64g of ram as 14tb of 
disk space. The rest link very fast.  If anyone is interested, 
let me know.  I would love to get the 38 working.  Also there 
are a few that produce incorrect answers.  The Generate_maze.d  
produces all but the last line of the maze.  I added a line 
just for it.  I do not understand why.  All of the programs are 
from RosettaCode.org. The  script to compile them generates a 
log file and you will see a few that the linker just stops 
No idea why. A few have 64K link errors no idea why.



TIA,
Steven


what's up ?

;)

Did you upload, so that bugs can be verified ?


are MRV as an optimization well known ?

2015-12-28 Thread Basile B. via Digitalmars-d-learn
While working on a framework, I've found that Multiple Return 
Values (MRV) are clearly an optimization. I'de like to write a 
small D blog post about this but I don't know If it's clever 
enough or if it's a well know fact.


My base D material is this:

---
#!runnable-flags: -O -boundscheck=off -release
module runnable;

struct Get
{
static auto all()
{
import std.typecons;
return tuple(0.1f,0.2f,0.3f,0.4f);
}
static float a(){return 0.1f;}
static float b(){return 0.2f;}
static float c(){return 0.3f;}
static float d(){return 0.4f;}
}

void call(float a, float b, float c, float d){}

void tupYes()
{
call(Get.all[0..$]);
}

void tupNo()
{
call(Get.a, Get.b, Get.c, Get.d);
}

void main(string[] args)
{
import disassembler;
import std.stdio;

symbolTable.addModule!runnable;
writeln(prettyDisasm());
writeln;
writeln(prettyDisasm());
}
---

with my d beaengine bindings I get this (bin comes from DMD 
backend) :


;--- SUB 0044C918h ---
; NAMED: tupYes
0044C918h  push rbp
0044C919h  mov rbp, rsp
0044C91Ch  sub rsp, 20h
0044C920h  call 0044C8A0h
0044C925h  movsd qword ptr [rbp-20h], xmm0
0044C92Ah  fld qword ptr [rbp-20h]
0044C92Dh  movsd qword ptr [rbp-20h], xmm1
0044C932h  fld qword ptr [rbp-20h]
0044C935h  fstp qword ptr [rbp-08h]
0044C938h  fstp qword ptr [rbp-10h]
0044C93Bh  movss xmm3, dword ptr [rbp-10h]
0044C940h  movss xmm2, dword ptr [rbp-0Ch]
0044C945h  movss xmm1, dword ptr [rbp-08h]
0044C94Ah  movss xmm0, dword ptr [rbp-04h]
0044C94Fh  call 0044C910h ; (call)
0044C954h  mov rsp, rbp
0044C957h  pop rbp
0044C958h  ret
;-

;--- SUB 0044C960h ---
; NAMED: tupNo
0044C960h  sub rsp, 78h
0044C964h  call 0044C8D0h
0044C969h  movss dword ptr [rsp], xmm0
0044C96Eh  movss xmm3, dword ptr [rsp]
0044C973h  movapd dqword ptr [rsp+10h], xmm3
0044C979h  call 0044C8E0h
0044C97Eh  movss dword ptr [rsp], xmm0
0044C983h  movss xmm2, dword ptr [rsp]
0044C988h  movapd xmm3, dqword ptr [rsp+10h]
0044C98Eh  movapd dqword ptr [rsp+20h], xmm2
0044C994h  movapd dqword ptr [rsp+30h], xmm3
0044C99Ah  call 0044C8F0h
0044C99Fh  movss dword ptr [rsp], xmm0
0044C9A4h  movss xmm1, dword ptr [rsp]
0044C9A9h  movapd xmm2, dqword ptr [rsp+20h]
0044C9AFh  movapd xmm3, dqword ptr [rsp+30h]
0044C9B5h  movapd dqword ptr [rsp+40h], xmm1
0044C9BBh  movapd dqword ptr [rsp+50h], xmm2
0044C9C1h  movapd dqword ptr [rsp+60h], xmm3
0044C9C7h  call 0044C900h
0044C9CCh  movapd xmm1, dqword ptr [rsp+40h]
0044C9D2h  movapd xmm2, dqword ptr [rsp+50h]
0044C9D8h  movapd xmm3, dqword ptr [rsp+60h]
0044C9DEh  call 0044C910h ; (call)
0044C9E3h  add rsp, 78h
0044C9E7h  ret
;-

Which clearly shows that using the MRV version is faster than 
grabing each property, since in the second, version there's a 
call for each parameter.


When I google "MRV optimization tuple", there's nothing, maybe 
some garbages from the early 2000's...nothing else. I'd like your 
mind before writing something possibly ridiculous.


Re: are MRV as an optimization well known ?

2015-12-28 Thread Basile B. via Digitalmars-d-learn
I mean it's maybe "just" a special case of RVO, since tuples are 
processed as structs ?





Re: Multiple selective imports on one line

2015-12-28 Thread Basile B. via Digitalmars-d-learn

On Monday, 28 December 2015 at 14:16:36 UTC, Basile B. wrote:

On Monday, 28 December 2015 at 14:09:30 UTC, Joakim wrote:
I wish dfmt could do this for us, so that you develop with all 
the modules imported at the top, then run dfmt and it scopes 
all the imports and adds the selective import of symbols.  
I've been thinking about implementing a tool to do this 
myself, will get around to it someday.


This is not formating (what DFMT is aimed to do) this is 
refactoring.


oops, my answer could lead to a misunderstanding. I meant:

This is not formating (what DFMT is aimed to do), but rather 
refactoring.




Re: Multiple selective imports on one line

2015-12-28 Thread Basile B. via Digitalmars-d-learn

On Monday, 28 December 2015 at 14:09:30 UTC, Joakim wrote:
I wish dfmt could do this for us, so that you develop with all 
the modules imported at the top, then run dfmt and it scopes 
all the imports and adds the selective import of symbols.  I've 
been thinking about implementing a tool to do this myself, will 
get around to it someday.


This is not formating (what DFMT is aimed to do) this is 
refactoring.


Re: are MRV as an optimization well known ?

2015-12-28 Thread Basile B. via Digitalmars-d-learn

On Monday, 28 December 2015 at 12:40:09 UTC, Basile B. wrote:
I mean it's maybe "just" a special case of RVO, since tuples 
are processed as structs ?


Also in the second version the stack size is modified by 78 
bytes. Not when using MRV.


Re: Variable below zero but if statement doesn't grab?

2015-12-28 Thread Basile B. via Digitalmars-d-learn

On Monday, 28 December 2015 at 15:07:08 UTC, jkpl wrote:

On Sunday, 27 December 2015 at 16:00:34 UTC, jkpl wrote:

On Sunday, 27 December 2015 at 15:53:55 UTC, TheDGuy wrote:

Any idea what i am doing wrong?
https://www.youtube.com/watch?v=j_VCa-5VeP8


You could post the code also, personnaly I'm always almost at 
2 meters from my screen, with zoom, so I can't read the code...


I work more or less lying on a futon. Desks are so cheesy...


Anarchism is comfy...




Re: Set color to a single point in Cairo

2015-12-21 Thread Basile B. via Digitalmars-d-learn

On Sunday, 20 December 2015 at 11:16:06 UTC, TheDGuy wrote:

On Sunday, 20 December 2015 at 01:17:50 UTC, Basile B. wrote:

On Saturday, 19 December 2015 at 14:16:23 UTC, TheDGuy wrote:

is it possible to set the color of a single pixel with Cairo?


Not like you would do with a classic canvas (2d grid), because 
colors are applied with `cairo_fill()` and `cairo_stroke()` on 
a particular path.


but you can define a path that represents a single pixel and 
fill it:


```
cairo_rectangle (cr, x, y, 1, 1); // 1 pix rectangle
cairo_set_source_rgba (cr, 0, 0, 0, 1); // color
cairo_fill (cr); // fill the rectangle with source rgba

```

However cairo is node made to be used like this. The workflow 
is usually more based on stacked layers (1 layer = 1 path) 
with different filling, different transparency.


Thanks for your answer,

but a bit disappointing that cairo doesn't offer a real 
"setPixel" function :(


Vectorial graphics are like that, they are at a higher level 
than, for, example, open GL. My experience with such libraries is 
a bit dusty (for example I made this when I was younger: 
http://4.bp.blogspot.com/-cmzQAHlaE50/TxcG3vEAA9I/QS0/qFxVLeo1JGU/s1600/GrainPlot%2Bv.2.4.jpg, here it plots some variable shape segments defined by x³-ax²+ax) but I clearly remember that you **never** need to draw a single pixel. A point is either part of the fill or of the border, I mean **always**.


However not that internaly cairo uses "pixman" but IDK if you can 
access it directly.

(see http://www.pixman.org/)



Re: Multiple selective imports on one line

2015-12-23 Thread Basile B. via Digitalmars-d-learn

On Wednesday, 23 December 2015 at 19:34:26 UTC, earthfront wrote:
On Wednesday, 23 December 2015 at 11:00:19 UTC, Jakob Ovrum 
wrote:

[...]

My goal is to import several symbols from different modules on 
one line.
I'm trying to figure out if it's possible or not. It makes the 
code more concise in some cases.


This is not available in the grammar. You can still open a 
duplicate enhancement request.


https://issues.dlang.org/show_bug.cgi?id=14704

see also:

http://forum.dlang.org/post/trrxoacvpyyqrdfqx...@forum.dlang.org

I remember also another NG thread about this. A guy wanted this 
feature because he thought that this would allow him to write 
faster during a Hackathlon or something like that.


Re: Graphics/font/platform backends with common interfaces?

2015-12-23 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 23 December 2015 at 21:19:14 UTC, Taylor Hillegeist 
wrote:
On Wednesday, 23 December 2015 at 21:12:11 UTC, Taylor 
Hillegeist wrote:
On Wednesday, 23 December 2015 at 21:07:12 UTC, Basile B. 
wrote:

[...]


Thanks for letting me know! So is what your saying is that an 
common interface is not possible or practical or perhaps 
useful?


Also wouldn't the least common denominator be
2D FP in Retained Mode?


Yes. and 2D FP immediate the most common then. GDI+, cairo, OGL 
ok. GDI with a lot of rouding.


Re: Graphics/font/platform backends with common interfaces?

2015-12-23 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 23 December 2015 at 20:52:05 UTC, Adam D. Ruppe 
wrote:
On Wednesday, 23 December 2015 at 20:49:21 UTC, Taylor 
Hillegeist wrote:

|  GRAPICS LIB  |
+---+---+---+ <- what is this interface
|SDL|GDI|OPENGL.|
+---+---+---+


SDL, GDI, and OpenGL *are* graphics libs so it seems a bit 
silly to put an interface there.


yes silly, more specially as

- some of them are 2D with FP coordinates
- some of them are 2D with integral coordinates
- some of them are 2D with integral coordinates with 
transformation of the plan
- some of them are 2D with integral coordinates without 
transformation of the plan
- some of them are 3D FP float coordinates with transformation of 
the plan

- some of them are in DirectMode, some of them not.
- etc...

So this would result in 5 or 6 templatized (because of the coord 
type) interface.
IIRC Interfaces are not devirtualizables so that they can be 
extracted...


also to put SDL and OPENGL on the same level is a bit strange.


Re: Graphics/font/platform backends with common interfaces?

2015-12-23 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 23 December 2015 at 21:12:11 UTC, Taylor Hillegeist 
wrote:

On Wednesday, 23 December 2015 at 21:07:12 UTC, Basile B. wrote:

[...]


Thanks for letting me know! So is what your saying is that an 
common interface is not possible or practical or perhaps useful?


It's possible but it seems to be complex.


Re: Lots of D code

2015-12-22 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 23 December 2015 at 00:59:53 UTC, steven kladitis 
wrote:

I have 843 programs written in D.
[...] All of the programs are from RosettaCode.org. The  script 
to compile them generates a log file and you will see a few 
that the linker just stops No idea why. A few have 64K link 
errors no idea why.



TIA,
Steven


I suggest you to put the 38 on GH (or the whole thing). They 
probably reveal some DMD bugs.


Re: Easier way to add libraries to visual d?

2016-06-07 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 7 June 2016 at 08:49:16 UTC, TheDGuy wrote:

On Friday, 3 June 2016 at 16:20:53 UTC, TheDGuy wrote:

On Thursday, 26 May 2016 at 17:06:03 UTC, Basile B. wrote:


colorize works. You meant "serial-port" ?


Does Coedit have the possibility to debug?


Yes / No?


No


Re: Implicit conversion of struct to bool for if (s) operation ?

2016-06-07 Thread Basile B. via Digitalmars-d-learn

On Monday, 6 June 2016 at 15:34:18 UTC, chmike wrote:

On Monday, 6 June 2016 at 15:28:35 UTC, John wrote:
Thank you John and Adam. That was a quick answer !


Too late but another option would have been to put an alias this 
on a bool getter:


struct Info
{
bool getStuff()
{
return true;
}

alias getStuff this;
}


Re: Effect of declaring a class immutable ?

2016-05-26 Thread Basile B. via Digitalmars-d-learn

On Thursday, 26 May 2016 at 14:12:23 UTC, chmike wrote:
I couldn't find any information about this on the dlang web 
site.


What is the effect adding the immutable attribute to a class 
like this


immutable class MyClass { ... }

The compiler doesn't complain.
Will it add the immutable attribute to all members ?


Since immutable is transitive everything in your class will be. 
So basically the only thing you can do is


- create a new immutable(MyClass)
- sets the instances variables in the ctor.
- calls the method (which can't do anything on the variables).

And that's all, e.g:


immutable class Foo
{
int i;
this(int i){this.i = i;}
void method(){}
}

void main()
{
immutable(Foo) foo = new immutable(Foo)(1);
//foo.i = 8; // not possible since i is immutable
Foo foo1 = cast(Foo) foo; // cast away immutable from the 
type.

//foo1.method; // not pissible since method is immutable
}


So it's more or less useless, unless you want to wrap some 
variables in a class to simplify completion in the IDE or 
whatever other reasons.


_

By the way the doc for "immutable class Stuff" is here: 
https://dlang.org/spec/const3.html#immutable_type, it's a type 
constructor. "immutable" is fully part of the type.


Re: Why do some T.init evaluate to true while others to false?

2016-05-26 Thread Basile B. via Digitalmars-d-learn

On Thursday, 26 May 2016 at 14:03:16 UTC, ArturG wrote:

for example:

if(any floatingpoint.init) will be true
if(any char.init) also true
if("") also true

while others are false e.g.

string s;
if(s) will be false
all others are also false or did i miss any?


It's a shortcut that works for certain type and that means:

- pointers: if (ptr)  <=> if (ptr != null)
- pointers: if (!ptr) <=> if (ptr == null)
- integral(*): if (i) <=> if (i > 0)
- integral: if (!i)   <=> if (i == 0)
- classes: if (c) <=> if (c !is null)
- classes: if (!c)<=> if (c is null)

(*) integral: generally speaking so: byte, ubyte, short, ushort, 
int, uint, long, ulong, char, wchar, dchar and also, very special 
case, structs with an alias this to one of this integral type.


for array this works and this tests the (.ptr) member but most of 
the people here (incl. me) would recommand rather to always do:


"if (arr.length)"

because in some cases "if (arr)" will yield "true" even if the 
length is equal to 0.


Re: Why do some T.init evaluate to true while others to false?

2016-05-26 Thread Basile B. via Digitalmars-d-learn

On Thursday, 26 May 2016 at 15:11:50 UTC, Basile B. wrote:

On Thursday, 26 May 2016 at 14:03:16 UTC, ArturG wrote:

[...]



[...]
- integral(*): if (i) <=> if (i > 0)


I obviously meant:

- integral(*): if (i) <=> if (i <> 0)

and "<=>" stands for "equivalence"


Re: How to detect/filter modules in __traits(allMembers)?

2016-06-11 Thread Basile B. via Digitalmars-d-learn

On Saturday, 11 June 2016 at 19:45:56 UTC, Random D user wrote:

Any good ideas how to do that?

I couldn't figure it out in a short amount of time, but I 
expect that it's possible. I'm probably missing something 
obvious here. Probably because D's reflection/meta programming 
facilities are a bit all over the place (and unnecessarily 
convoluted IMO).
Also I'm not super familiar with every compile-time feature, 
which is why I want to learn and some meta functions/templates 
myself.


[...]


It will compile if you define the option informational warnings 
(-wi).


Re: Access private member

2016-06-13 Thread Basile B. via Digitalmars-d-learn

On Monday, 13 June 2016 at 07:53:08 UTC, Jacob Carlborg wrote:

On 2016-06-13 09:49, Jacob Carlborg wrote:


For fields, used .tupleof, for other symbols, use a pointer.


Here's an example [1] of accessing a field using the name of 
the field as a string. It will bypass private.


That module [1] contains some generic functionality for working 
with fields which you would need for serialization. Or you can 
use the whole serialization library directly [2] ;)


[1] 
https://github.com/jacob-carlborg/orange/blob/master/orange/util/Reflection.d#L123


[2] https://github.com/jacob-carlborg/orange


There's also the IZ serializer. It's based on accessors (called 
property descriptor) to read and write private or protected 
fields. Actually it's never a good idea to directly access them. 
Usually they're not hidden for anything (e.g the count of items 
in a list, the setter update the list...)


pd: 
https://github.com/BBasile/iz/blob/master/import/iz/properties.d
ser: 
https://github.com/BBasile/iz/blob/master/import/iz/serializer.d


Re: Access private member

2016-06-13 Thread Basile B. via Digitalmars-d-learn

On Monday, 13 June 2016 at 07:43:09 UTC, Pierre wrote:

Hi,
I would like to know how can i access private member of class 
from outside ?
I think about serialization for instance, serializer must have 
access to protected attributes. How this is done ?

Thank you.


You can perform the introspection in the class itself, e .g in 
the __ctor.





Re: Access private member

2016-06-13 Thread Basile B. via Digitalmars-d-learn

On Monday, 13 June 2016 at 11:27:31 UTC, Jacob Carlborg wrote:

On 2016-06-13 09:54, Pierre wrote:

Thank you i will try it.


You don't need to involve the constructor. You can use 
.tupleof, as I mentioned [1] [2].


[1] http://forum.dlang.org/post/njlohq$1n99$1...@digitalmars.com
[2] http://forum.dlang.org/post/njlop0$1ngk$1...@digitalmars.com


I understand that web devels needs to dump 47 bytes and send them 
at 8759 miles in 200 ms, but this serialization scheme is not 
good for object streaming, e.g store a full GUI in a resource 
file. Nobody will ever use flatbuffer or message pack to store a 
GUI...lol.


Re: Access private member

2016-06-13 Thread Basile B. via Digitalmars-d-learn

On Monday, 13 June 2016 at 15:00:06 UTC, Basile B. wrote:

On Monday, 13 June 2016 at 14:30:13 UTC, Basile B. wrote:

On Monday, 13 June 2016 at 11:27:31 UTC, Jacob Carlborg wrote:

On 2016-06-13 09:54, Pierre wrote:

Thank you i will try it.


You don't need to involve the constructor. You can use 
.tupleof, as I mentioned [1] [2].


[1] http://forum.dlang.org/post/njlohq$1n99$1...@digitalmars.com
[2] http://forum.dlang.org/post/njlop0$1ngk$1...@digitalmars.com


I understand that web devels needs to dump 47 bytes and send 
them at 8759 miles in 200 ms, but this serialization scheme is 
not good for object streaming, e.g store a full GUI in a 
resource file. Nobody will ever use flatbuffer or message pack 
to store a GUI...lol.


oops I think I've replied to another thread on another board :/

Unless It's you Jacob who have proposed Orange to phobos in 
2012. And then since refused it's not developed at all. IIRC 
it's even not possible to compile it with DUB.


https://www.youtube.com/watch?v=YJO4-aa6PCI=PLuhnsen8iS5ltHofd21TWBx-bqmR9V8RU=14=False

now you know the origin of the hat ;)


Re: Access private member

2016-06-13 Thread Basile B. via Digitalmars-d-learn

On Monday, 13 June 2016 at 14:30:13 UTC, Basile B. wrote:

On Monday, 13 June 2016 at 11:27:31 UTC, Jacob Carlborg wrote:

On 2016-06-13 09:54, Pierre wrote:

Thank you i will try it.


You don't need to involve the constructor. You can use 
.tupleof, as I mentioned [1] [2].


[1] http://forum.dlang.org/post/njlohq$1n99$1...@digitalmars.com
[2] http://forum.dlang.org/post/njlop0$1ngk$1...@digitalmars.com


I understand that web devels needs to dump 47 bytes and send 
them at 8759 miles in 200 ms, but this serialization scheme is 
not good for object streaming, e.g store a full GUI in a 
resource file. Nobody will ever use flatbuffer or message pack 
to store a GUI...lol.


oops I think I've replied to another thread on another board :/

Unless It's you Jacob who have proposed Orange to phobos in 2012. 
And then since refused it's not developed at all. IIRC it's even 
not possible to compile it with DUB.


Re: Easier way to add libraries to visual d?

2016-05-28 Thread Basile B. via Digitalmars-d-learn

On Saturday, 28 May 2016 at 15:31:18 UTC, TheDGuy wrote:

On Saturday, 28 May 2016 at 15:29:36 UTC, TheDGuy wrote:


Thanks a lot for the fast hot fix, now everything works fine! 
:) Great IDE!


Do you mind implementing an option to reset the layout to 
default? Because i think i messed up and no i don't know how i 
can get the file view for the project (which was originally on 
the left side) back?


You must delete the option file that's name "docking.xml", so 
under windows in the folder appdata\roaming\coedit. Once done, 
rebuild your layout and most important: 'lock it' ! It also 
happened to me some time to time.


See also the wiki: https://github.com/BBasile/Coedit/wiki#docking

Another way to preserve the docking is to kill the application by 
hand, so that the new xml is not written. But this is not always 
doable since in this case no settings are saved at all (e.g if a 
new custom tool was added or a new libman entry then they're 
lost).


Re: Keeping a mutable reference to a struct with immutable members

2016-05-29 Thread Basile B. via Digitalmars-d-learn

On Sunday, 29 May 2016 at 19:09:13 UTC, pineapple wrote:

On Sunday, 29 May 2016 at 18:52:36 UTC, pineapple wrote:

What's the best way to handle something like this?


Well I did get something to work but it's ugly and I refuse to 
believe there isn't a better way to handle this.


Where `Range` is an alias to a struct with an immutable member, 
and `this.source` is the attribute that I need to be able to 
re-assign to a locally scoped return value:


this.source = cast(Range*) newptr;


Do yo have a simple, concise runnable example to show ?


Re: Easier way to add libraries to visual d?

2016-05-28 Thread Basile B. via Digitalmars-d-learn

On Friday, 27 May 2016 at 19:30:10 UTC, TheDGuy wrote:

On Thursday, 26 May 2016 at 22:15:17 UTC, Basile B. wrote:

gfm doesn't yield a .lib because of this:

https://github.com/d-gamedev-team/gfm/blob/master/dub.json#L22

it should be "library" or staticLibrary or "sourceLibrary"

thus it can't be registered. Bad luck here you've chosen the 
wrong stuff to test.


Okay, i now tried requests and serial-port and with both i have 
the same problem that i can't add them to the library manager.


I've released a hot fix yesterday and now it works with latest 
DUB tag (0.9.25).


But registering from the project that's loaded was already 
working yesterday. I think that you have forgotten to choose the 
right configuration to compile, example with serial-port:


http://imgur.com/7wAwqPz

- open the dub json
- to the left, the DUB inspector: the green arrow must be on a 
config that's dedicated to build the library

- double click to select a config
- compile the project
- to the bottom library manager: click the icon with a book and 
link on the top


Re: Getting the parameters and other attributes belonging to the function overload with the greatest number of arguments

2016-05-31 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 31 May 2016 at 20:06:47 UTC, pineapple wrote:
I'd like to find the overload of some function with the most 
parameters and (in this specific case) to get their identifiers 
using e.g. ParameterIdentifierTuple. There have also been cases 
where I'd have liked to iterate over the result of 
Parameters!func for each overload of that function. Can this be 
done, and if so how?


Yes this can be done, you must use the getOverload trait:

https://dlang.org/spec/traits.html#getOverloads

The result of this trait is the function itself so it's not hard 
to use, e.g the result can be passed directly to 'Parameters', 
'ReturnType' and such library traits.


Re: Easier way to add libraries to visual d?

2016-05-26 Thread Basile B. via Digitalmars-d-learn

On Thursday, 26 May 2016 at 15:11:05 UTC, TheDGuy wrote:

Hi,
i use Visual D as a plugin for visual studio to create D 
applications. But what bothers me a bit is that i have to tell 
visual D the exact link to the .lib file for every lib i want 
to use in the project (!).
So these are the steps i have to make to get an external lib 
working:


1. create a new folder in D:\dmd2\src\ with the name of the 
library
2. edit the 'sc.ini' file in D:\dmd2\windows\bin\ and add 
"-I%@P%\..\..\src\[foldername]" under '[Environment]' for every 
lib i want to use

3. add the .lib file to D:\dmd2\windows\lib
4. add the path to the lib in visual studio (project properties 
-> Linker -> General -> Library Files)


Why do i have to do that? Why can i not just use one folder for 
the library files in visual d and the compiler searches the 
.lib files for each library which was imported into the project 
on its own?


Is there an easier way to use libraries?


Use Coedit: the widget "library manager" allow to register 
libraries in a single click and then they are usable on the fly, 
in the projects or in a runnable modules, without specifying 
anything (except a (*) in a project setting called 
"libraryAliases".


https://github.com/BBasile/Coedit/wiki#library-manager-widget

It was especially designed because the other IDE suck a bit with 
static libraries.




Re: Why do some T.init evaluate to true while others to false?

2016-05-26 Thread Basile B. via Digitalmars-d-learn

On Thursday, 26 May 2016 at 15:14:21 UTC, Basile B. wrote:

On Thursday, 26 May 2016 at 15:11:50 UTC, Basile B. wrote:

On Thursday, 26 May 2016 at 14:03:16 UTC, ArturG wrote:

[...]



[...]
- integral(*): if (i) <=> if (i > 0)


I obviously meant:

- integral(*): if (i) <=> if (i <> 0)

and "<=>" stands for "equivalence"


I obviously meant:

integral(*): if (i) <=> if (i != 0),

"<>" is the Pascal operator for C's "!=" 


Re: Why do some T.init evaluate to true while others to false?

2016-05-26 Thread Basile B. via Digitalmars-d-learn

On Thursday, 26 May 2016 at 15:48:18 UTC, Basile B. wrote:

On Thursday, 26 May 2016 at 15:34:50 UTC, ArturG wrote:

On Thursday, 26 May 2016 at 15:29:52 UTC, Basile B. wrote:



float.init is not equal to 0.0f. In D FP points values are 
initialized to nan (not a number).


By the way for strings it works, it's like the array case I 
described in the first answer).


yes i guess i tested all/most types and know that float.init 
is float.nan but why is nan true and not false?


Oh, I'm so sorry ! I totally missed the point of the Q.

float.nan is not a "unique" value. Several values verify "nan" 
(Look at std.math.isNan). So I suppose it's simpler to test for 
nullity. Though with the sign there's also two possible 0...


void main(string[] args)
{
writeln(float.nan == float.init); // false
import std.math: isNaN;
writeln(isNaN(float.nan));  // true
writeln(isNaN(float.init)); //true
}

So the shortcut in the compiler might be more simple, there is 
only a single test for "if(myFloat)"...


Re: Easier way to add libraries to visual d?

2016-05-26 Thread Basile B. via Digitalmars-d-learn

On Thursday, 26 May 2016 at 15:41:45 UTC, TheDGuy wrote:

On Thursday, 26 May 2016 at 15:21:40 UTC, Basile B. wrote:


Use Coedit: the widget "library manager" allow to register 
libraries in a single click and then they are usable on the 
fly, in the projects or in a runnable modules, without 
specifying anything (except a (*) in a project setting called 
"libraryAliases".


https://github.com/BBasile/Coedit/wiki#library-manager-widget

It was especially designed because the other IDE suck a bit 
with static libraries.


Thanks for the tip. I downloaded the version for windows from 
github and it works fine so far but if i want to "run compiled 
file" i get the message 'the executino of a runnable module has 
been implicitly aborted" even though i can run the .exe file 
manually without any errors. Do you know how i can run my app 
from out of coedit?


Yes and no
- CE Projects and DUB projects are always run outside (by 
deafault)
- runnable modules can be run outside using: "Compile file and 
run outside".


It's because runnable modules are different from projects. They 
are usually compiled so fast that you can recompile before each 
execution but you can open a GH issue and ask for a new action 
"run compiled file outside" (to split the action in two phases)


When they are run inside, you can use the "Input process" widget 
to pass some input to the process that's hosted (see the 
"Windows" menu).


To register a DUB package, you can either fetch (DUB icon) or 
clone the repo, open the DUB JSON project, compile the right 
config, then in the libman there's a icon with a gray chain over 
a book. Click this icon and the library is registered.


Note that DUB projects are displayed in another widget that the 
one displayed by default at the right (see "DUB project editor") 
in the "Windows" menu.


Re: Easier way to add libraries to visual d?

2016-05-26 Thread Basile B. via Digitalmars-d-learn

On Thursday, 26 May 2016 at 16:21:30 UTC, TheDGuy wrote:

On Thursday, 26 May 2016 at 16:01:22 UTC, Basile B. wrote:
To register a DUB package, you can either fetch (DUB icon) or 
clone the repo, open the DUB JSON project, compile the right 
config, then in the libman there's a icon with a gray chain 
over a book. Click this icon and the library is registered.


Where? I searched for 10 minutes and can't find any DUB button 
besides the dub project editor. If i create a new DUB project 
it looks like that everything is locked (for example native 
project configuration)?


- Registering a dub package from online is in the "library 
manager"
- The DUB project editor is a widget that's not docked by 
default, see in the menu "Windows", the item "Dub project editor".


The Native project configuration and editor is for the native 
project format (which is another format than DUB, just like 
vsprojects are another format).


Re: Why do some T.init evaluate to true while others to false?

2016-05-26 Thread Basile B. via Digitalmars-d-learn

On Thursday, 26 May 2016 at 15:34:50 UTC, ArturG wrote:

On Thursday, 26 May 2016 at 15:29:52 UTC, Basile B. wrote:



float.init is not equal to 0.0f. In D FP points values are 
initialized to nan (not a number).


By the way for strings it works, it's like the array case I 
described in the first answer).


yes i guess i tested all/most types and know that float.init is 
float.nan but why is nan true and not false?


Oh, I'm so sorry ! I totally missed the point of the Q.

float.nan is not a "unique" value. Several values verify "nan" 
(Look at std.math.isNan). So I suppose it's simpler to test for 
nullity. Though with the sign there's also two possible 0...





Re: Easier way to add libraries to visual d?

2016-05-26 Thread Basile B. via Digitalmars-d-learn

On Thursday, 26 May 2016 at 16:53:42 UTC, Basile B. wrote:

On Thursday, 26 May 2016 at 16:21:30 UTC, TheDGuy wrote:

On Thursday, 26 May 2016 at 16:01:22 UTC, Basile B. wrote:
To register a DUB package, you can either fetch (DUB icon) or 
clone the repo, open the DUB JSON project, compile the right 
config, then in the libman there's a icon with a gray chain 
over a book. Click this icon and the library is registered.


Where? I searched for 10 minutes and can't find any DUB button 
besides the dub project editor. If i create a new DUB project 
it looks like that everything is locked (for example native 
project configuration)?


- Registering a dub package from online is in the "library 
manager"
- The DUB project editor is a widget that's not docked by 
default, see in the menu "Windows", the item "Dub project 
editor".


The Native project configuration and editor is for the native 
project format (which is another format than DUB, just like 
vsprojects are another format).


By the way everything is explained in the wiki. If the browser 
didn't display the right anchor click F5. This happens because 
everything is in a big single page:


https://github.com/BBasile/Coedit/wiki#library-manager-widget


Re: Why do some T.init evaluate to true while others to false?

2016-05-26 Thread Basile B. via Digitalmars-d-learn

On Thursday, 26 May 2016 at 15:25:03 UTC, arturg wrote:

On Thursday, 26 May 2016 at 15:15:57 UTC, Basile B. wrote:

On Thursday, 26 May 2016 at 15:14:21 UTC, Basile B. wrote:

On Thursday, 26 May 2016 at 15:11:50 UTC, Basile B. wrote:

On Thursday, 26 May 2016 at 14:03:16 UTC, ArturG wrote:

[...]



[...]
- integral(*): if (i) <=> if (i > 0)


I obviously meant:

- integral(*): if (i) <=> if (i <> 0)

and "<=>" stands for "equivalence"


I obviously meant:

integral(*): if (i) <=> if (i != 0),

"<>" is the Pascal operator for C's "!=" 


yes i know about most of those shortcuts its just float.init 
and char.init that work different then the other when you do 
this


if(someType) // will be true for float and char while someType 
is T.init


float.init is not equal to 0.0f. In D FP points values are 
initialized to nan (not a number).


By the way for strings it works, it's like the array case I 
described in the first answer).


Re: Why do some T.init evaluate to true while others to false?

2016-05-26 Thread Basile B. via Digitalmars-d-learn

On Thursday, 26 May 2016 at 15:34:50 UTC, ArturG wrote:

On Thursday, 26 May 2016 at 15:29:52 UTC, Basile B. wrote:



float.init is not equal to 0.0f. In D FP points values are 
initialized to nan (not a number).


By the way for strings it works, it's like the array case I 
described in the first answer).


yes i guess i tested all/most types and know that float.init is 
float.nan but why is nan true and not false?


because nan is not 0 and that the shortcut for float is

if (fpValue) <=> if (fpValue != 0)
if (!fpValue)<=> if (fpValue == 0)

There's no relation between the initializer and the shortcut. 
It's not because for some values the shortcut matches to the 
initializer that it must always be the case...But I admit I don't 
know the exact rationale.


Does anyone know ?


Re: Easier way to add libraries to visual d?

2016-05-26 Thread Basile B. via Digitalmars-d-learn

On Thursday, 26 May 2016 at 17:09:03 UTC, TheDGuy wrote:

On Thursday, 26 May 2016 at 17:06:03 UTC, Basile B. wrote:

colorize works. You meant "serial-port" ?


Well, i get the same message for both packages...Even though it 
creates a new folder with all the files in 
AppData\Roaming\dub\packages


Can you create a GH issue ? I'll fix it ASAP.
That's a desatrous bug. version 2 update 5 should have been the 
latest before monthes.


Re: Easier way to add libraries to visual d?

2016-05-26 Thread Basile B. via Digitalmars-d-learn

On Thursday, 26 May 2016 at 17:02:06 UTC, TheDGuy wrote:

On Thursday, 26 May 2016 at 16:53:42 UTC, Basile B. wrote:

[...]


Thanks, now i found it.

If i try to add for example 'colorize' as a package i get:

Fetching serial-port ~master...
Placing serial-port ~master to 
C:\Users\luc\AppData\Roaming\dub\packages\...


Neither a package description file, nor source/app.d was found 
in

C:\Users\luc\AppData\Roaming\dub\packages\serial-port-master
Please run DUB from the root directory of an existing package, 
or run

"dub init --help" to get information on creating a new package.

No valid root package found - aborting.
error, failed to compile the package to register


colorize works. You meant "serial-port" ?


Re: Easier way to add libraries to visual d?

2016-05-26 Thread Basile B. via Digitalmars-d-learn

On Thursday, 26 May 2016 at 17:09:03 UTC, TheDGuy wrote:

On Thursday, 26 May 2016 at 17:06:03 UTC, Basile B. wrote:

colorize works. You meant "serial-port" ?


Well, i get the same message for both packages...Even though it 
creates a new folder with all the files in 
AppData\Roaming\dub\packages


I'm on Windows now. I'm sorry but both packages were setup 
successfully.


What you can do is the other way:
- clone the git repos.
- open the DUB json as project.
- choose the right config in the inspector.
- compile.
- while the project for the lib to reg is still open, register in 
the library manager using the book-link icon.


You have well version 2 update 5 ?



Re: Easier way to add libraries to visual d?

2016-05-26 Thread Basile B. via Digitalmars-d-learn

On Thursday, 26 May 2016 at 17:06:03 UTC, Basile B. wrote:

On Thursday, 26 May 2016 at 17:02:06 UTC, TheDGuy wrote:

On Thursday, 26 May 2016 at 16:53:42 UTC, Basile B. wrote:

[...]


Thanks, now i found it.

If i try to add for example 'colorize' as a package i get:

Fetching serial-port ~master...
Placing serial-port ~master to 
C:\Users\luc\AppData\Roaming\dub\packages\...


Neither a package description file, nor source/app.d was found 
in

C:\Users\luc\AppData\Roaming\dub\packages\serial-port-master
Please run DUB from the root directory of an existing package, 
or run

"dub init --help" to get information on creating a new package.

No valid root package found - aborting.
error, failed to compile the package to register


colorize works. You meant "serial-port" ?


serial-port worked too here. I'm on linux (and CE is mostly 
developed on this platform) so it could be a bug (to verify).


Re: Easier way to add libraries to visual d?

2016-05-26 Thread Basile B. via Digitalmars-d-learn

On Thursday, 26 May 2016 at 17:09:03 UTC, TheDGuy wrote:

On Thursday, 26 May 2016 at 17:06:03 UTC, Basile B. wrote:

colorize works. You meant "serial-port" ?


Well, i get the same message for both packages...Even though it 
creates a new folder with all the files in 
AppData\Roaming\dub\packages


I confirm there is a bug. It's due to a DUB breaking change from 
0.9.24-rc4 to 0.9.24. (everything is placed in a sub folder that 
has the same name of the package).


Re: Easier way to add libraries to visual d?

2016-05-26 Thread Basile B. via Digitalmars-d-learn

On Thursday, 26 May 2016 at 19:07:42 UTC, TheDGuy wrote:

On Thursday, 26 May 2016 at 17:25:25 UTC, Basile B. wrote:


I'm on Windows now. I'm sorry but both packages were setup 
successfully.


What you can do is the other way:
- clone the git repos.
- open the DUB json as project.
- choose the right config in the inspector.
- compile.
- while the project for the lib to reg is still open, register 
in the library manager using the book-link icon.


You have well version 2 update 5 ?


Yes. So do you have any idea how i could get this to work? It 
would be nice to link libraries directly from the IDE but for 
the time being linking the project manually with the files on 
my harddrive is no problem.


I'll release a hotfix tonight, so you'll be able to give Coedit 
another try if you're not already too much disapointed.


But the procedure I described is very easy. you just have to 
clone, compile and click a button in the library manager. It's 
even better because you can choose which version to compile by 
"git checkout vx.x.x" while using the "DUB button" it's always 
the master version that get fetched (this is a limitation).


One thing that's important to get (sorry if I heavily advertise 
Coedit...) is that the libman is a central component, everything 
rely on this (CE projects, ease of compilation of the 
"runnables", and super important: DCD). That's also why it's 
split from the project editors.





Re: Easier way to add libraries to visual d?

2016-05-26 Thread Basile B. via Digitalmars-d-learn

On Thursday, 26 May 2016 at 20:46:31 UTC, TheDGuy wrote:

On Thursday, 26 May 2016 at 20:25:43 UTC, Basile B. wrote:

[...]


I tried this with the gfm-package. I opened the dub.json file 
as a project and clicked 'Compilation'-> 'Compile Project' then 
it did its things:


[...]


gfm doesn't yield a .lib because of this:

https://github.com/d-gamedev-team/gfm/blob/master/dub.json#L22

it should be "library" or staticLibrary or "sourceLibrary"

thus it can't be registered. Bad luck here you've chosen the 
wrong stuff to test.


Re: TypeInfo_Interface from runtime string?

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

On Wednesday, 22 June 2016 at 15:15:51 UTC, Thalamus wrote:

Hi everyone,

My project includes lots of .Net interop via C linkage. One of 
the things I need to do is refer in C# to an interface declared 
in the D code, and then to actually work with the interface 
concretely in the D layer. So, I need to get a 
TypeInfo_Interface object from a string passed in from C#.


The problem isn't in marshaling the string between C# and D, 
but rather what to do with the string once I have it in D.


So in the D code, where interfaceName is the fully qualified 
name of an interface, e.g.  "MyPackage.MyModule.MyInterface", 
what I would like is something like:



TypeInfo_Interface theInterface = new 
TypeInfo_Interface(interfaceName);



But there's no such constructor.


No need for a constructor. typeid() returns a static instance 
that's pre-allocated.


Apologies if this seems like it should be obvious, but I 
couldn't find anything in the forums or the wider web. :)


No problem. What you need to do is to create a registry with all 
the possible TypeInfo_Interfaces. This registry will have the 
form of an associative array. Each TypeInfo_Interface will be 
selectable with the fully qualified string, for example:


__gshared TypeInfo_Interface[string] registry;

interface Foo{}
interface Bar{}

static this()
{
registry[typeid(Foo).toString] = typeid(Foo);
registry[typeid(Bar).toString] = typeid(Bar);
}

That's the basic idea but with introspection (foreach(member; 
traits) you should be able to automate the creation of the 
registry, in a smarter way.


Re: GTKD - Application crashes - or not? [Coedit]

2016-06-16 Thread Basile B. via Digitalmars-d-learn

On Thursday, 16 June 2016 at 07:51:14 UTC, TheDGuy wrote:

On Thursday, 16 June 2016 at 07:50:13 UTC, TheDGuy wrote:
I get 'Failed to execute: 267'. Probably because a symbolic 
string is used in the run options?

https://picload.org/upload,8e3f683557a8cd3401f002304f387932.html


That is the correct image link: 
https://img1.picload.org/image/rgwaopli/coedit_run_options.png


Yes it's "WorkingDirectory" (and not current...). But otherwise 
you can use args[0]. Actually using the cwd in a program is often 
an error because there is no guarantee that the cwd is the path 
to the application ;)


People often forget that (Generally speaking).


Re: GTKD - Application crashes - or not? [Coedit]

2016-06-16 Thread Basile B. via Digitalmars-d-learn

On Thursday, 16 June 2016 at 10:02:01 UTC, TheDGuy wrote:

On Thursday, 16 June 2016 at 09:27:38 UTC, Basile B. wrote:
FOrget any previous comment and in your program use the first 
argument of the command line to detect your resources, this 
will solve your problem. For the execution click compile and 
run or just run.


Okay:

void main(string[] args){
writeln(args[0]);
Main.init(args);
auto win = new Window(250,250,"Tutorial");
Main.run();
}

This gives me the location of the .exe. What should i do with 
it now?


On Win and Nux, the first argument of the command line is 
always the program filename so you just have to get the 
directory for this string and you'll get what you expected 
with cwd.


I don't care about cwd i want to get rid of the error!


from args[0] you can get the base bath and since your css is 
relative to the base path:


string cssPath = "test.css";
CssProvider provider = new CssProvider();
provider.loadFromPath(cssPath);


add something like

import std.path;
basePath = args[0].dirName;

string cssPath = basePath ~ "\" ~ "test.css";

and you can remove all the stuff in the Run options.



Re: GTKD - Application crashes - or not? [Coedit]

2016-06-16 Thread Basile B. via Digitalmars-d-learn

On Thursday, 16 June 2016 at 09:18:54 UTC, TheDGuy wrote:

On Thursday, 16 June 2016 at 08:20:00 UTC, Basile B. wrote:
Yes it's "WorkingDirectory" (and not current...). But 
otherwise you can use args[0]. Actually using the cwd in a 
program is often an error because there is no guarantee that 
the cwd is the path to the application ;)


People often forget that (Generally speaking).


If i use args[0] as workingDirectory i still get the same 
error. I created a custom Tool like this:


https://picload.org/image/rgwapdac/coedit_run_options.png

if i execute it via "Custom Tools" -> "Run this project" 
nothing happens.


FOrget any previous comment and in your program use the first 
argument of the command line to detect your resources, this will 
solve your problem. For the execution click compile and run or 
just run.


On Win and Nux, the first argument of the command line is always 
the program filename so you just have to get the directory for 
this string and you'll get what you expected with cwd.


Re: Passing anonymous templated functions as template parameters

2016-06-15 Thread Basile B. via Digitalmars-d-learn

On Wednesday, 15 June 2016 at 23:52:56 UTC, Basile B. wrote:

On Wednesday, 15 June 2016 at 22:27:38 UTC, pineapple wrote:
Here's a simple code example to illustrate what I expected to 
work and didn't - is this a mistake in my syntax or a 
limitation of the language?


template SomeTemplate(alias func){
auto templatefunc(T)(int x){
return func!T(x);
}
}

// Valid
auto somefunc(T)(int x){
return cast(T) x;
}
alias fn1 = SomeTemplate!somefunc;

// Not valid
alias fn2 = SomeTemplate!(
(T)(int x){return cast(T) x;}
);


This syntax passes:

alias fn2(T) = SomeTemplate!((int x){return cast(T) x;});


I didn't try to instanciate previously. It works a bit with a 
lambda to the

extent that the alias has the template parameter list.

import std.stdio;

template A(alias func)
{
auto a(T)(int x)
{
return func!T(x);
}
}

alias spec(T) = A!(x => (cast(T) x));

void main(string[] args)
{
writeln((spec!byte).a!int(257)); // 1
}


Re: GTKD - Application crashes - or not? [Coedit]

2016-06-16 Thread Basile B. via Digitalmars-d-learn

On Thursday, 16 June 2016 at 15:57:36 UTC, TheDGuy wrote:

On Thursday, 16 June 2016 at 10:14:47 UTC, Basile B. wrote:


from args[0] you can get the base bath and since your css is 
relative to the base path:


string cssPath = "test.css";
CssProvider provider = new CssProvider();
provider.loadFromPath(cssPath);


add something like

import std.path;
basePath = args[0].dirName;

string cssPath = basePath ~ "\" ~ "test.css";

and you can remove all the stuff in the Run options.


But i don't call my CSS file in the main-function but instead i 
call it in the MainWindow:


import gtk.Main;
import gtk.MainWindow;
import gtk.CssProvider;
import gtk.Button;
import gdk.Display;
import gdk.Screen;
import gtk.StyleContext;
import glib.GException;

class Window : MainWindow{
this(int width, int height, string title){
super(title);
setDefaultSize(width, height);
Button btn = new Button("Test");
btn.setName("CssName");

string cssPath = "test.css";

CssProvider provider = new CssProvider();
provider.loadFromPath(cssPath);

Display display = Display.getDefault();
Screen screen = display.getDefaultScreen();
StyleContext.addProviderForScreen(screen, provider, 
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);


add(btn);
showAll();
}
}

void main(string[] args){
Main.init(args);
auto win = new Window(250,250,"Tutorial");
Main.run();
}


Please Stop your comedy.


Re: GTKD - Application crashes - or not? [Coedit]

2016-06-15 Thread Basile B. via Digitalmars-d-learn

On Wednesday, 15 June 2016 at 23:41:51 UTC, Basile B. wrote:

On Wednesday, 15 June 2016 at 17:35:32 UTC, TheDGuy wrote:
I'm gonna check on Windows today but in the meantime you can try



I've checked on windows and here is what I can say about the 
problem.


- Symbolic strings won't work on the "CurrentDirectoy" parameter. 
This is not handled at all. (you would get an error 267). I'll 
add the translation code for this parameter but this is for 
version 3 so not soon.


- I had to verify but the cwd should really be set to the path 
where the application is output. I mean that it's written so. I 
don't know what's happening on your system right now. My windows 
is still win 7 and my dev directory is not in ProgramFiles. And 
I've tested using this simple project: 
https://gist.github.com/BBasile/2e110ed48989b53e2a53b57977a81736. 
You can DL it as a zip, open the .ce file as a project and click 
"compile project and run" you should see the right CWD written in 
the messages.


- You can create a launcher in the custom tools, excluding the 
double quote:

- as executable type ""
- as CurrentDirectory type ""
- as alias put something like "Run this project"
This will work if the binary is compiled in the same directory as 
the binary that's produced. Otherwise you can adjust by adding 
directories after the symbol. (e.g  "bin\release").


Re: Passing anonymous templated functions as template parameters

2016-06-15 Thread Basile B. via Digitalmars-d-learn

On Wednesday, 15 June 2016 at 22:27:38 UTC, pineapple wrote:
Here's a simple code example to illustrate what I expected to 
work and didn't - is this a mistake in my syntax or a 
limitation of the language?


template SomeTemplate(alias func){
auto templatefunc(T)(int x){
return func!T(x);
}
}

// Valid
auto somefunc(T)(int x){
return cast(T) x;
}
alias fn1 = SomeTemplate!somefunc;

// Not valid
alias fn2 = SomeTemplate!(
(T)(int x){return cast(T) x;}
);


This syntax passes:

alias fn2(T) = SomeTemplate!((int x){return cast(T) x;});


Re: GTKD - Application crashes - or not? [Coedit]

2016-06-15 Thread Basile B. via Digitalmars-d-learn

On Wednesday, 15 June 2016 at 17:35:32 UTC, TheDGuy wrote:
On Wednesday, 15 June 2016 at 13:15:56 UTC, Rene Zwanenburg 
wrote:
I'm not familiar with Coedit, but the run options seem to 
contain a field for setting it:

https://github.com/BBasile/Coedit/wiki#run-options

You may be able to use the symbolic strings there:
https://github.com/BBasile/Coedit/wiki#symbolic-strings


I changed the working directory in the native project 
configuration in "Pre-build process", "Post-build process" and 
in "Run options" in "default", "debug" and "release" to:


You just need to change "CurrentDirectory" in the "Run options". 
The two others are for the process that's executed before and 
after compiling.


I'm gonna check on Windows today but in the meantime you can try

- sets the output path to to a value that's different from the 
project file location, e.g bin/name.exe and remove completly the 
value you've set in "Run Options"\"CurrentDirectory"
- add a trailing back slash to the value in the "Run 
Options"\"CurrentDirectory"




Re: Variable below zero but if statement doesn't grab?

2016-01-15 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 5 January 2016 at 23:52:05 UTC, Basile B. wrote:

On Monday, 28 December 2015 at 18:02:53 UTC, jkpl wrote:

On Monday, 28 December 2015 at 15:50:06 UTC, Basile B. wrote:

On Monday, 28 December 2015 at 15:07:08 UTC, jkpl wrote:

On Sunday, 27 December 2015 at 16:00:34 UTC, jkpl wrote:

On Sunday, 27 December 2015 at 15:53:55 UTC, TheDGuy wrote:

Any idea what i am doing wrong?
https://www.youtube.com/watch?v=j_VCa-5VeP8


You could post the code also, personnaly I'm always almost 
at 2 meters from my screen, with zoom, so I can't read the 
code...


I work more or less lying on a futon. Desks are so cheesy...


Anarchism is comfy...


when I'm tired with the conformism I just let my head go on 
the pillow and I sleep...

(snoring)

Even if I dont't think that you have won:
https://youtu.be/Uj_7kTwRMKE?t=2m35s


https://www.youtube.com/watch?v=YgSPaXgAdzE

I'm a loser baby, so why don't you leave me ?
You luv losers ? And you don't leave them ?
Nurse syndrom.


to the MI6:

It's a english daddy boy who tought me what is a papirosn

https://en.wikipedia.org/wiki/Belomorkanal

TIP to englishmen: you should learn how to behave in France.


Fuck the brits

2016-01-15 Thread Basile B. via Digitalmars-d-learn

On Friday, 15 January 2016 at 22:16:09 UTC, Basile B. wrote:

On Tuesday, 5 January 2016 at 23:52:05 UTC, Basile B. wrote:

On Monday, 28 December 2015 at 18:02:53 UTC, jkpl wrote:

On Monday, 28 December 2015 at 15:50:06 UTC, Basile B. wrote:

On Monday, 28 December 2015 at 15:07:08 UTC, jkpl wrote:

On Sunday, 27 December 2015 at 16:00:34 UTC, jkpl wrote:

On Sunday, 27 December 2015 at 15:53:55 UTC, TheDGuy wrote:

Any idea what i am doing wrong?
https://www.youtube.com/watch?v=j_VCa-5VeP8


You could post the code also, personnaly I'm always almost 
at 2 meters from my screen, with zoom, so I can't read the 
code...


I work more or less lying on a futon. Desks are so cheesy...


Anarchism is comfy...


when I'm tired with the conformism I just let my head go on 
the pillow and I sleep...

(snoring)

Even if I dont't think that you have won:
https://youtu.be/Uj_7kTwRMKE?t=2m35s


https://www.youtube.com/watch?v=YgSPaXgAdzE

I'm a loser baby, so why don't you leave me ?
You luv losers ? And you don't leave them ?
Nurse syndrom.


to the MI6:

It's a english daddy boy who tought me what is a papirosn

https://en.wikipedia.org/wiki/Belomorkanal

TIP to englishmen: you should learn how to behave in France.


Like the whole world can see today, you have took an anwesome 
decision in 1948. Well managed. very clever I'd say...


Re: GTKD - Application crashes - or not? [Coedit]

2016-06-17 Thread Basile B. via Digitalmars-d-learn

On Thursday, 16 June 2016 at 09:18:54 UTC, TheDGuy wrote:

On Thursday, 16 June 2016 at 08:20:00 UTC, Basile B. wrote:
Yes it's "WorkingDirectory" (and not current...). But 
otherwise you can use args[0]. Actually using the cwd in a 
program is often an error because there is no guarantee that 
the cwd is the path to the application ;)


People often forget that (Generally speaking).


If i use args[0] as workingDirectory i still get the same 
error. I created a custom Tool like this:


https://picload.org/image/rgwapdac/coedit_run_options.png

if i execute it via "Custom Tools" -> "Run this project" 
nothing happens.


There was a bug I've fixed yesterday. There's a workaround: this 
would have worked when the tool option "clearMessages" is checked.


Re: How to warn of unused imports?

2016-02-09 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 9 February 2016 at 17:54:30 UTC, Basile B. wrote:

On Tuesday, 9 February 2016 at 15:21:59 UTC, Basile B. wrote:

On Monday, 8 February 2016 at 20:48:29 UTC, cy wrote:

On Monday, 8 February 2016 at 18:57:52 UTC, Basile B. wrote:

Otherwise, it sounds like a decent enhancement request for 
DMD. I know other compilers who do this warning.


It definitely does sound like a decent enhancement request. I 
didn't know it wasn't implemented yet, but it should be 
pretty straightforward, since within DMD you can access the 
AST. Alternatively, implementing DIP50 might let you do it 
outside the compiler.


http://wiki.dlang.org/DIP50


DIP50 is a "golem"

It looks usefull, and it will help in many cases...but after a 
while it'll become a problem.


If you don't understand what's a "golem":

AlquiaDa was the golem of the CIA (in the 80's while russians 
were fighting in Afgnan). Useful until a certain point.


Useful until a certain point...


It's time for me to leave...once again alcool drives me crazy...
Latest weeks I've been ofensive against two guys: kinsley and 
lopatim...it's time for me to leave.


https://www.youtube.com/watch?v=6ixdPnLFVIo

seeya.


Re: How do you reference variables in an AA of Variants?

2016-02-08 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 9 February 2016 at 03:49:11 UTC, Enjoys Math wrote:

This:   
double b = 1.0;

Variant[string] aa = ["b": ];

writeln(aa["b"]);

fails with:

Error: cannot implicitly convert expression(["b":]) of type 
double*[string] to VariantN!20u[string]


Helps please!


Use an intermediate to carry the result of &:

double b = 1.0;
Variant vb = 
Variant[string] aa = ["b": vb];
writeln(aa["b"]);

 is a rvalue.
vb is a lvalue.


Re: How to warn of unused imports?

2016-02-09 Thread Basile B. via Digitalmars-d-learn

On Monday, 8 February 2016 at 20:48:29 UTC, cy wrote:

On Monday, 8 February 2016 at 18:57:52 UTC, Basile B. wrote:

Otherwise, it sounds like a decent enhancement request for 
DMD. I know other compilers who do this warning.


It definitely does sound like a decent enhancement request. I 
didn't know it wasn't implemented yet, but it should be pretty 
straightforward, since within DMD you can access the AST. 
Alternatively, implementing DIP50 might let you do it outside 
the compiler.


http://wiki.dlang.org/DIP50


DIP50 is a "golem"

It looks usefull, and it will help in many cases...but after a 
while it'll become a problem.


Re: Can D interface with Free Pascal?

2016-02-08 Thread Basile B. via Digitalmars-d-learn
On Thursday, 28 January 2016 at 04:26:26 UTC, Taylor Hillegeist 
wrote:
Just curious... I had a thought that perhaps since Objective C 
was a replacement for Pascal on the mac. that they might have 
the same interface. but I'm not savvy enough with fpc to figure 
out how to try it.


As said in the other posts you can link dlls or even object files 
produced by a D compiler. There is the D runtime to initialize 
and finalize, a particular attention must be put on te calling 
conventions, also some stuff like strings must be passed using 
toStringz() or received with fromStringz() (and Pchar() in 
pascal)...


One thing that's interesting is to develop let's say the GUI with 
Lazarus and use a core made in D. When you'll debug your 
application in Lazarus, and if an exception is raised within the 
object or the dll made in D, the integrated debugger will break 
and display the D source directly in Lazarus.


The first time it happend to me, I was **totally mesmerized**...

(I even made a post here: 
https://forum.dlang.org/thread/aeiwsnmsrchgmkbll...@forum.dlang.org "//debugger breaks here": it was the Lazarus debugger who displayed a D source).


But actually it's totally logical, it's just the DWARF debug info 
that indicates the source name...





Re: How to warn of unused imports?

2016-02-08 Thread Basile B. via Digitalmars-d-learn

On Monday, 8 February 2016 at 08:50:17 UTC, Daniel Kozak wrote:

V Mon, 08 Feb 2016 08:25:09 +
cy via Digitalmars-d-learn  
napsáno:


When I factor out code from my modules, it really, really 
often leaves import statements that just sit there doing 
nothing, making it look like my program is more complex than 
it is. How do I get warned for leaving those, and a list of 
which ones I can safely remove?


I dont think there is a way right now. But in a future 
dscanner. https://github.com/Hackerpilot/Dscanner/issues/134


I don't think that Dscanner will be able to do this soon. Its 
scope is limited to a single module, it's not like DCD, which 
works with the imports and which is able to look-up elsewhere.


For example you'll see this if you try to make an analyzer that 
produces warnings for signed & unsigned comparison. It impossible 
without a bit of semantic (ref: 
https://github.com/Hackerpilot/Dscanner/issues/204).


Otherwise, it sounds like a decent enhancement request for DMD. I 
know other compilers who do this warning.


Re: How to warn of unused imports?

2016-02-09 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 9 February 2016 at 15:21:59 UTC, Basile B. wrote:

On Monday, 8 February 2016 at 20:48:29 UTC, cy wrote:

On Monday, 8 February 2016 at 18:57:52 UTC, Basile B. wrote:

Otherwise, it sounds like a decent enhancement request for 
DMD. I know other compilers who do this warning.


It definitely does sound like a decent enhancement request. I 
didn't know it wasn't implemented yet, but it should be pretty 
straightforward, since within DMD you can access the AST. 
Alternatively, implementing DIP50 might let you do it outside 
the compiler.


http://wiki.dlang.org/DIP50


DIP50 is a "golem"

It looks usefull, and it will help in many cases...but after a 
while it'll become a problem.


If you don't understand what's a "golem":

AlquiaDa was the golem of the CIA (in the 80's while russians 
were fighting in Afgnan). Useful until a certain point.


Useful until a certain point...


Re: is(some template instantiation) is true, but the actual instantiation fails

2016-01-29 Thread Basile B. via Digitalmars-d-learn

On Friday, 29 January 2016 at 15:28:29 UTC, Adrian Matoga wrote:

How can I reliably test if CallsFoo can be instantiated?


You can use a constraint to prevent invalid instantiation:

struct HasFoo { void foo() {} }

struct NoFoo {}

struct CallsFoo(T)
if (__traits(hasMember, T, "foo"))
{
T t;
void bar() { t.foo(); }
}

static assert(is(CallsFoo!HasFoo));
static assert(!is(CallsFoo!NoFoo));





Re: how to allocate class without gc?

2016-01-28 Thread Basile B. via Digitalmars-d-learn

On Wednesday, 27 January 2016 at 22:39:54 UTC, Igor wrote:
But doesn't this ultimately defeat the purpose of having manual 
memory management if one has to add it to the GC to be scanned?


You can make the LOC related to the GC optional with an 
additional bool template parameter and a static if, but as said 
previously it can introduce bugs.


AddRange() is used to make the GC scan pointers inside the range 
(build-in array for example)) but the range is itself well 
manually managed.


Re: how to allocate class without gc?

2016-01-26 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 26 January 2016 at 01:09:50 UTC, Igor wrote:
Is there any examples that shows how to properly allocate an 
object of a class type with the new allocators and then release 
it when desired?


This is more or less the same answer as you've get previously 
except that I don't use emplace but rather a copy of what's done 
in _d_new_class() from the D runtime:


CT construct(CT, A...)(A a) @trusted @nogc
if (is(CT == class))
{
import std.experimental.allocator.mallocator;
auto size = typeid(CT).init.length;
auto memory = Mallocator.instance.allocate(size); // D 
runtime use GC here

memory[0 .. size] = typeid(CT).init[];
static if (__traits(hasMember, CT, "__ctor"))
(cast(CT) (memory.ptr)).__ctor(a);
import core.memory: GC;
GC.addRange(memory.ptr, size, typeid(CT));
return cast(CT) memory.ptr;
}

the GC stuff could look superfluous but without this and if 
there's a GC allocated members in your class (even a simple 
dynamic array) then you'll encounter random errors at run-time.


Re: is(some template instantiation) is true, but the actual instantiation fails

2016-01-29 Thread Basile B. via Digitalmars-d-learn

On Friday, 29 January 2016 at 17:01:46 UTC, Adrian Matoga wrote:
On Friday, 29 January 2016 at 16:36:01 UTC, Steven 
Schveighoffer wrote:

On 1/29/16 10:28 AM, Adrian Matoga wrote:

[...]


is(T) is supposed to be false if T is not a valid type.

I would agree with you that the static assert should fail.

-Steve


Oh, there's more:
// this should fail:
static assert(is(CallsFoo!NoFoo));
// this should fail too:
static assert(is(typeof({ alias Baz = CallsFoo!NoFoo; return 
Baz.init; }(;

// and this:
static assert(__traits(compiles, { alias Baz = CallsFoo!NoFoo; 
return Baz.init; }()));

// but only this fails:
alias Baz = CallsFoo!NoFoo;

https://issues.dlang.org/show_bug.cgi?id=15623


Haven't you seen my answer about constraint ?

If you put a constraint on your function template then invalid 
instantiations are rejected. I mean... this language feature is 
not just ornamental...


What do you think constraints are used for otherwise ^^


Re: opApply @safety

2016-01-29 Thread Basile B. via Digitalmars-d-learn

On Friday, 29 January 2016 at 17:44:34 UTC, Chris Wright wrote:

I want to create an opApply for a type.

I've marked my code @safe, because everything I wrote was 
@safe. The body of opApply is @safe, but it calls a delegate 
that may or may not be @safe.


How do I make it so I can iterate through this type safely and 
systemly?


I want to support iteration like:

foreach (string key, string value; collection) {}
foreach (size_t i, string key, string value; collection) {}


You can implement an input range and annotate all the primitives 
as @safe.
Then if there's only an input range in your agregate, DMD will 
auto-detect that it must use it in foreach():


http://dlang.org/spec/statement.html#foreach-with-ranges

in the worst case (range not implementable directly but only as a 
getter in .range() or .opSlice() you'll have to change the style 
a bit and consume the range explicitly in a typical "while 
(!stuff.empty) {...}"





  1   2   3   4   5   6   7   8   >