DLL creation fails with undefined symbol error

2019-04-25 Thread dokutoku via Digitalmars-d-learn

I tried to build a DLL in a Windows 64bit environment.
It works well if the compiler is DMD, but in the case of LDC, the 
build fails with a large number of undefined symbol errors.


Is this a DUB or LDC bug?
Or do I have to specify some additional arguments to the command?



Re: Call delegate from C++

2019-04-25 Thread Alex via Digitalmars-d-learn
On Wednesday, 24 April 2019 at 16:20:17 UTC, Nicholas Wilson 
wrote:

How do you pass a delegate to a c++ function to be called by it?

The function to pass the delegate to is:

extern (C++) int
fakeEntrypoint(
extern(C++) void function(void* /*delegate's context*/) 
func,

void* /*delegate's context*/ arg);


What I want is:

int entrypoint(scope void delegate() func)
{
return fakeEntrypoint(
// for some reason func.funcptr is void 
function()

cast(void function(void*))func.funcptr,
func.ptr);
}

but that fails with

cannot pass argument cast(void function(void*))func.funcptr of 
type
void function(void*) to parameter extern (C++) void 
function(void*) func


It's clear that your delegate is not extern C++


int entrypoint(scope extern(C++) void delegate() func)


Re: DMD different compiler behaviour on Linux and Windows

2019-04-25 Thread Mike Parker via Digitalmars-d-learn

On Thursday, 25 April 2019 at 20:18:28 UTC, Zans wrote:

import std.stdio;

void main()
{
char[] mychars;
mychars ~= 'a';
long index = 0L;
writeln(mychars[index]);
}

Why would the code above compile perfectly on Linux (Ubuntu 
16.04), however it would produce the following error on Windows 
10:


source\app.d(8,21): Error: cannot implicitly convert expression 
index of type long to uint


On both operating systems DMD version is 2.085.0.


DMD defaults to 64-bit output on 64-Bit Linux but always to 
32-bit output on Windows, If you compile with -m32 on Windows the 
error goes away. Reasons::


* Array indices are default typed as size_t, which is uint in 
32-bit and ulong in 64. long is not implicitly convertible to 
uint.


* On Linux, both 64- and 32-bit builds of DMD are available and 
the output for each defaults to the same. Only the 32-bit build 
is distributed on Windows.


* Historically, compiling 64-bit binaries on Windows required a 
separate installation of the Microsoft Build Tools ( or Visual 
Studio) and/or the Windows SDK. If 64-bit output were the 
default, DMD would not work out of the box. Recently, DMD has 
been shipping with the lld linker and some MinGW-based Windows 
libraries so that the additional installation is not required and 
64-bit compiles can work out of the box, but it’s still 
considered experimental.


When out-of-the-box 64-bit compilation is solid and 64-bit builds 
are distributed on Windows, the default behavior should be the 
same as on Linux.


Re: DMD different compiler behaviour on Linux and Windows

2019-04-25 Thread Patrick Schluter via Digitalmars-d-learn

On Thursday, 25 April 2019 at 20:18:28 UTC, Zans wrote:

import std.stdio;

void main()
{
char[] mychars;
mychars ~= 'a';
long index = 0L;
writeln(mychars[index]);
}

Why would the code above compile perfectly on Linux (Ubuntu 
16.04), however it would produce the following error on Windows 
10:


source\app.d(8,21): Error: cannot implicitly convert expression 
index of type long to uint


On both operating systems DMD version is 2.085.0.


The issue here is not Windows vs Linux but 32 bits vs 64 bits.
On 32 bits architectures size_t is defined as uint, long being 64 
bits long, conversion from long to uint is a truncating cast 
which are not allowed implicitely in D.
It is unfortunate that the D compiler on Windows is still 
delivered by default as a 32 bits binary and generating 32 bits 
code. I think the next release will start to deliver the compiler 
as 64 bits binary and generating 64 bits code.




DMD different compiler behaviour on Linux and Windows

2019-04-25 Thread Zans via Digitalmars-d-learn

import std.stdio;

void main()
{
char[] mychars;
mychars ~= 'a';
long index = 0L;
writeln(mychars[index]);
}

Why would the code above compile perfectly on Linux (Ubuntu 
16.04), however it would produce the following error on Windows 
10:


source\app.d(8,21): Error: cannot implicitly convert expression 
index of type long to uint


On both operating systems DMD version is 2.085.0.


Re: GTK Scale/Volume Buttons Show Muted Icon on Startup

2019-04-25 Thread Ron Tarrant via Digitalmars-d-learn

On Thursday, 25 April 2019 at 17:57:25 UTC, Mike Wey wrote:

On 25-04-2019 15:19, Ron Tarrant wrote:


This looks like an issue with GTK, the icon is not updated when 
changing the Adjustment, only when the value changes.


So, it should be reported directly to the GTK people rather 
than... well... you?


Using setValue after setting the ajustment should work, only 
you have to use a different value than the initial value of the 
adjustment or GTK doesn't see it as a change.


Thanks, Mike. That does the trick. I guess the world loves a 
gludge, eh? :)




Re: GTK Scale/Volume Buttons Show Muted Icon on Startup

2019-04-25 Thread Mike Wey via Digitalmars-d-learn

On 25-04-2019 15:19, Ron Tarrant wrote:

On Thursday, 25 April 2019 at 12:40:00 UTC, number wrote:

On Thursday, 25 April 2019 at 11:36:26 UTC, Ron Tarrant wrote:

When running this example of a VolumeButton, ...


When using `setValue(initialValue)` after `setAdjustment()` the scale 
seems have the correct value. If in addition the Adjustment is created 
with an initial value different from the `initialValue` used with 
`setValue()` then the icons are also correct on startup. Though I 
don't know why that is. The loading issue doesn't happen here (on linux).


Must be a Windows thing, then.

And even explicitly setting it with setValue() doesn't help. The icon is 
still wrong on startup.




This looks like an issue with GTK, the icon is not updated when changing 
the Adjustment, only when the value changes.


Using setValue after setting the ajustment should work, only you have to 
use a different value than the initial value of the adjustment or GTK 
doesn't see it as a change.


--
Mike Wey


Re: Logging best practices

2019-04-25 Thread dangbinghoo via Digitalmars-d-learn
On Thursday, 25 April 2019 at 10:33:00 UTC, Vladimirs Nordholm 
wrote:

Hello.

Is there a current "Best Practices" for logging in D?

For the actual logging, I know of `std.experimental.logger`. 
However, the `experimental` has kept me away from it.


Is it good, or are there any better alternatives?


for the latest alpha version of D release, all std.experimental 
has been already moved to std.


so, just don't be afraid! ~_^


-
binghoo dang


Re: Retrieving Column Data from a ListStore?

2019-04-25 Thread number via Digitalmars-d-learn

On Thursday, 25 April 2019 at 15:16:03 UTC, Ron Tarrant wrote:

On Thursday, 25 April 2019 at 11:29:04 UTC, number wrote:

I'm trying to do it with multi-selection. It works now but I 
wonder if it's right to just create a dummy TreeModelIF to 
call getSelectedRows()? Same question for creating a TreeIter 
to call getIter()?


Whatever works, I guess. Just looking over what you've got, I 
don't really see anyway around creating the dummy for either 
one since they each have to be passed into functions.


I wasn't sure if it wants the actual tree model used with the 
tree view, but passing my treeStore didn't work, so I used a 
dummy. Don't know what it's for though.


Re: Retrieving Column Data from a ListStore?

2019-04-25 Thread Ron Tarrant via Digitalmars-d-learn

On Thursday, 25 April 2019 at 11:29:04 UTC, number wrote:

I'm trying to do it with multi-selection. It works now but I 
wonder if it's right to just create a dummy TreeModelIF to call 
getSelectedRows()? Same question for creating a TreeIter to 
call getIter()?


Whatever works, I guess. Just looking over what you've got, I 
don't really see anyway around creating the dummy for either one 
since they each have to be passed into functions.


Re: GTK Scale/Volume Buttons Show Muted Icon on Startup

2019-04-25 Thread Ron Tarrant via Digitalmars-d-learn

On Thursday, 25 April 2019 at 12:40:00 UTC, number wrote:

On Thursday, 25 April 2019 at 11:36:26 UTC, Ron Tarrant wrote:

When running this example of a VolumeButton, ...


When using `setValue(initialValue)` after `setAdjustment()` the 
scale seems have the correct value. If in addition the 
Adjustment is created with an initial value different from the 
`initialValue` used with `setValue()` then the icons are also 
correct on startup. Though I don't know why that is. The 
loading issue doesn't happen here (on linux).


Must be a Windows thing, then.

And even explicitly setting it with setValue() doesn't help. The 
icon is still wrong on startup.




Re: GTK Scale/Volume Buttons Show Muted Icon on Startup

2019-04-25 Thread number via Digitalmars-d-learn

On Thursday, 25 April 2019 at 11:36:26 UTC, Ron Tarrant wrote:

When running this example of a VolumeButton, ...


When using `setValue(initialValue)` after `setAdjustment()` the 
scale seems have the correct value. If in addition the Adjustment 
is created with an initial value different from the 
`initialValue` used with `setValue()` then the icons are also 
correct on startup. Though I don't know why that is. The loading 
issue doesn't happen here (on linux).


GTK Scale/Volume Buttons Show Muted Icon on Startup

2019-04-25 Thread Ron Tarrant via Digitalmars-d-learn
I've scoured the docs, the wrapper code, the Internet, but can't 
come up with an explanation...


When running this example of a VolumeButton, no matter what the 
initial value of the slider, the icon showing is 
audio-volume-muted.


I wrote up a second test using the parent, a ScaleButton, passing 
a list of icons to the constructor. The order of the icons in the 
string array is correct, but the result was the same as with the 
VolumeButton. The muted icon shows on startup despite the initial 
value.


After fiddling with either one of these, moving the value up or 
down, the icons behave as described in the docs.


I've put both buttons in this one sample code file below.

Another odd thing...

If I run this example repeatedly, sometimes it doesn't find the 
icon set for one of the buttons. When it can't find the icons, 
and which button it can't find them for, seems to be random. This 
also happens if only one of these buttons is present in the code.



```
// Test Rig Foundation for Learning GtkD Coding

import std.stdio;

import gtk.MainWindow;
import gtk.Main;
import gtk.Box;
import gtk.Widget;
import gtk.VolumeButton;
import gtk.ScaleButton;
import gtk.Adjustment;
import gtk.c.types;

void main(string[] args)
{
Main.init(args);

	TestRigWindow myTestRig = new TestRigWindow("Test Rig with 
VolumeButton");


Main.run();

} // main()


class TestRigWindow : MainWindow
{
int borderWidth = 10;
int width = 250;
int height = 175;
AppBox appBox;

this(string title)
{
super(title);
addOnDestroy();
setBorderWidth(borderWidth);
setSizeRequest(width, height);

appBox = new AppBox();
add(appBox);

showAll();

} // this() CONSTRUCTOR


void quitApp(Widget widget)
{
writeln("Bye.");
Main.quit();

} // quitApp()

} // class myAppWindow


class AppBox : Box
{
MyVolumeButton myVolumeButton;
MyScaleButton myScaleButton;

this()
{
super(Orientation.VERTICAL, 10);

myVolumeButton = new MyVolumeButton();
packStart(myVolumeButton, false, false, 0);

myScaleButton = new MyScaleButton();
packStart(myScaleButton, false, false, 0);

} // this()

} // class AppBox


class MyScaleButton : ScaleButton
{
double minimum = 0;
double maximum = 10;
double step = 1;

Adjustment adjustment;
double initialValue = 0;
double pageIncrement = 1;
double pageSize = 0;

	string[] icons = ["audio-volume-muted", "audio-volume-high", 
"audio-volume-low", "audio-volume-medium"];

//  string[] icons = ["audio-volume-low", "audio-volume-high"];

this()
{
super(IconSize.BUTTON, minimum, maximum, step, icons);

		adjustment = new Adjustment(initialValue, minimum, maximum, 
step, pageIncrement, pageSize);

setAdjustment(adjustment);
addOnValueChanged();

} // this()


void valueChanged(double value, ScaleButton sb)
{
writeln(getValue());

} // valueChanged()


} // class MyScaleButton


class MyVolumeButton : VolumeButton
{
double minimum = 0;
double maximum = 10;
double step = 1;

Adjustment adjustment;
double initialValue = 7;
double pageIncrement = 1;
double pageSize = 1;

this()
{
super();

		adjustment = new Adjustment(initialValue, minimum, maximum, 
step, pageIncrement, pageSize);

setAdjustment(adjustment);
addOnValueChanged();

} // this()


void valueChanged(double value, ScaleButton sb)
{
writeln(getValue());

} // valueChanged()


} // class MyVolumeButton

```



Re: Retrieving Column Data from a ListStore?

2019-04-25 Thread number via Digitalmars-d-learn

On Wednesday, 24 April 2019 at 18:56:50 UTC, Ron Tarrant wrote:


For anyone else who comes along looking for the same answer, 
here's what I did:




I'm trying to do it with multi-selection. It works now but I 
wonder if it's right to just create a dummy TreeModelIF to call 
getSelectedRows()? Same question for creating a TreeIter to call 
getIter()?


```
import std.stdio;

import gtk.Main;
import gtk.MainWindow;
import gtk.TreeView;
import gtk.CellRendererText;
import gtk.TreeViewColumn;
import gtk.ListStore;
import gtk.TreeStore;
import gtk.TreeIter;
import gtk.TreeSelection;
import gtk.TreePath;

void main(string[] args)
{
Main.init(args);

MainWindow window = new MainWindow("title");
window.setSizeRequest(400, 200);

TreeView treeView = new TreeView();

CellRendererText cellRendererText;
TreeViewColumn treeViewColumn;

CellRendererText cellRendererTextA = new CellRendererText();
CellRendererText cellRendererTextB = new CellRendererText();
treeViewColumn = new TreeViewColumn();
treeViewColumn.setTitle("A and B");
treeViewColumn.packStart(cellRendererTextA, true);
treeViewColumn.packStart(cellRendererTextB, true);
treeViewColumn.addAttribute(cellRendererTextA, "text", 0);
treeViewColumn.addAttribute(cellRendererTextB, "text", 1);
treeView.appendColumn(treeViewColumn);

cellRendererText = new CellRendererText();
	treeViewColumn = new TreeViewColumn("C", cellRendererText, 
"text", 2);

treeView.appendColumn(treeViewColumn);

	//ListStore listStore = new ListStore([GType.STRING, 
GType.STRING, GType.STRING]);
	TreeStore treeStore = new TreeStore([GType.STRING, GType.STRING, 
GType.STRING]);

treeView.setModel(treeStore);

TreeIter treeIter;

treeIter = treeStore.createIter();
treeStore.setValue(treeIter, 0, "a");
treeStore.setValue(treeIter, 1, "b");
treeStore.setValue(treeIter, 2, "c");

treeIter = treeStore.createIter();
treeStore.setValue(treeIter, 0, "a2");
treeStore.setValue(treeIter, 1, "b2");
treeStore.setValue(treeIter, 2, "c2");

TreeSelection treeSelection = treeView.getSelection();
treeSelection.setMode(SelectionMode.MULTIPLE);
	treeSelection.addOnChanged(delegate void(TreeSelection 
treeSelection) {

writeln("");
if (treeSelection.getMode() == SelectionMode.MULTIPLE)
{
import gtk.TreeModelIF;
TreeModelIF tm;
//writeln(tm);
TreePath[] treePaths = 
treeSelection.getSelectedRows(tm);
writeln("nb selected: ", 
treeSelection.countSelectedRows());
if (treePaths.length)
{
foreach (i, treePath; treePaths)
{
writefln("path(%s) : %s", i, treePath);
TreeIter treeIter = new TreeIter();
treeStore.getIter(treeIter, treePath);
writefln("%s, %s, %s"
, 
treeStore.getValueString(treeIter, 0)
, 
treeStore.getValueString(treeIter, 1)
, 
treeStore.getValueString(treeIter, 2)
);
}
}
else
{
writeln("nothing");
}
}
else
{
TreeIter treeIter = treeSelection.getSelected();
if (treeIter)
{
writefln("%s, %s, %s"
, treeStore.getValueString(treeIter, 0)
, treeStore.getValueString(treeIter, 1)
, treeStore.getValueString(treeIter, 2)
);
}
else
{
writeln("nothing");
}
}
});

window.add(treeView);

window.showAll();
Main.run();
}

```


Logging best practices

2019-04-25 Thread Vladimirs Nordholm via Digitalmars-d-learn

Hello.

Is there a current "Best Practices" for logging in D?

For the actual logging, I know of `std.experimental.logger`. 
However, the `experimental` has kept me away from it.


Is it good, or are there any better alternatives?


Re: Does D have a tool like pySnooper?

2019-04-25 Thread Dennis via Digitalmars-d-learn

On Monday, 22 April 2019 at 16:24:53 UTC, Taylor Hillegeist wrote:

Or would this not be easy at all with D?


I don't think so. While there are lots of traits for 
introspection of declarations, there is no way to introspect 
lines of code. The whole function
would need to be wrapped into a mixin, and the D code would need 
to be parsed

at compile time for this to work.

It could be possible for the compiler to do this, similar to how 
it inserts counter increments every line when compiling with -cov 
for code coverage, but currently it doesn't.


Re: Future of D language

2019-04-25 Thread Vijay Singh via Digitalmars-d-learn

On Wednesday, 24 April 2019 at 05:22:35 UTC, Arjunkumar wrote:
I am title bit confuse about learning D Lang and is it well 
good for future point of view. Currently in a market many of 
language is present, so why people learn D Lang and any site 
which provide best tutorials for D Lang?


Just follow these tutorials from here: 
https://hackr.io/tutorials/learn-d-programming-language.