Re: Function pointer array slice?
On Sat, 11 Jul 2015 09:54:40 +, tcak wrote: On Saturday, 11 July 2015 at 09:30:43 UTC, Tofu Ninja wrote: So simple syntax question, how do I make an array slice of function pointers? I just have no idea where to put the [] on something like void function() nothrow pure @nogc @safe arrayName; Or should I just alias it and make an array of the alias? alias f = void function() nothrow pure @nogc @safe; f[] arrayName; Alias is the correct way IMO. yet void function() nothrow pure @nogc @safe [2]arrayName; is perfectly fine too. signature.asc Description: PGP signature
Re: std.concurrency: The fate of unmatched messages
On Saturday, 11 July 2015 at 02:15:02 UTC, ketmar wrote: so simply don't receive the messages you don't need right now. as i said, `receive()` doesn't look to top message only, it scans the whole mailbox, trying to find a message that matches. you can use `receiveTimeout()` to do nothing if there are no suitable messages. you can also adjust mailbox size and mode. Okay, so it doesn't purge unrecognized messages, then! That's what I needed to know!
Function pointer array slice?
So simple syntax question, how do I make an array slice of function pointers? I just have no idea where to put the [] on something like void function() nothrow pure @nogc @safe arrayName; Or should I just alias it and make an array of the alias? alias f = void function() nothrow pure @nogc @safe; f[] arrayName;
Re: Function pointer array slice?
On Saturday, 11 July 2015 at 10:54:45 UTC, ketmar wrote: On Sat, 11 Jul 2015 09:54:40 +, tcak wrote: On Saturday, 11 July 2015 at 09:30:43 UTC, Tofu Ninja wrote: So simple syntax question, how do I make an array slice of function pointers? I just have no idea where to put the [] on something like void function() nothrow pure @nogc @safe arrayName; Or should I just alias it and make an array of the alias? alias f = void function() nothrow pure @nogc @safe; f[] arrayName; Alias is the correct way IMO. yet void function() nothrow pure @nogc @safe [2]arrayName; is perfectly fine too. Ahh, guess that makes sense, I kept trying to put the [] over near function()... looks weird as hell though. I really wish you could put types in parens, I feel like things like this would make way more sense if you could write (void function() nothrow pure @nogc @safe)[] arrayName; Reading it, that makes wayyy more sense to me, to bad I can't write this...
Re: DUB Build Linker Library Search Path
On Friday, 10 July 2015 at 12:26:02 UTC, Per Nordlöw wrote: On Friday, 10 July 2015 at 12:04:53 UTC, Nordlöw wrote: Should be LFLAGS=-L/usr/lib/llvm-3.6/lib dub build --compiler=/usr/bin/dmd but still fails I can't find any place in the DUB sources that reads `LFLAGS` from the environment. Only one place when `DFLAGS` is read. A regression? Do you want me to add this? Hmm, an observation related to this topic. I've started using dub-0.9.24-beta.2 with the intention of converting to the new SDLang format. When reading the documentation I noticed that it is possible to specify environment flags in the .sdl-file. Can I use this to pass a -L linker flag?... dub.sdl: .. lflags -lclang $LFLAGS bash$ LFLAGS=/... dub build -c release It works :)
Re: why adding extern(C) cause a runtime error?
On Saturday, 11 July 2015 at 01:22:14 UTC, mzf wrote: win7 x86 dmd2.067.1 ok ubuntu x64 dmd2.067.1 error - import std.stdio; import std.socket; extern(C) void recv() { writeln(recv...); } extern(C) void send() { writeln(send...); } int main(string[] argv) { //copy from std.socket unittest immutable ubyte[] data = [1, 2, 3, 4]; auto pair = socketPair(); scope(exit) foreach (s; pair) s.close(); pair[0].send(data); auto buf = new ubyte[data.length]; pair[1].receive(buf); assert(buf == data); return 0; } -- send... recv... core.exception.AssertError@a.d(27): Assertion failure ./a() [0x43d61f] ./a(_Dmain+0xcc) [0x43d1bc] ./a(_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv+0x1f) [0x4400fb] ./a(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x2a) [0x44004e] ./a(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll()+0x30) [0x4400b4] ./a(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x2a) [0x44004e] ./a(_d_run_main+0x1dc) [0x43ffc8] ./a(main+0x17) [0x43d637] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7f5fabd8fec5] You basically overwrite the C send(2) and recv(2) functions with your code (the actual symbols, the linker will yours instead the real ones). So std.socket doesn't call the C functions but yours. Yours obviously don't send and receive data. If you really want to overwrite these functions you might be able to call the original ones via dlsym.
Re: Function pointer array slice?
On Saturday, 11 July 2015 at 09:30:43 UTC, Tofu Ninja wrote: So simple syntax question, how do I make an array slice of function pointers? I just have no idea where to put the [] on something like void function() nothrow pure @nogc @safe arrayName; Or should I just alias it and make an array of the alias? alias f = void function() nothrow pure @nogc @safe; f[] arrayName; Alias is the correct way IMO.
Re: Array operations with array of structs
On Wednesday, 8 July 2015 at 06:05:54 UTC, ketmar wrote: do you see the gotcha? if you uncomment postblit or assigns, this build function fails to compile, as that operations aren't pure nothrow @nogc @trusted, and they will be used for either assign or postblitting. So after looking into it a little bit... It looks like the opAssigns can take all the attributes without throwing errors so that's good. The postblit can only not take @nogc due to the array duplication which is understandable. I think the postblit might be redundant anyway since the struct is built on a static array so there is no possibility of two different Vect3s pointing to the same data. Can someone confirm or does the postblit do anything else?
Re: Array operations with array of structs
On Saturday, 11 July 2015 at 13:31:12 UTC, Peter wrote: The postblit can only not take @nogc due to the array duplication which is understandable. I think the postblit might be redundant anyway since the struct is built on a static array so there is no possibility of two different Vect3s pointing to the same data. Can someone confirm or does the postblit do anything else? The postblit is pointless, yes. The `.dup` copies from one location to another, only for the assignment to copy everything back to the original location; and then the new array is discarded.
Re: Array operations with array of structs
On Saturday, 11 July 2015 at 13:31:12 UTC, Peter wrote: So after looking into it a little bit... So now I'm trying to multiply the array by a double but it's giving incompatible type errors. opBinary, opBinaryRight, and opOpAssign are defined. I have: struct Vector3 { public double[3] _p; @nogc this(in double[] p){ switch ( p.length ) { case 0: _p[0] = _p[1] = _p[2] = 0.0; break; case 1: _p[0] = p[0]; _p[1] = _p[2] = 0.0; break; case 2: _p[0] = p[0]; _p[1] = p[1]; _p[2] = 0.0; break; default: _p[0] = p[0]; _p[1] = p[1]; _p[2] = p[2]; break; } } @nogc this(in double p0, in double p1=0.0, in double p2=0.0){ _p[0] = p0; _p[1] = p1; _p[2] = p2; } @nogc this(in Vector3 other){ _p[] = other._p[]; } Vector3 opBinary(string op)(in Vector3 rhs) const if (op == +) { Vector3 result; result._p[] = this._p[] + rhs._p[]; return result; } Vector3 opBinary(string op)(in double rhs) const if (op == *) { Vector3 result; result._p[] = this._p[] * rhs; return result; } Vector3 opBinaryRight(string op)(in double lhs) const if (op == *) { Vector3 result; result._p[] = this._p[] * lhs; return result; } //... pure nothrow @trusted @nogc ref Vector3 opAssign(ref Vector3 rhs) { _p[] = rhs._p[]; return this; } pure nothrow @trusted @nogc ref Vector3 opAssign(Vector3 rhs) { _p[] = rhs._p[]; return this; } @nogc ref Vector3 opOpAssign(string op)(in double rhs) if (op == *) { this._p[] *= rhs; return this; } //... } unittest{ auto a = Vector3([2.0, 2.0, 0.0]); auto b = Vector3([1.0, 2.0, 1.0]); Vector3[] c = [a]; Vector3[] d = [b]; Vector3 e = a + b; //fine Vector3[] f; f[] = c[] + d[]; //fine e = 2*a; //fine e = 3.0*a; //fine f[] = 2*c[]; //Error: incompatible types for ((2) * (c[])): 'int' and 'Vector3[]' f[] = 3.0*c[]; //Error: incompatible types for ((3.0) * (c[])): 'double' and 'Vector3[]' }
DUB Different Library Name
Hello, I am trying to use Derelict's Allegro 5 in my DUB project, however, when I try to run `dub build` it says it cannot find liballegro-5.0.11.so and liballegro-5.0.so. I have both libraries installed as liballegro.so.5.0.11 and liballegro.so.5.0 under my Arch system respectively. Is there a way to tell DUB that these are the libraries it must use without making ugly symlinks?
Re: I'm getting NAN out of nowhere
On Thursday, 9 July 2015 at 15:14:43 UTC, Binarydepth wrote: This is my code : import std.stdio : writeln, readf; void main() { int[3] nums; float prom; foreach(nem; 0..2) { writeln(input a number : ); readf( %d, nums[nem]); prom+=nums[nem]; } writeln(prom/3.0); } I get prompted two times for a number and I then get NAN out of nowhere. foreach(nem; 0..3)
Re: DUB Different Library Name
On Saturday, 11 July 2015 at 16:43:39 UTC, serh wrote: Hello, I am trying to use Derelict's Allegro 5 in my DUB project, however, when I try to run `dub build` it says it cannot find liballegro-5.0.11.so and liballegro-5.0.so. I have both libraries installed as liballegro.so.5.0.11 and liballegro.so.5.0 under my Arch system respectively. Is there a way to tell DUB that these are the libraries it must use without making ugly symlinks? No Derelict package has a compile-time or link-time dependency on the libraries they bind. The libraries are loaded at run time. DUB doesn't know anything about those libraries, so you shouldn't be seeing such an error with 'dub build'. The only time you should see it is when trying to run the program. Could you please post the command line you used and the exact errors you're seeing?
Re: DUB Different Library Name
On Sunday, 12 July 2015 at 01:17:27 UTC, Mike Parker wrote: No Derelict package has a compile-time or link-time dependency on the libraries they bind. The libraries are loaded at run time. DUB doesn't know anything about those libraries, so you shouldn't be seeing such an error with 'dub build'. The only time you should see it is when trying to run the program. Could you please post the command line you used and the exact errors you're seeing? You are right, I am running dub run, I made a mistake in the original post. This is what I get when I run dub in the directory: http://codepad.org/BpnOHVSV As mentioned, I already have respective Allegro libs installed, but as liballegro.so.5.0 instead of liballegro-5.0.so and so on. The C++ linker sees them fine, but I am not sure how to make dmd/DUB see the correct libraries to link.
socket server help
Hello, I have a project of updater for a game with few functions for administrate the game and for this i need a server to communicate with my client side (written in C#). I started to create the server but i have a problem with the async part, i tried std.concurrency for the receive thread but i have a problem with spawn function (template std.concurrency.spawn cannot deduce function from argument types !()(void delegate(Tid ownerTid), Tid)). I'm not sure of this part and i don't know how to achieve that. The link of my server.d : https://github.com/Adwelean/EmperadorServer/blob/master/source/network/server.d I'd like to know how i could do for create this part. Sorry for my basic English, Quentin
Re: socket server help
On 12/07/2015 2:53 p.m., Adwelean wrote: Hello, I have a project of updater for a game with few functions for administrate the game and for this i need a server to communicate with my client side (written in C#). I started to create the server but i have a problem with the async part, i tried std.concurrency for the receive thread but i have a problem with spawn function (template std.concurrency.spawn cannot deduce function from argument types !()(void delegate(Tid ownerTid), Tid)). I'm not sure of this part and i don't know how to achieve that. The link of my server.d : https://github.com/Adwelean/EmperadorServer/blob/master/source/network/server.d I'd like to know how i could do for create this part. Sorry for my basic English, Quentin Perhaps try vibe.d? It does support what you want, automatically.
Calling D Code from Assembly
Is there a way I can call D code from assembly without declaring functions as extern(C) and and doing it the C way?
Re: Calling D Code from Assembly
On Sunday, 12 July 2015 at 04:30:58 UTC, John wrote: Is there a way I can call D code from assembly without declaring functions as extern(C) and and doing it the C way? SOLVED: Found the calling convention description. http://dlang.org/abi.html
Re: socket server help
On Sun, 12 Jul 2015 02:53:57 +, Adwelean wrote: Hello, I have a project of updater for a game with few functions for administrate the game and for this i need a server to communicate with my client side (written in C#). I started to create the server but i have a problem with the async part, i tried std.concurrency for the receive thread but i have a problem with spawn function (template std.concurrency.spawn cannot deduce function from argument types !()(void delegate(Tid ownerTid), Tid)). I'm not sure of this part and i don't know how to achieve that. The link of my server.d : https://github.com/Adwelean/EmperadorServer/blob/master/source/network/ server.d I'd like to know how i could do for create this part. the problem is that you cannot spawn a *delegate*, only *function*. i.e. `_receive` must be a free function, not a class/struct method. free function doesn't require context pointers and called function. method does require context pointer (`this`, to access class/struct fields), so it's delegate (a fat pointer under the hood, incompatible with simple pointers). note that compiler is not smart enough to see that some method never accesses fields of it's class/struct. so, you have to make your `_receive` either free function or static method -- it doesn't access class fields anyway, so it shouldn't be hard. signature.asc Description: PGP signature
Re: socket server help
On Sun, 12 Jul 2015 15:44:44 +1200, Rikki Cattermole wrote: Perhaps try vibe.d? It does support what you want, automatically. most of the time vibe.d seems to be overkill. that's like building a space ship to visit Aunt Ellie, who lives in a town nearby. signature.asc Description: PGP signature
Re: DUB Different Library Name
On Sunday, 12 July 2015 at 02:14:06 UTC, serh wrote: This is what I get when I run dub in the directory: http://codepad.org/BpnOHVSV As mentioned, I already have respective Allegro libs installed, but as liballegro.so.5.0 instead of liballegro-5.0.so and so on. The C++ linker sees them fine, but I am not sure how to make dmd/DUB see the correct libraries to link. This has nothing to do with DMD, DUB, or linking :) Derelict loads the shared libraries at runtime through the system API (LoadLibrary on Windows and dlopen elsewhere). Each package has a default set of library names it looks for. I was under the impression that liballegro-x.x.so was the common form for Allegro, so either I was wrong or things are different on Arch. Regardless, the default library names can be overridden. Just past the library names you need in the call to load: ``` DerelictAllegro5.load(liballegro.so.5.0); ``` That should do the trick for now. In the meantime, I'll update the loader to include this form in the default library name list as soon as I get the chance. Also, I recommend you take a look at the documentation for using Derelict at [1]. For future reference, when using DUB to manage a project, you need to be aware of the different kinds of error output. Sometimes it's from the compiler, sometimes from the linker, and sometimes from something that happened at run time. In your case, look at this line: derelict.util.exception.SharedLibLoadException@../../../.dub/packages/derelict-util-2.0.0/source/derelict/util/exception.d(35): The first part, 'derelict.util.exception.SharedLibLoadException' tells you that this is an exception being thrown by Derelict. That can only happen at run time. [1] http://derelictorg.github.io/using.html
Re: DUB Different Library Name
On Sun, 12 Jul 2015 02:14:04 +, serh wrote: As mentioned, I already have respective Allegro libs installed, but as liballegro.so.5.0 instead of liballegro-5.0.so and so on. The C++ linker sees them fine, but I am not sure how to make dmd/DUB see the correct libraries to link. Derelict doesn't do compile-time linking with libraries, it loads libraries in runtime. rather controversal approach, but it seems to work better for windows. the side effect of it is that: 1. build system can't use pkg-config (or another *-config) utility to link with correct libraries. 2. if your library is old, and Derelict was written against newer with some API added -- badaboom! even if you never used that new API. both problems are solvable, though. if you'll read Derelict documentation (and, maybe, sources) hard enough, you'll find a way to tell Derelict which library to load, and how to live with missing APIs. i can't give you a direct link, though, as i'm not using Derelict, but i'm pretty sure that it shouldn't be hard to find. signature.asc Description: PGP signature
Re: Function pointer array slice?
On Sat, 11 Jul 2015 11:37:03 +, Tofu Ninja wrote: void function() nothrow pure @nogc @safe [2]arrayName; is perfectly fine too. Ahh, guess that makes sense, I kept trying to put the [] over near function()... attributes are the parts of the type. and the rule is really simple: put [] array declaration immediately left of the array name. ;-) looks weird as hell though. I really wish you could put types in parens, I feel like things like this would make way more sense if you could write (void function() nothrow pure @nogc @safe)[] arrayName; Reading it, that makes wayyy more sense to me, to bad I can't write this... i agree, this is somewhat easier to read. but it requires grammar changes, i believe, and dunno what consequences that may have. yet it may worth filling a ER. signature.asc Description: PGP signature
Re: socket server help
On 12/07/2015 5:13 p.m., ketmar wrote: On Sun, 12 Jul 2015 15:44:44 +1200, Rikki Cattermole wrote: Perhaps try vibe.d? It does support what you want, automatically. most of the time vibe.d seems to be overkill. that's like building a space ship to visit Aunt Ellie, who lives in a town nearby. That seems like a great idea! Let's build space ships. After all, its not like it's rocket science. http://www.stuff.co.nz/the-press/news/69903405/rocket-lab-to-bring-200-jobs-to-canterbury-region But seriously, vibe.d is also pretty easy for most use cases. Hence why I'm saying it.
Re: socket server help
On Sun, 12 Jul 2015 17:32:23 +1200, Rikki Cattermole wrote: But seriously, vibe.d is also pretty easy for most use cases. Hence why I'm saying it. that's until your operations are very-very fast, or your libraries have async API. hit the synchronous API, and everything will start turning to a mess, with threads, locks and other niceties onboard. not that vibe.d is bad or limited -- it was designed to work with async APIs, and it does exactly that, and does that good. signature.asc Description: PGP signature