Re: LDC2 with -fxray-instrument

2019-01-15 Thread Johan Engelen via Digitalmars-d-learn

On Tuesday, 15 January 2019 at 14:32:03 UTC, Márcio Martins wrote:

Anyone has any idea how to build with LDC and -fxray-instrument?
I am running LDC 1.13 on Linux (x64)

The XRay section is in the binary, and the compiler-rt is 
linked in, but when I run the binary with 
XRAY_OPTIONS="patch_premain=true verbosity=1" in the 
environment, and I get nothing. No XRay logging or terminal 
output.


Great that you are trying this! I added it to LDC (trivial), but 
I have not tested it because I develop on macOS (bad excuse). 
Back than at least, XRay did not function on macOS.


What platform are you on?

-Johan



Re: problem extracting data from GtkSourceView using Gtkd

2019-01-15 Thread Mike Wey via Digitalmars-d-learn

On 14-01-2019 23:52, Chris Bare wrote:
I would have posted this in the Gtkd forum, but it has been down for a 
while.


I'm porting a GTK2/C program to Gtkd. I'm trying to read the data from a 
GtkSourceView, but when I try to get the bounds, it's always zero.


Here's the c version that works:
 GtkSourceBuffer *bf;
 GtkTextIter start, end;
 int len;

 bf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (w.mainTxt));
 gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER(bf), , );
 data = gtk_text_buffer_get_text (GTK_TEXT_BUFFER(bf), , , 
FALSE);


Here's what I tried in D:
 SourceBuffer bf;
 auto start = new TextIter();
 auto end = new TextIter();

 bf = this.mainTxt.getBuffer ();
 bf.getBounds (start, end);
 string str = bf.getText (start, end, false);

getBounds is defined as: getBounds(out TextIter start, out TextIter end)

Is there something I'm doing wrong?
Any suggestions on what else to try?


Your code looks correct, and when copying it into the GtkD sourceview 
demo str does indeed hold the text displayed in the GtkSourceview.


Do you have a more complete example we could look at?

--
Mike Wey


Re: Has anyone tried making a QtCreator plugin for D and what is your experience?

2019-01-15 Thread Laurent Tréguier via Digitalmars-d-learn

On Saturday, 12 January 2019 at 20:10:40 UTC, Enjoys Math wrote:
On Saturday, 12 January 2019 at 16:09:22 UTC, Laurent Tréguier 
wrote:
On Saturday, 12 January 2019 at 15:16:25 UTC, Laurent Tréguier 
wrote:
QtCreator 4.8.0 introduced support for the LSP last month : 
https://blog.qt.io/blog/2018/12/06/qt-creator-4-8-0-released


I think I'm going to add it to the list of editors to look 
into and perhaps try to make a plugin for it.


Correction: a language server can simply be set up in the LSP 
plugin's options after the plugin has been enabled, so some 
amount of D support is achievable already.


I see your links. Would you like to work on this together?  
Social coding is more powerful than solo coding IMO.


Is it necessary to make a plugin though ? Syntax highlighting can 
be downloaded directly through QtCreator's syntax options, and 
then the new bundled LSP plugin can be configured directly to use 
any language server.


Re: What's that 'q' before '{' in this code?

2019-01-15 Thread SrMordred via Digitalmars-d-learn

On Tuesday, 15 January 2019 at 17:52:35 UTC, Machine Code wrote:

https://github.com/dlang/dmd/blob/master/src/dmd/compiler.d#L75


https://dlang.org/spec/lex.html#token_strings
:)


Re: What's that 'q' before '{' in this code?

2019-01-15 Thread Adam D. Ruppe via Digitalmars-d-learn

On Tuesday, 15 January 2019 at 17:52:35 UTC, Machine Code wrote:

https://github.com/dlang/dmd/blob/master/src/dmd/compiler.d#L75


It is a string literal that must be made out of D code tokens.

In my blog this week, I talked about some code that uses them:

http://dpldocs.info/this-week-in-d/Blog.Posted_2019_01_14.html#the-generated-client

You can see how it syntax highlights as code, but is semantically 
a string. The code inside is passed to mixin, so this hybrid 
appearance works well.


Re: What's that 'q' before '{' in this code?

2019-01-15 Thread Machine Code via Digitalmars-d-learn

On Tuesday, 15 January 2019 at 17:56:10 UTC, SrMordred wrote:

On Tuesday, 15 January 2019 at 17:52:35 UTC, Machine Code wrote:

https://github.com/dlang/dmd/blob/master/src/dmd/compiler.d#L75


https://dlang.org/spec/lex.html#token_strings
:)


I had just infered from the commend in the code "The D code to be 
generated is provided as D source code in the form of a string."


then I tried:

auto s = q{ foo(); return 10 };
writeln(s);

Then whoa. What a feature! I'm not aware of any language with 
this feature. Amazing.

Thank for your answer as well :)


What's that 'q' before '{' in this code?

2019-01-15 Thread Machine Code via Digitalmars-d-learn

https://github.com/dlang/dmd/blob/master/src/dmd/compiler.d#L75


LDC2 with -fxray-instrument

2019-01-15 Thread Márcio Martins via Digitalmars-d-learn

Anyone has any idea how to build with LDC and -fxray-instrument?
I am running LDC 1.13 on Linux (x64)

The XRay section is in the binary, and the compiler-rt is linked 
in, but when I run the binary with 
XRAY_OPTIONS="patch_premain=true verbosity=1" in the environment, 
and I get nothing. No XRay logging or terminal output.


Re: Is there a nice syntax to achieve optional named parameters?

2019-01-15 Thread John Burton via Digitalmars-d-learn
On Tuesday, 15 January 2019 at 12:15:41 UTC, rikki cattermole 
wrote:

On 16/01/2019 1:05 AM, John Burton wrote:
On Tuesday, 15 January 2019 at 11:26:50 UTC, rikki cattermole 
wrote:

Longer term, you're better off with the builder.

Thanks for your reply. But what is the builder?


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

One of the few OOP design patterns that I can agree with.


Ah right, that.
Thank you.
Hmm that would work.


Re: Is there a nice syntax to achieve optional named parameters?

2019-01-15 Thread rikki cattermole via Digitalmars-d-learn

On 16/01/2019 1:05 AM, John Burton wrote:

On Tuesday, 15 January 2019 at 11:26:50 UTC, rikki cattermole wrote:

Longer term, you're better off with the builder.

Thanks for your reply. But what is the builder?


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

One of the few OOP design patterns that I can agree with.


Re: Is there a nice syntax to achieve optional named parameters?

2019-01-15 Thread John Burton via Digitalmars-d-learn
On Tuesday, 15 January 2019 at 11:26:50 UTC, rikki cattermole 
wrote:

Longer term, you're better off with the builder.

Thanks for your reply. But what is the builder?


Creating windows is a very complex task that can balloon in 
scope.


Well that was mostly just an example that I thought people could 
relate to more than my obscure real case :) But the principle is 
the same so the answer is likely too




Re: Is there a nice syntax to achieve optional named parameters?

2019-01-15 Thread rikki cattermole via Digitalmars-d-learn
Longer term, you're better off with the builder. Even with named 
parameters (2 DIP's are in the queue for adding it).


Creating windows is a very complex task that can balloon in scope.
Being able to hide it away in a separate type can be quite desirable if 
you want your windowing library to be actually useful in not just one 
simple case.


Of course that doesn't mean you couldn't hide that its there ;)


Re: Destructor for struct invoked many times

2019-01-15 Thread Antonio Corbi via Digitalmars-d-learn
On Tuesday, 15 January 2019 at 10:49:17 UTC, rikki cattermole 
wrote:
Because you passed it by value to writeln, which goes on to 
pass it to many other functions.


Thanks Rikki!

I was thinking about something like that.
Antonio


Is there a nice syntax to achieve optional named parameters?

2019-01-15 Thread John Burton via Digitalmars-d-learn
As an example let's say I have a type 'Window' that represents a 
win32 window. I'd like to be able to construct an instance of the 
type with some optional parameters that default to some 
reasonable settings and create the underlying win32 window.


I'd ideally like some syntax like this :-

auto window = Window(title = "My Window", width = 1000, 
fullscreen = true);


Assume that title, width, fullscreen are optional and if not 
specified there are defaults to use. And that there are many 
other settings than just these 3 that I've chosen to just use the 
default here.


I know that I can't do it like this is D but what is the best way 
to achieve this kind of thing? I can add properties and then do a 
specific "create" function to create the underlying win32 window 
once I'm done but that seems ugly.


auto window = Window();
window.title = "My Window";
window.width = 1000;
window.create();

This is ok, but I'm not so keen on separating the creation and 
construction like this.

Is there a better way that's not ugly?


Destructor for struct invoked many times

2019-01-15 Thread Antonio Corbi via Digitalmars-d-learn

Hi,

In this simple example, the destructor for the struct is invoked 
four more times than expected:



import std.stdio;

struct Person {
  string name;
  int age;

  ~this() {
writefln("%s is gone (0x%x)", name, );
  }
}

int main(string[] args) {
  Person* p = new Person;

  writefln ("Created person (0x%x)", p);
  p.name = "Peter";
  p.age = 23;

  writeln("Person:", *p); // Comment this line and try

  return 0;
}


Output:

Created person (0x7f85ee997000)
Person:Person("Peter", 23)Peter is gone (0x7ffd916c1560)
Peter is gone (0x7ffd916c15c0)

Peter is gone (0x7ffd916c1640)
Peter is gone (0x7ffd916c16f0)
Peter is gone (0x7f85ee997000)
-

If I comment the line "writeln("Person:", *p);" then the 
destructor is invoked only one time as expected.


Why is it?


Re: Destructor for struct invoked many times

2019-01-15 Thread rikki cattermole via Digitalmars-d-learn
Because you passed it by value to writeln, which goes on to pass it to 
many other functions.


Re: Design by Introspection - Looking for examples

2019-01-15 Thread Tony A via Digitalmars-d-learn
On Tuesday, 15 January 2019 at 07:14:22 UTC, Petar Kirov 
[ZombineDev] wrote:
Basically, look for `static if`s in Phobos. A couple of rich 
modules/packages:

...


Hi Petar,

Thanks for the links, especially the checkint which was one 
example Andrei gave in the presentation.


Tony.


Re: Design by Introspection - Looking for examples

2019-01-15 Thread Tony A via Digitalmars-d-learn
On Tuesday, 15 January 2019 at 07:14:22 UTC, Petar Kirov 
[ZombineDev] wrote:
Basically, look for `static if`s in Phobos. A couple of rich 
modules/packages:


Hi Petar