Re: function default parameters lost
On Thursday, 25 June 2015 at 04:43:51 UTC, Paul D Anderson wrote: I'm trying to pass a function pointer while keeping the default parameter values intact. Given the following: [...] I filed a bug about 2-3 months ago about default parameters similar to yours. My guess is that it hasn't been fixed yet, and you have hit the same issue.
Importing local modules in C style
I want to import a module from my local project in C style (#include "local.h"). I know I can do "dmd main.d local.d" but I wonder if it can be done C style. Thank you BD
Opening browser and url.
In other programming languages you can open a website in the default browser by spawning a process using the url, but it does not seem to work with D using spawnProcess(). Do I have to do API calls to get the default browser and then call spawnProcess() with the url as an argument or is there a standard D way. I tried it like the following spawnProcess("http://www.x.x/";);
Typed Message Passing between D Processes
Is there an alternative to http://dlang.org/phobos/std_process.html#.pipe that can be used to do _typed_ _message_ _passing_ between two D processes with the same convenience as `send` and `receive` in std.concurrency ? Either in Phobos or in a third party library?
Re: Importing local modules in C style
On 6/25/15 9:57 AM, Binarydepth wrote: I want to import a module from my local project in C style (#include "local.h"). No. I know I can do "dmd main.d local.d" but I wonder if it can be done C style. What is your goal? Why doesn't D import work for you? -Steve
Re: Opening browser and url.
On Thursday, 25 June 2015 at 14:02:41 UTC, Bauss wrote: In other programming languages you can open a website in the default browser by spawning a process using the url, but it does not seem to work with D using spawnProcess(). Do I have to do API calls to get the default browser and then call spawnProcess() with the url as an argument or is there a standard D way. I tried it like the following spawnProcess("http://www.x.x/";); http://dlang.org/phobos/std_process.html#.browse
Re: Opening browser and url.
On Thursday, 25 June 2015 at 14:05:54 UTC, MrSmith wrote: On Thursday, 25 June 2015 at 14:02:41 UTC, Bauss wrote: In other programming languages you can open a website in the default browser by spawning a process using the url, but it does not seem to work with D using spawnProcess(). Do I have to do API calls to get the default browser and then call spawnProcess() with the url as an argument or is there a standard D way. I tried it like the following spawnProcess("http://www.x.x/";); http://dlang.org/phobos/std_process.html#.browse Thank you, how could I have not seen that!
Re: function default parameters lost
On Thursday, 25 June 2015 at 07:10:57 UTC, tcak wrote: On Thursday, 25 June 2015 at 04:43:51 UTC, Paul D Anderson wrote: I'm trying to pass a function pointer while keeping the default parameter values intact. Given the following: [...] I filed a bug about 2-3 months ago about default parameters similar to yours. My guess is that it hasn't been fixed yet, and you have hit the same issue. Thanks
Re: Importing local modules in C style
On Thursday, 25 June 2015 at 14:10:00 UTC, Steven Schveighoffer wrote: On 6/25/15 9:57 AM, Binarydepth wrote: I want to import a module from my local project in C style (#include "local.h"). No. I know I can do "dmd main.d local.d" but I wonder if it can be done C style. What is your goal? Why doesn't D import work for you? -Steve I organize some exercises in some source files, it's more how I like to work with C. I'm used to organize source files this way and I was wondering if this was possible with D. Thank you for your response Steven
Re: Importing local modules in C style
On 6/25/15 10:37 AM, Binarydepth wrote: On Thursday, 25 June 2015 at 14:10:00 UTC, Steven Schveighoffer wrote: On 6/25/15 9:57 AM, Binarydepth wrote: I want to import a module from my local project in C style (#include "local.h"). No. I know I can do "dmd main.d local.d" but I wonder if it can be done C style. What is your goal? Why doesn't D import work for you? -Steve I organize some exercises in some source files, it's more how I like to work with C. I'm used to organize source files this way and I was wondering if this was possible with D. Well, if you publicly import the other module, it pulls all those public symbols as if they were defined in the importing module. Perhaps this would work for you. -Steve
Abstract sockets (linux)
I am having trouble using abstract sockets on Linux. Here is sample python code that works, which works: ptm_sockname = "\0/var/run/ptmd.socket" sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect(ptm_sockname) sock.setblocking(1) sock.sendall('get-status detail') Similar code in D, which does not work: string socket_name = "\0/var/run/ptmd.socket"; auto address = new UnixAddress(socket_name); auto sock = new Socket(AddressFamily.UNIX, SocketType.STREAM); scope(exit) sock.close(); sock.blocking = true; sock.connect(address); sock.send("get-status detail"); This is the equivalent with socat, which works: $ echo "get-status detail" | socat - ABSTRACT-CLIENT:/var/run/ptmd.socket My test D program exits on connect: std.socket.SocketOSException@runtime/phobos/std/socket.d(2674): Unable to connect socket: Connection refused Any pointers?
Re: Abstract sockets (linux)
On 6/25/15 11:56 AM, freeman wrote: I am having trouble using abstract sockets on Linux. Here is sample python code that works, which works: ptm_sockname = "\0/var/run/ptmd.socket" sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect(ptm_sockname) sock.setblocking(1) sock.sendall('get-status detail') Similar code in D, which does not work: string socket_name = "\0/var/run/ptmd.socket"; auto address = new UnixAddress(socket_name); auto sock = new Socket(AddressFamily.UNIX, SocketType.STREAM); scope(exit) sock.close(); sock.blocking = true; sock.connect(address); sock.send("get-status detail"); This is the equivalent with socat, which works: $ echo "get-status detail" | socat - ABSTRACT-CLIENT:/var/run/ptmd.socket My test D program exits on connect: std.socket.SocketOSException@runtime/phobos/std/socket.d(2674): Unable to connect socket: Connection refused Any pointers? I believe there was a recently fixed bug regarding unix sockets. The upcoming 2.068 may help, have you tried the beta? http://downloads.dlang.org/pre-releases/2.x/2.068.0/ -Steve
Re: Abstract sockets (linux)
On Thursday, 25 June 2015 at 16:07:51 UTC, Steven Schveighoffer wrote: I believe there was a recently fixed bug regarding unix sockets. The upcoming 2.068 may help, have you tried the beta? http://downloads.dlang.org/pre-releases/2.x/2.068.0/ -Steve Unfortunately the problem persists (I was using ldc2 before): $ ./test std.socket.SocketOSException@std/socket.d(2808): Unable to connect socket: Connection refused ./test(_Dmain+0xce) [0x443b42] ./test(_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv+0x1f) [0x44ad7b] ./test(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x2a) [0x44acd6] ./test(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll()+0x2b) [0x44ad37] ./test(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x2a) [0x44acd6] ./test(_d_run_main+0x1d2) [0x44ac56] ./test(main+0x12) [0x447e96] /lib64/libc.so.6(__libc_start_main+0xfd) [0x7f1bff50cd5d]
Re: Importing local modules in C style
On Thursday, 25 June 2015 at 14:37:28 UTC, Binarydepth wrote: I organize some exercises in some source files, it's more how I like to work with C. I'm used to organize source files this way and I was wondering if this was possible with D. If the files are in the same folder, just import local; in the main.d file and then run dmd main.d from the command line. You might need to ensure that there is only one main function. If the files are in different folders, you have to use a -I to the folder that contains local.d. I would recommend familiarizing yourself with Dub. It may make your life easier.
Re: Check if template has been passed a reference type or value type?
On Sunday, 7 June 2015 at 15:17:27 UTC, 1967 wrote: I've got a template that takes in a type. Sometimes the type is a class, sometimes a struct, sometimes just an int. It doesn't much matter what it is, but if it's a reference type I need to check if it's null so I can make it not null before using it. I get an error if I try to check if a value type is null so I'd like to put a "static if" to check if the type passed to the template is a nullable one so I can avoid checking the value types passed in. What do I have to do to check for nullability? A simple test: http://dpaste.dzfl.pl/3b8c5a0bb69c
Using C library libsndfile with D
Hi I want to read wav files. I thought I can use libsndfile since I am quite familiar with it. I downloaded the project from. https://github.com/D-Programming-Deimos/libsndfile I add the sndfile.di file to my project. I thought I could directly use libsndfile.dll since D directly supports C. But I am getting link errors. Can I use a C DLL directly ? Do I have to add anything to my dub.json file if dll is my project file ? What is "Deimos" stands for ? Is it collections of bindings ? Does community supports "Deimos" projects?
Compiler complaining about code that can't be reached, builtin types .equals()
I have a method, containsValue() in a class similar to java.util.HashMap. The class is a template class, instantiated with 2 parameters, K key, V value. bool containsValue(V value){ // dlang associative array, .values returns dynamic array of values in the aa auto values = this.internal_arr.values; /* * isBuiltIn() checks against all the builtin types in D * returns true if value instantiated as int, double, immutable(char)[] etc... * returns false iff value is a user defined object */ if(!isBuiltIn(value)){ foreach(val; values){ if(val.equals(value)) return true; } } // isBuiltin() false, assume builtin type, use "==" for comparison else{ foreach(val; values){ if(val == value) return true; } } return false; } The problem I'm having is using a D builtin type for the value parameter. The compiler tells me "no property 'equals' for type 'string'" in the containsValue() method. Well that's well and good, but I already know that which is why I check if the class has been instantiated with a builtin type or a user defined type. My question: Is there any way around the compiler complaining about this? The code doesn't allow (as best I can tell) the .equals() method to be called when "value" is a builtin type, so why does the compiler still complain? As a side note, I couldn't get std.traits.isBuiltinType(T) to work, so the function isBuiltIn() is not just calling std.traits.isBuiltinType(T), it's checking the typeid(value) against D builtin typeids.
Re: Using C library libsndfile with D
On 06/25/2015 11:12 AM, kerdemdemir wrote: > I downloaded the project from. > https://github.com/D-Programming-Deimos/libsndfile > > I add the sndfile.di file to my project. > > I thought I could directly use libsndfile.dll since D directly supports > C. But I am getting link errors. Bindings are for compilation only. You still need to link with the libraries, which varies by platform. D has the pragma(lib) feature where you can tell the compiler to link with a specific library as well. For example: pragma(lib, "curl"); You would probably use "sndfile" in your case (not sure): pragma(lib, "sndfile"); > Can I use a C DLL directly ? Yes. > Do I have to add anything to my dub.json file if dll is my project file ? I will let others answer that. I don't know Windows anymore. > What is "Deimos" stands for ? All the names come from planet Mars. Phobos is its large moon and Deimos is the small one. > Is it collections of bindings ? Yes. > Does community supports "Deimos" projects? Yes. Ali
Re: Compiler complaining about code that can't be reached, builtin types .equals()
On 06/25/2015 11:26 AM, Sean Grimes wrote: > /* >* isBuiltIn() checks against all the builtin types in D >* returns true if value instantiated as int, double, > immutable(char)[] etc... >* returns false iff value is a user defined object >*/ > if(!isBuiltIn(value)){ > foreach(val; values){ > if(val.equals(value)) > return true; > } > } That is a run-time conditional. There is no guarantee for the compiler that isBuiltIn() will return 'true' for every 'value'. For example, it can return 'false' for 42 but 'true' for 43. To enable or disable code sections you can use 'static if'. However, isBuiltIn must be evaluable at compile time as well. Since isBuiltIn works with values (not types) in your case, you can't pass it to 'static if': static if (!isBuiltIn(value)) { // <-- compilation error You want isBuiltIn to be a template which works on a type (V in your case). Here is a short example which treats 'int' and 'double' as built-in only: import std.typetuple; bool isBuiltIn(T)() { foreach (T2; TypeTuple!(int, double/*, ... */)) { if (is (T2 == T)) { return true; } } return false; } struct S(V) { void foo(V v) { static if (!isBuiltIn!V) { /* Assumes that non-built-ins support bar(). */ v.bar(); } } } void main() { auto s = S!int(); s.foo(42); } Ali
Re: Abstract sockets (linux)
On Thu, 25 Jun 2015 15:56:04 + freeman via Digitalmars-d-learn wrote: > I am having trouble using abstract sockets on Linux. > > Here is sample python code that works, which works: > ptm_sockname = "\0/var/run/ptmd.socket" > sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) > sock.connect(ptm_sockname) > sock.setblocking(1) > sock.sendall('get-status detail') > > Similar code in D, which does not work: > string socket_name = "\0/var/run/ptmd.socket"; > auto address = new UnixAddress(socket_name); > auto sock = new Socket(AddressFamily.UNIX, SocketType.STREAM); > scope(exit) sock.close(); > sock.blocking = true; > sock.connect(address); > sock.send("get-status detail"); > > This is the equivalent with socat, which works: > $ echo "get-status detail" | socat - > ABSTRACT-CLIENT:/var/run/ptmd.socket > > My test D program exits on connect: > std.socket.SocketOSException@runtime/phobos/std/socket.d(2674): > Unable to connect socket: Connection refused > > Any pointers? instead of: string socket_name = "\0/var/run/ptmd.socket"; try: string socket_name = "/var/run/ptmd.socket"; works for me
Re: Compiler complaining about code that can't be reached, builtin types .equals()
On Thursday, 25 June 2015 at 18:43:31 UTC, Ali Çehreli wrote: On 06/25/2015 11:26 AM, Sean Grimes wrote: Here is a short example which treats 'int' and 'double' as built-in only: import std.typetuple; bool isBuiltIn(T)() { foreach (T2; TypeTuple!(int, double/*, ... */)) { if (is (T2 == T)) { return true; } } return false; } struct S(V) { void foo(V v) { static if (!isBuiltIn!V) { /* Assumes that non-built-ins support bar(). */ v.bar(); } } } void main() { auto s = S!int(); s.foo(42); } Ali Ali, Thanks that works for me. - Sean
Re: Abstract sockets (linux)
On Thursday, 25 June 2015 at 18:50:29 UTC, Daniel Kozak wrote: Any pointers? instead of: string socket_name = "\0/var/run/ptmd.socket"; try: string socket_name = "/var/run/ptmd.socket"; works for me It is the null character that makes it an abstract socket (see man unix). There is no file /var/run/ptmd.socket, as what follows the null character is just a name: $ ls -al /var/run/ptmd.socket ls: cannot access /var/run/ptmd.socket: No such file or directory Here is what happens when I remove the null: std.socket.SocketOSException@runtime/phobos/std/socket.d(2674): Unable to connect socket: No such file or directory
Re: Abstract sockets (linux)
On 06/25/2015 08:56 AM, freeman wrote: I am having trouble using abstract sockets on Linux. Here is sample python code that works, which works: ptm_sockname = "\0/var/run/ptmd.socket" sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect(ptm_sockname) sock.setblocking(1) sock.sendall('get-status detail') Similar code in D, which does not work: string socket_name = "\0/var/run/ptmd.socket"; auto address = new UnixAddress(socket_name); auto sock = new Socket(AddressFamily.UNIX, SocketType.STREAM); scope(exit) sock.close(); sock.blocking = true; sock.connect(address); sock.send("get-status detail"); This is the equivalent with socat, which works: $ echo "get-status detail" | socat - ABSTRACT-CLIENT:/var/run/ptmd.socket My test D program exits on connect: std.socket.SocketOSException@runtime/phobos/std/socket.d(2674): Unable to connect socket: Connection refused Any pointers? I've found an old example of mine, which uses abstract sockets. Apparently, it was a concurrency experiment as well. Just translated from Turkish to English: http://ddili.org/ornek_kod/client_server.d One difference I see is that mine doesn't set blocking. You can use it like this: 1) Start it as a server: ./deneme --role=server 2) Start as many clients as needed: ./deneme --role=client Ali P.S. And here is the original Turkish version: http://ddili.org/ornek_kod/istemci_sunucu.d
Re: Using C library libsndfile with D
On Thursday, 25 June 2015 at 18:29:23 UTC, Ali Çehreli wrote: D has the pragma(lib) feature where you can tell the compiler to link with a specific library as well. For example: pragma(lib, "curl"); You would probably use "sndfile" in your case (not sure): pragma(lib, "sndfile"); This is the first time I've heard of pragma(lib). It's a nice feature that should be added to the compiler documentation.
Re: Using C library libsndfile with D
On 6/25/15 3:51 PM, bachmeier wrote: On Thursday, 25 June 2015 at 18:29:23 UTC, Ali Çehreli wrote: D has the pragma(lib) feature where you can tell the compiler to link with a specific library as well. For example: pragma(lib, "curl"); You would probably use "sndfile" in your case (not sure): pragma(lib, "sndfile"); This is the first time I've heard of pragma(lib). It's a nice feature that should be added to the compiler documentation. http://dlang.org/pragma.html#lib It's got some problems though. Not everyone's system is the same. -Steve
Re: Using C library libsndfile with D
On 06/25/2015 12:51 PM, bachmeier wrote: pragma(lib, "sndfile"); This is the first time I've heard of pragma(lib). It's a nice feature that should be added to the compiler documentation. They are all here: http://dlang.org/pragma.html pragma(inline) is the latest, which will be available in 2.068. Ali
Re: Using C library libsndfile with D
On Thursday, 25 June 2015 at 19:54:34 UTC, Ali Çehreli wrote: They are all here: http://dlang.org/pragma.html pragma(inline) is the latest, which will be available in 2.068. Ali I meant on this page: http://dlang.org/dmd-linux.html Someone starting out with D might not look at the pragma documentation. pragma(lib) is easy to miss even if you read that page.
Re: Using C library libsndfile with D
On Thursday, 25 June 2015 at 19:54:40 UTC, Steven Schveighoffer wrote: http://dlang.org/pragma.html#lib It's got some problems though. Not everyone's system is the same. -Steve Okay. Then I guess it should not be pushed.
Re: Using C library libsndfile with D
You probably need to make a .lib file from the dll too. The implib program does that. If you don't have it, if you wanna email me the libsoundfile.dll program, I'll run it and make the .lib for you.
Re: Importing local modules in C style
On Thursday, 25 June 2015 at 17:20:46 UTC, jmh530 wrote: On Thursday, 25 June 2015 at 14:37:28 UTC, Binarydepth wrote: I organize some exercises in some source files, it's more how I like to work with C. I'm used to organize source files this way and I was wondering if this was possible with D. If the files are in the same folder, just import local; in the main.d file and then run dmd main.d from the command line. You might need to ensure that there is only one main function. If the files are in different folders, you have to use a -I to the folder that contains local.d. I would recommend familiarizing yourself with Dub. It may make your life easier. Made a mistake. I was testing this with rdmd. rdmd main.d works fine because it builds dependencies, but dmd main.d does not work. You need it like you had it before, dmd main.d local.d.
Re: Using C library libsndfile with D
On Thursday, 25 June 2015 at 19:54:34 UTC, Ali Çehreli wrote: On 06/25/2015 12:51 PM, bachmeier wrote: pragma(lib, "sndfile"); This is the first time I've heard of pragma(lib). It's a nice feature that should be added to the compiler documentation. They are all here: http://dlang.org/pragma.html pragma(inline) is the latest, which will be available in 2.068. Ali I would expect documentation was to be saying "Added on 2.068" somewhere for it.
Re: Typed Message Passing between D Processes
On Thursday, 25 June 2015 at 14:04:23 UTC, Per Nordlöw wrote: Is there an alternative to http://dlang.org/phobos/std_process.html#.pipe that can be used to do _typed_ _message_ _passing_ between two D processes with the same convenience as `send` and `receive` in std.concurrency ? Either in Phobos or in a third party library? not sure if this is quite what you are looking for, or if the performance overhead is acceptable but have you looked at msgpack to go on top of a lower level pipe ?
compile shared lib with dub
i want to build a shared library (.so) with dub. currently i compile with a shell script, but i'd like to use dub [code] dmd -c test.d -fPIC dmd -ofcod4xalicebridge.so test.o -shared -g -w -debug -version=Have_cod4xalicebridge [/code] could anyone tell me how my dub.json has to look like? my >failing< dub.json :/ [code] { "name": "cod4xalicebridge", "description": "A minimal D application.", "copyright": "Copyright © 2015, root", "authors": ["root"], "targetType": "dynamicLibrary", "dflags": ["-fPIC", "-shared"], "dependencies": { } } [/code]
Re: compile shared lib with dub
ok i actually did everything right x3 ... but my code threw some warnings which are interpreted as errors by default. /solved
Re: Using C library libsndfile with D
D has the pragma(lib) feature where you can tell the compiler to link with a specific library as well. For example: pragma(lib, "curl"); I want to try that as soon as I get home from work. You probably need to make a .lib file from the dll too. The implib program does that. If you don't have it, if you wanna email me the libsoundfile.dll program, I'll run it and make the .lib for you. Your advice and your time is very important for me. I will try to run implib. I think it is important to get use to this tool for future anyways. Thanks alot Erdem