Growing multidimensional dynamic arrays

2012-10-08 Thread KillerSponge

Hi all,

This seems like something that should be possible: how do I grow 
multidimensional arrays?


I want something like this:

struct X{ ... };
X*[][] listOfLists;
foreach ( x ; otherListOfX ) {
   if ( newListForArbitraryReason ) {
  listOfLists ~= new X*[];
   }

   listOfLists[$] ~= x;
}

Now, this doesn't compile, because I _have_ to give a size to new 
X*[](arbitrary_number), and the listOfLists[$] ~= x; line never 
works (hangs at runtime).


So, how would I go about doing this? My apologies if this is 
something really obvious.


Re: Growing multidimensional dynamic arrays

2012-10-08 Thread KillerSponge

On Monday, 8 October 2012 at 13:56:00 UTC, Ali Çehreli wrote:
I don't see the need for 'new' nor the use of a pointer, so I 
will not use them (yet): :)


import std.stdio;

struct X
{
int i;
}

void main()
{
X[][] listOfLists;

auto otherListOfX = [ X(1), X(2), X(3) ];
auto newListForArbitraryReason = true;

foreach (x; otherListOfX) {
if (newListForArbitraryReason) {
X[] newList = [ x ];
listOfLists ~= newList;
}
}

writeln(listOfLists);
}

The body of foreach can be shorter:

listOfLists ~= [ x ];

Also note that

- There is no need for the semicolon at the end of the struct 
definition.


- $ is not a valid index value. The last element is indexed by 
$-1.


Ali


Ah, that works great (even with pointers ;)! Thanks a lot! :) It 
seems so obvious now.


And the use of $ was indeed a stupid mistake on my part. I guess 
I was confused because of the way it is often used in slicing. I 
really should pay attention to that :)


Re: Using Cairo library bindings on Windows

2012-09-29 Thread KillerSponge
On Friday, 28 September 2012 at 22:20:54 UTC, Andrej Mitrovic 
wrote:

On 9/28/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote:

I have some win32 cairo samples on my github page.


Here you go: https://github.com/AndrejMitrovic/cairoDSamples

Just follow the readme instructions.


Wow, thank you so much for the quick reply and all the effort! I 
am going to try this out as soon as I can (which probably won't 
be until Monday, sorry..) and let you know how it works out :)


Using Cairo library bindings on Windows

2012-09-28 Thread KillerSponge

Hi all,

I'm fairly new to D, but so far everything has been going pretty 
smooth. I come from a C(++) background under Linux, so I'm used 
to having to specify the name of the needed .so, and the include 
directory of the headers when using an external library.


I am now trying to build a small D application on Windows to play 
around with Cairo, the graphics library. I found D bindings for 
it in the Deimos repository 
(https://github.com/D-Programming-Deimos/cairo), downloaded the 
dll files from de Cairo website (zlib, libcairo and libpng) and 
put them in the working directory of the project.


When I try to compile the example.d from the Cairo bindings with 
rdmd without specifying anything, I get (as I would expect) a 
whole bunch of error 42: undefined symbol errors. But, when I 
try to specify the dll by adding -L 
{working_dir}\\libcairo-2.dll, I get an Error 43: Not a Valid 
Library File message.


I have tried to use the .lib files (which also gives error 43), 
and even tried to convert them using implib, which just results 
in the same bunch of error 42s (at least it's a valid library, I 
suppose?)


As I mentioned, I'm quite new to all this, so it might be 
something really obvious I'm missing, but I'm totally stumped at 
this point. Does anyone here maybe have any idea what the problem 
could be? :)