Re: Connecting python to D on socket of localhost : target machine actively refuses connection

2017-09-21 Thread Enjoys Math via Digitalmars-d-learn
On Friday, 22 September 2017 at 05:43:24 UTC, Nicholas Wilson wrote: On Friday, 22 September 2017 at 04:37:44 UTC, Enjoys Math wrote: On Friday, 22 September 2017 at 04:25:00 UTC, Enjoys Math wrote: I've tried opening the port for TCP with windows 10 firewall settings. Same result. What

Re: Connecting python to D on socket of localhost : target machine actively refuses connection

2017-09-21 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 22 September 2017 at 04:37:44 UTC, Enjoys Math wrote: On Friday, 22 September 2017 at 04:25:00 UTC, Enjoys Math wrote: I've tried opening the port for TCP with windows 10 firewall settings. Same result. What tool would best help me debug this? Wireshark or is that too low level?

Re: Connecting python to D on socket of localhost : target machine actively refuses connection

2017-09-21 Thread Enjoys Math via Digitalmars-d-learn
On Friday, 22 September 2017 at 04:25:00 UTC, Enjoys Math wrote: I've tried opening the port for TCP with windows 10 firewall settings. Same result. What tool would best help me debug this? Wireshark or is that too low level? I've used Hercules:

Re: Problems with function as parameter

2017-09-21 Thread Josh via Digitalmars-d-learn
On Friday, 22 September 2017 at 03:26:36 UTC, Mike Parker wrote: On Friday, 22 September 2017 at 02:22:46 UTC, Josh wrote: src\mixer.d(80,22): Error: function pointer Mix_ChannelFinished (extern (C) void function(int channel)) is not callable using argument types (extern (C) void

Re: Connecting python to D on socket of localhost : target machine actively refuses connection

2017-09-21 Thread Enjoys Math via Digitalmars-d-learn
I've tried opening the port for TCP with windows 10 firewall settings. Same result. What tool would best help me debug this? Wireshark or is that too low level?

Connecting python to D on socket of localhost : target machine actively refuses connection

2017-09-21 Thread Enjoys Math via Digitalmars-d-learn
Here's my minimal D code (server.d): module server; import core.thread; import std.socket; import std.experimental.logger; class Server : Thread { private: Socket listener; int backlog; string address; ushort port; SocketSet sockSet; Socket[]

Re: How to get DnD to work in GTKD?

2017-09-21 Thread Joseph via Digitalmars-d-learn
On Friday, 22 September 2017 at 02:57:32 UTC, Joseph wrote: On Saturday, 16 September 2017 at 14:33:53 UTC, Mike Wey wrote: On 16-09-17 06:33, Joseph wrote: I've used null in place of [te]. I'm not sure what target entry is for and if that is the problem or what. I am trying to drag files

Re: Problems with function as parameter

2017-09-21 Thread Mike Parker via Digitalmars-d-learn
On Friday, 22 September 2017 at 02:32:56 UTC, Josh wrote: Why should the binding force nothrow? I don't understand why you HAVE to not throw exceptions. Is it because of the C -> D aspect? Yes, it's because D exceptions are not guaranteed to propagate through the C callstack. It works on

Re: Problems with function as parameter

2017-09-21 Thread Mike Parker via Digitalmars-d-learn
On Friday, 22 September 2017 at 02:32:56 UTC, Josh wrote: Why should the binding force nothrow? I don't understand why you HAVE to not throw exceptions. Is it because of the C -> D aspect? Yes, it's because D exceptions are not guaranteed to propagate through the C callstack. It works on

Re: Problems with function as parameter

2017-09-21 Thread Mike Parker via Digitalmars-d-learn
On Friday, 22 September 2017 at 02:22:46 UTC, Josh wrote: src\mixer.d(80,22): Error: function pointer Mix_ChannelFinished (extern (C) void function(int channel)) is not callable using argument types (extern (C) void delegate(int channel)) Code: void unmuteAfterPlaySound() {

Re: How to get DnD to work in GTKD?

2017-09-21 Thread Joseph via Digitalmars-d-learn
On Saturday, 16 September 2017 at 14:33:53 UTC, Mike Wey wrote: On 16-09-17 06:33, Joseph wrote: I've used null in place of [te]. I'm not sure what target entry is for and if that is the problem or what. I am trying to drag files from windows explorer to a grid or label(I duplicated the

Re: Problems with function as parameter

2017-09-21 Thread Josh via Digitalmars-d-learn
On Friday, 22 September 2017 at 02:18:34 UTC, Mike Parker wrote: On Thursday, 21 September 2017 at 22:05:22 UTC, Matt Jones wrote: On Thursday, 21 September 2017 at 20:21:58 UTC, Josh wrote: I'm trying to write a callback function for SDL_mixer through Derelict, but this is the first time I've

Re: Problems with function as parameter

2017-09-21 Thread Josh via Digitalmars-d-learn
On Thursday, 21 September 2017 at 22:05:22 UTC, Matt Jones wrote: On Thursday, 21 September 2017 at 20:21:58 UTC, Josh wrote: I'm trying to write a callback function for SDL_mixer through Derelict, but this is the first time I've tried to use a function as a parameter, and so I think I'm just

Re: Problems with function as parameter

2017-09-21 Thread Mike Parker via Digitalmars-d-learn
On Friday, 22 September 2017 at 02:18:34 UTC, Mike Parker wrote: and use & to reference the function instead of calling it: Mix_ChannelFinished(); To expand on this, D allows functions to be called without parentheses. `channelDone` is actually a function call, whereas in C, it's treated

Re: Problems with function as parameter

2017-09-21 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 21 September 2017 at 22:05:22 UTC, Matt Jones wrote: On Thursday, 21 September 2017 at 20:21:58 UTC, Josh wrote: I'm trying to write a callback function for SDL_mixer through Derelict, but this is the first time I've tried to use a function as a parameter, and so I think I'm just

Re: Problems with function as parameter

2017-09-21 Thread Matt Jones via Digitalmars-d-learn
On Thursday, 21 September 2017 at 20:21:58 UTC, Josh wrote: I'm trying to write a callback function for SDL_mixer through Derelict, but this is the first time I've tried to use a function as a parameter, and so I think I'm just making a minor mistake somewhere. [...] Make it a C function,

Re: How to check if string is available at compile time

2017-09-21 Thread David Bennett via Digitalmars-d-learn
On Thursday, 21 September 2017 at 13:52:25 UTC, Meta wrote: On Thursday, 21 September 2017 at 12:30:15 UTC, David Bennett wrote: On Thursday, 21 September 2017 at 11:42:36 UTC, David Bennett wrote: enum isCTstring(alias arg) = (!isAssignable!(typeof(arg)) || __traits(compiles, mixin(` "foo"

Re: Getting the size of a type tuple

2017-09-21 Thread ag0aep6g via Digitalmars-d-learn
On 09/21/2017 09:59 PM, H. S. Teoh wrote: On Thu, Sep 21, 2017 at 09:49:14PM +0200, ag0aep6g via Digitalmars-d-learn wrote: [...] 3) Declaring a packed struct in a function literal that gets immediately called: enum size_so_very_clever(Types ...) = () { struct S { align(1) Types

Problems with function as parameter

2017-09-21 Thread Josh via Digitalmars-d-learn
I'm trying to write a callback function for SDL_mixer through Derelict, but this is the first time I've tried to use a function as a parameter, and so I think I'm just making a minor mistake somewhere. The C SDL docs say: // make a

Re: Getting the size of a type tuple

2017-09-21 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Sep 21, 2017 at 09:49:14PM +0200, ag0aep6g via Digitalmars-d-learn wrote: [...] > 3) Declaring a packed struct in a function literal that gets > immediately called: > > enum size_so_very_clever(Types ...) = () { > struct S { align(1) Types fields; } > return S.sizeof; > } ();

Re: [OT] Converting booleans to numbers

2017-09-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/21/17 3:24 PM, Timon Gehr wrote: This is a good alternative, maybe arrange it like this: dfs(a + 1, b); dfs(a, b + 1); dfs(a - 1, b); dfs(a, b - 1); Yes, better! Just need to make sure no code is duplicated. (For example, there could be more work to do in each loop iteration, and then

Re: Getting the size of a type tuple

2017-09-21 Thread David Zhang via Digitalmars-d-learn
On Thursday, 21 September 2017 at 19:49:14 UTC, ag0aep6g wrote: I don't have a one-liner, but here are some other solutions that might be interesting. None of them is particularly pretty, though. 1) Recursive template: 2) Using the std library: 3) Declaring a packed struct in a function

Re: Getting the size of a type tuple

2017-09-21 Thread ag0aep6g via Digitalmars-d-learn
On 09/21/2017 08:44 PM, David Zhang wrote: Given the function F, where: F(Args...)(Args args) { ... } How can I statically determine the size of the argument list in bytes? Preferably, I would like a one-liner. However, std.algorithm doesn't seem to support tuples, or `Args.each!(T =>

Re: [OT] Converting booleans to numbers

2017-09-21 Thread Timon Gehr via Digitalmars-d-learn
On 21.09.2017 17:53, Steven Schveighoffer wrote: On 9/21/17 11:48 AM, Steven Schveighoffer wrote: On 9/21/17 11:06 AM, Timon Gehr wrote:     foreach(i; 0 .. 4){     dfs(a + (i==0) - (i==1),     b + (i==2) - (i==3));     } So am I, but I wasn't commenting on

Getting the size of a type tuple

2017-09-21 Thread David Zhang via Digitalmars-d-learn
Given the function F, where: F(Args...)(Args args) { ... } How can I statically determine the size of the argument list in bytes? Preferably, I would like a one-liner. However, std.algorithm doesn't seem to support tuples, or `Args.each!(T => T.sizeof).sum` would work. For the moment,

Re: [OT] Converting booleans to numbers

2017-09-21 Thread Mark via Digitalmars-d-learn
On Wednesday, 20 September 2017 at 19:25:58 UTC, Timon Gehr wrote: Actually, it is useful enough to have a Wikipedia page: https://en.wikipedia.org/wiki/Iverson_bracket Example of a good use: void floodFill(dchar[][] data,dchar c,int i,int j) { void dfs(int a, int b) { if (a<0 ||

Re: [OT] Converting booleans to numbers

2017-09-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/21/17 11:48 AM, Steven Schveighoffer wrote: On 9/21/17 11:06 AM, Timon Gehr wrote:     foreach(i; 0 .. 4){     dfs(a + (i==0) - (i==1),     b + (i==2) - (i==3));     } So am I, but I wasn't commenting on trade-offs, only the view that there are no good

Re: [OT] Converting booleans to numbers

2017-09-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/21/17 11:06 AM, Timon Gehr wrote: foreach(i; 0 .. 4){ dfs(a + (i==0) - (i==1), b + (i==2) - (i==3)); } ... So am I, but I wasn't commenting on trade-offs, only the view that there are no good uses. This seems way easier for me to grok, and

Re: [OT] Converting booleans to numbers

2017-09-21 Thread Timon Gehr via Digitalmars-d-learn
On 20.09.2017 23:13, nkm1 wrote: Example of a good use: void floodFill(dchar[][] data,dchar c,int i,int j) {     void dfs(int a, int b) { Example of a good use: void floodFill(dchar[][] data,dchar c,int i,int j) { void dfs(int a, int b) { if (a<0 || a >= data.length) return;

Re: How to check if string is available at compile time

2017-09-21 Thread Meta via Digitalmars-d-learn
On Thursday, 21 September 2017 at 12:30:15 UTC, David Bennett wrote: On Thursday, 21 September 2017 at 11:42:36 UTC, David Bennett wrote: [snip] ``` string[] escapeCTFE(Args...)(){ static foreach (arg; Args){ static if(__traits(compiles, ###WHATDOIPUTHERE###)){ [snip] So far

Re: How to check if string is available at compile time

2017-09-21 Thread David Bennett via Digitalmars-d-learn
On Thursday, 21 September 2017 at 11:42:36 UTC, David Bennett wrote: [snip] ``` string[] escapeCTFE(Args...)(){ static foreach (arg; Args){ static if(__traits(compiles, ###WHATDOIPUTHERE###)){ [snip] So far the best I've come up with is : ``` enum isCTstring(alias arg) =

How to check if string is available at compile time

2017-09-21 Thread David Bennett via Digitalmars-d-learn
Hi Guys, Is there an easy way to check if the value of string passed to a template is available at compile time? Here is a cut down example of that I'm doing: ``` string[] escapeCTFE(Args...)(){ static foreach (arg; Args){ static if(__traits(compiles, ###WHATDOIPUTHERE###)){