Re: Frontend and backend communication

2011-11-29 Thread Dainius (GreatEmerald)
Ah, I see, that makes sense. And it now compiles correctly, thanks.

Re: Frontend and backend communication

2011-11-29 Thread Dainius (GreatEmerald)
I seem to have another problem with the function pointer approach. I am trying to set up a function that would pass the function pointers from C to D, and DMD refuses to compile it: If I have the function pointer struct with D calling convention pointers, like this: struct S_FrontendFunctions

Re: Frontend and backend communication

2011-10-18 Thread Dainius (GreatEmerald)
I'm trying to implement the function pointer system right now, and it seems to work on the C side, but not D. I assume I'm missing some kind of syntax here. I have these global variables: struct S_FrontendFunctions { void function() RedrawScreen; void function(const

Re: Transferring global variables from D to C

2011-10-01 Thread Dainius (GreatEmerald)
> However, this gets quite inefficient with a lot of different strings, I just had an idea, perhaps it's possible to work around this particular point by creating a wrapper function that converts the passed variable into the C string type? The problem with this idea is that I can't find a way to p

Transferring global variables from D to C

2011-10-01 Thread Dainius (GreatEmerald)
I'm testing how I could use globals in C, when using D as a library and C as a frontend. So far it seems to be working well with some data types, but not so much with a few others. First of all, one obvious problem is strings, since they are a lot different in D. I can transfer them with a wrapper

CLI library?

2011-09-13 Thread Dainius (GreatEmerald)
Is there any library that would allow me to use the extended terminal features (like coloured backgrounds and custom/multiple resolution support) that works with D and is not platform-dependent? Something similar to ncurses? I know that there was a dcurses project, but it seems that it only works w

Re: Importing D libraries

2011-08-25 Thread Dainius (GreatEmerald)
Yeap, it's definitely a bug, and the temp file is in fact the library that I need. Anyway I'm trying to compile it on Windows now. However, there are two problems. First of all, the Windows Command Prompt does not expand wildcards, and DMD does not take it as an argument. Thus importing LuaD as a

Re: Importing D libraries

2011-08-19 Thread Dainius (GreatEmerald)
Anyone have any ideas about this? Or is it a bug? If I make RDMD chatty and listing all warnings, I get these lines: dmd -w -wi -lib -L-llua -I../include/LuaD -v -o- 'arco.d' -I'.' >arco.d.deps dmd -w -wi -lib -L-llua -I../include/LuaD -of'/tmp/.rdmd/home/dainius/src/arco.d.3C10152112FB7E5

Re: Importing D libraries

2011-08-10 Thread Dainius (GreatEmerald)
A question about RDMD - can it compile libraries as well? Since right now it compiles my library code fine, yet I get an .a file that is mere 72 bytes of size, so I'm pretty sure that it's not what I am supposed to be getting. The command I use to compile it is: rdmd --build-only -lib -L-llua

Re: Frontend and backend communication

2011-08-10 Thread Dainius (GreatEmerald)
Oh, so structs themselves are only definitions and not global variables, I see. Thanks.

Re: Frontend and backend communication

2011-08-10 Thread Dainius (GreatEmerald)
I seem to have run into a problem with the function pointer method here. I have this code: arco.d: struct FrontendFunctions { void function(SoundTypes) Sound_Play; void function() RedrawScreenFull; void function(const char*, int) PrecacheCard; void function(Car

Re: Frontend and backend communication

2011-07-29 Thread Dainius (GreatEmerald)
Yes, this is a library, so a main() there would be rather pointless. However, it seems that on many occasions compilers will simply not acknowledge anything without one, so I guess at least a declaration is in order... I'll have to try that out once I get back on Windows. Meanwhile, on Linux, I am

Re: Frontend and backend communication

2011-07-29 Thread Dainius (GreatEmerald)
So, now my (static) library nearly links in Win32. There is only one link error, and apparently it's generated by phobos: ..\lib\phobos.lib(dmain2) Error 42: Symbol Undefined __end Any clues about what is happening? Admittedly, that phobos.lib is from March 20, 2011, so it's rather old b

Re: Frontend and backend communication

2011-07-29 Thread Dainius (GreatEmerald)
I see. Well, I guess I'll have to stick to static ones until this gets sorted out.

Re: Frontend and backend communication

2011-07-28 Thread Dainius (GreatEmerald)
On Thu, Jul 28, 2011 at 10:37 PM, Kai Meyer wrote: > On 07/27/2011 04:40 PM, Dainius (GreatEmerald) wrote: > > One reason for the confusing responses is that in your original post you > said: > "a frontend (a library)", "a backend (an > executable)",

Re: Frontend and backend communication

2011-07-28 Thread Dainius (GreatEmerald)
Hmm, there are still a whole lot of functions that call Shuffle(), so it might not be ideal. However, this gives me an idea - if a pointer to a function can be a parameter, can it be a global variable? In that case, the frontend would indeed be able to overwrite the function that the backend calls

Re: Frontend and backend communication

2011-07-27 Thread Dainius (GreatEmerald)
No no. It's the other way round. Shuffle() is in the library (backend). PlaySound() is in the executable (frontend). Since I don't want the library to be dependent on any sound libraries, I can't have PlaySound() in it. And there is no other way that I can think of to execute PlaySound() just at th

Re: Frontend and backend communication

2011-07-27 Thread Dainius (GreatEmerald)
Hm, well, at least I don't know how it's possible for a binary to overwrite/capture a library's function. Would you care to give an example?

Frontend and backend communication

2011-07-27 Thread Dainius (GreatEmerald)
I have one program design problem and I wonder if anyone here could give any suggestions about it. The situation is like this: I am splitting a game into a frontend (a library) and a backend (an executable). The backend is going to handle all the game mechanics, while the frontend is going to handl

Re: Importing D libraries

2011-07-26 Thread Dainius (GreatEmerald)
Ah, that did the trick, thanks!

Re: Importing D libraries

2011-07-26 Thread Dainius (GreatEmerald)
I updated the DMD and tried RDMD, but still no luck. Linker errors galore. You can see all of them here: http://pastebin.com/C6cRVGKt

Re: Importing D libraries

2011-07-26 Thread Dainius (GreatEmerald)
Hmm, apparently it requires a strict compilation order. If I just add all .d files in no particular order, I get lots of linker errors, for example: LuaTest.o: In function `_D4luad4base9LuaObject9checkTypeFPT4luad1c3lua9lua_StateiiPxaZv': LuaD/luad/c/lua.d:(.text._D4luad4base9LuaObject9checkTypeFP

Importing D libraries

2011-07-26 Thread Dainius (GreatEmerald)
I must be missing something incredibly obvious here, but I can't find out what it is... I'm trying to build a very simple test program for LuaD, right now it simply imports the library. But it throws a linker error for some reason. Here's the program I'm trying to compile: import std.stdio;

Re: SDL with D

2011-07-12 Thread Dainius (GreatEmerald)
According to the Derelict page, there already are unofficial bindings. But I guess they wouldn't work with Derelict2 anyway.

Re: SDL with D

2011-07-12 Thread Dainius (GreatEmerald)
I see. And what about Lua? I see lots and lots of different libraries for that on dsource, and there is even some support in Derelict as well. I assume that LuaD is the one in active development and most fitting for current D2?

SDL with D

2011-07-11 Thread Dainius (GreatEmerald)
Can D interface with SDL directly? Right now the program I'm writing uses C as a sort of a wrapper for D and SDL to communicate, and I guess it would be simpler, cleaner and more reliable if D could call SDL functions directly. If it works, is there anything I should keep in mind about it?

Re: readf with strings

2011-06-23 Thread Dainius (GreatEmerald)
> I have a related enhancement request since lot of time: > http://d.puremagic.com/issues/show_bug.cgi?id=4716 > > Bye, > bearophile > That's exactly what I'd like to see. Voted. After all, D is created with practicality in mind, and doing all that parsing is the opposite of what it's trying to a

Re: readf with strings

2011-06-22 Thread Dainius (GreatEmerald)
I see. Using %s does indeed work with ints, and chomp(readln()) works with strings. It's rather counter-intuitive, though. I wonder why there isn't a simpler way to do this, something like writeln() - you could input the variables as parameters and it would automatically read them...

Re: Using D libs in C

2011-04-15 Thread Dainius (GreatEmerald)
They both return 4, and both short and int16_t return 2. Also, I've noticed that if I use a struct (of four ints) instead, the same thing happens, the parameters are not correct. And yes, of course they are extern already.

Re: Using D libs in C

2011-04-15 Thread Dainius (GreatEmerald)
All right, found something really odd today, might be a bug. If in C I have this: int16_t D_getPictureCoordX(int Pool, int Card); And in D I have this: short D_getPictureCoordX(int Pool, int Card); When I call D_getPictureCoord() from C, the parameters are all off, it seems that it receives eit

Re: Using D libs in C

2011-03-29 Thread Dainius (GreatEmerald)
Oh, never mind. About sending strings, I got it working, I just had to create a function like this in D: immutable(char)* GetString() { return StringD.toStringz(); } As for D not compiling, I had to declare it in D, d'oh :D And that extern is in the wrong place there.

Re: Using D libs in C

2011-03-29 Thread Dainius (GreatEmerald)
All right, I solved that part of the problem by creating a linked list. However, getting the string out of D is still problematic, namely because toStringz() gives me an immutable char*, and I don't seem to be able to pass those, since I can't assign those to immutable variables outside their const

Re: Using D libs in C

2011-03-27 Thread Dainius (GreatEmerald)
Hmm, if I was to do it from C, I would have to deal with all the allocation, since I don't know how large the array is going to be when it's complete, while D doesn't need to know since it uses dynamic arrays.

Re: Using D libs in C

2011-03-27 Thread Dainius (GreatEmerald)
Well, the situation is like this: D creates a list of names of files that should be loaded by C. C then takes the list, uses it to load the files, then stores both the pointers to the loaded files and the names of the files in an array of structs. Then when C wants to access the files, it asks D ab

Re: Using D libs in C

2011-03-27 Thread Dainius (GreatEmerald)
OK, now I have a question about passing variables. In D, I have a dynamic array of strings and I want C to get that array. Yet C supports neither dynamic arrays nor strings. So is there a way to accomplish this?

Re: Using D libs in C

2011-03-25 Thread Dainius (GreatEmerald)
Oh, I found the problem... It's just me forgetting that my library has to go before phobos to compile it. So right now it works perfectly! Thanks!

Re: Using D libs in C

2011-03-24 Thread Dainius (GreatEmerald)
Hmm... Spent a few hours trying to figure out how to update GCC and all to conform to the requirements for 2.0.52, and at seems that it compiles my small test program just fine, but it fails on compiling the main project for some reason. And the linker outputs half-scrambled things. Anyway, here's

Re: Using D libs in C

2011-03-24 Thread Dainius (GreatEmerald)
Ah, including pthread indeed works, but now I've run into another problem related to Linux and architecture. I want to use D for my program that also uses things like SDL and Lua. Earlier when I compiled it, I always did so with 64-bit libraries. But D is so far only in 32-bits, thus when compiling

Re: Using D libs in C

2011-03-23 Thread Dainius (GreatEmerald)
Ooh, thanks, it works! Though linking in Linux is still quite odd. So the final code for my test program is this: cpart.c #include extern int ResultD; int Process(int Value); int rt_init(); int rt_term(); void LinuxInit(); int main() { int num; rt_init(); //I

Re: Using D libs in C

2011-03-22 Thread Dainius (GreatEmerald)
I've tried compiling the same on Linux and the program still crashes (with segmentation fault there). No error message or anything. And it doesn't matter if I compile the thing from .obj or from .lib files, I still get the same crashes. So it's a real showtopper for me, since what's the use of havi

Re: Using D libs in C

2011-03-20 Thread Dainius (GreatEmerald)
Now I'm trying to do something more complicated, and it seems that while importing works (it compiles and links fine), actually using the imported things or pretty much anything that D offers makes the program crash. For instance, in the D part: --- module dpart; import std.stdio;