This is kind of silly, and I probably missed something, but for
some reason I can't get any kind of text file opened when using
readText from std.file. This is what I'm trying to do:
import std.stdio;
import std.file;
int main(string[] args)
{
if (!isFile(args[0]))
{
Oh, I just figured out what was going wrong. Apparently, args[0]
is the path to the program itself, and not the first argument.
args[1] is what I need to start reading from!
On Sunday, 17 June 2012 at 08:35:58 UTC, Jonathan M Davis wrote:
Also, you need to check exists before you check isFile,
otherwise isFile will
blow up if the file doesn't exst. And both of those are
properties, so you
should be calling them like
auto filename = args[1];
if(!filename.exists ||
A quick and simple question, but I couldn't find the answer to it
by myself: how do I cast the return type of std.array.splitter()
into a string[]?
According to the compiler, splitter() has a return type Result.
How useful... I assume it's a disguised tuple? If I try to simply
assign the resu
On Sunday, 17 June 2012 at 11:58:58 UTC, Jonathan M Davis wrote:
splitter(" a b ") is going to return a range of strings. If you
were to do
array(splitter("a b ")), you'd get ["", "a", "b"].
Aha, that worked! Thanks!
Still makes me wonder how you're supposed to figure out that this
type is a
Is it possible to write a static library in D and then use it in a program
written in C? I've found instructions about using DLLs here on the website,
but there is no mention about using static libraries instead.
Also, is it possible to use the same method on Linux, just with .a files
instead? Or
Ah, I see, thanks! I'll try that.
While I don't have a problem with using DMC, but others who are willing to join
my
project might have one... Right now I'm using MinGW, so it would definitely be
useful to know how to convert the libraries to the format it understands...
Though
from the looks of
All right, it worked, when the D side is this:
module techborg;
import std.c.stdio;
extern(C):
shared int ResultD;
int Process(int Value)
{
printf("You have sent the value: %d\n", Value);
ResultD = (Value % 5);
return ResultD;
}
However, if I wanted to us
Hmm, not being able to use D function kinda defeats the purpose of using it in
the
first place. Ah well, let's see if people know more about this elsewhere.
Anyway, I'm trying to compile this under Linux now. DMD works brilliantly and I
get techborg.a file. I do this (using Debian x64):
$ gcc -m
All right, found out how to make it compile. There are two ways:
1) Using DMD for the D part, DMC for the C part and combining them. This is
the batch file I use for that:
dmd -c -lib dpart.d
dmc cpart.c dpart.lib phobos.lib
2) Using DMD for the D part, DMC for the C part, DMD for combining them
Hmm, no, it won't work right on Linux for some reason. This is the output:
/usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../libphobos2.a(deh2_4e7_525.o): In
function `_D2rt4deh213__eh_finddataFPvZPS2rt4deh213DHandlerTable':
src/rt/deh2.d:(.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh213DHandlerTable+0x
Everything is right from what I can tell. This is the code I use for the D part:
module dpart;
import std.c.stdio;
extern(C):
shared int ResultD;
int Process(int Value)
{
printf("You have sent the value: %d\n", Value);
ResultD = (Value % 5);
return ResultD;
OK, well this is interesting... I managed to compile it but it's quite odd. In
order to do that, I added a call to main() in my Process() function, and then
added an empty main() in the D part before "extern(C)". It seems that there are
no
conflicts, too.
Andrej, that line is there. But it really
This should be a very elementary question. How do you get a string off stdin?
Or an integer, or a boolean, for that matter? If I use this:
float MyFloat;
string MyString;
readf("%f", &MyFloat);
writeln(MyFloat);
readf("%s", &MyString);
writeln(MyString);
I get the float printed correc
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
Ah, I see, that makes sense. And it now compiles correctly, thanks.
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;
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
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
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
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
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!
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?
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
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.
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
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.
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
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.
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...
> 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
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?
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?
According to the Derelict page, there already are unofficial bindings.
But I guess they wouldn't work with Derelict2 anyway.
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;
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
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
Ah, that did the trick, thanks!
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
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?
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
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
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)",
I see. Well, I guess I'll have to stick to static ones until this gets
sorted out.
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
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
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
Oh, so structs themselves are only definitions and not global
variables, I see. Thanks.
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
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
tem log says that it failed to
initialise lua51.dll, even though I used it with C just fine. Any
ideas about what could be wrong here?
This is the batch file that I use to compile my executable:
https://github.com/GreatEmerald/Arcomage-GreatEmerald/blob/libarcomage-dev/clarcomage/src/compile.cmd
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
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
> 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
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
55 matches
Mail list logo