Re: Programming on OSX
On 01-Jan-12 3:27 AM, Jacob Carlborg wrote: On 2011-12-31 00:50, Joel Christensen wrote: I've got an Mac with OSX. But I have a few problems with using it with D. 1. I haven't got any media programming going. Could you please elaborate. Derelict is a library that contains bindings for OpenGL, OpenAL, SDL and DevIL among others. Thanks for replying Jacob. I looked up Derelict and it seem to say Derelict's SDL didn't work with OSX yet. I haven't done much digging though. I'm more interested in Allegro5 working with OSX, there's one Allegro library that works with Windows and Linux, but not OSX. On a bit different note. What's the differences with a library, a wrapper, and a binding? 2. The readln (etc) isn't much good, same problem as Linux. It can only add characters and remove characters from the end.
Programming on OSX
I've got an Mac with OSX. But I have a few problems with using it with D. 1. I haven't got any media programming going. 2. The readln (etc) isn't much good, same problem as Linux. It can only add characters and remove characters from the end.
Re: xml Bible for conversion for D
I don't care to learn xml at this stage. I just want to use it on that Bible file. On 19-Oct-11 8:03 PM, Bernard Helyer wrote: I think I want to stick with the current std xml library for now.
Re: xml Bible for conversion for D
Thanks Adam. :-) It seems to be working now, with the stuff you gave me. I was thinking of making a text file from it that my programs can load from. avoiding the xml file, so they load faster. But I think I'll have my program(s) use the xml file each time they're run, in the mean time.
xml Bible for conversion for D
I've got xml text of a Bible version. I want to get the text in the following format: class Bible { Book[] bs; } class Book { Chapter[] cs; } class Chapter { Verse[] vs; } class Verse { string v; } Here's a part of the xml file: ?xml version=1.0 encoding=ISO-8859-1? bible b n=Genesis c n=1 v n=1In the beginning, God created the heavens and the earth./v v n=2The earth was without form and void, and darkness was over the face of the deep. And the Spirit of God I would like any pointers on xml with D. - Joelcnz
Re: xml Bible for conversion for D
I think I want to stick with the current std xml library for now. I think the books example is too different for me to work for what I want.
Get current date and time with std.datetime
Hi, I have a program that uses the old time stuff before the module std.datetime. I have a DateTime object, but I can't seem to set its properties to the current time. Some thing like: DateTime dateTime; dateTime = getCurrentDateTime(); -JoelCNZ
Re: Get current date and time with std.datetime
http://d-programming-language.org/intro-to-datetime.html Thanks Jonathan, that helped I think, (haven't read it all, though). But I've got errors with some of the date times not being able to change them with int's values. task.d(44): Error: function std.datetime.DateTime.month () const is not callable using argument types (int) task.d(44): Error: cannot implicitly convert expression (month0) of type int to Month -JoelCNZ
Re: copy and paste in program
I mean, I can't copy text from my program to the clipboard. - Joelcnz On 12-Sep-11 3:50 PM, Joel Christensen wrote: Thanks Jimmy. Your example worked. Or though I haven't managed to get the other way to work. [code] import std.stdio; //import core.stdc.string; import std.c.string; import std.string; import std.conv; extern(Windows) { bool OpenClipboard(void*); void* GetClipboardData(uint); void* SetClipboardData(uint, void*); } void main() { if (OpenClipboard(null)) { auto cstr = cast(char*)GetClipboardData( 1 ); if (cstr) writeln(to!string(cast(char*)cstr[0..strlen(cstr)])); SetClipboardData( 1, cast(char*)toStringz( data set ) ); } } [/code]
Re: copy and paste in program
Thanks so much Jimmy. You put in a bit of effort. :-) I just added this code to my general library: extern(Windows) { bool OpenClipboard(void*); void* GetClipboardData(uint); void* SetClipboardData(uint, void*); bool EmptyClipboard(); bool CloseClipboard(); void* GlobalAlloc(uint, size_t); void* GlobalLock(void*); bool GlobalUnlock(void*); } string getTextClipBoard() { if (OpenClipboard(null)) { scope( exit ) CloseClipboard(); auto cstr = cast(char*)GetClipboardData( 1 ); if(cstr) return cstr[0..strlen(cstr)].idup; } return null; } string setTextClipboard( string mystr ) { if (OpenClipboard(null)) { scope( exit ) CloseClipboard(); EmptyClipboard(); void* handle = GlobalAlloc(2, mystr.length + 1); void* ptr = GlobalLock(handle); memcpy(ptr, toStringz(mystr), mystr.length + 1); GlobalUnlock(handle); SetClipboardData( 1, handle); } return mystr; }
copy and paste in program
Hi, I've got a text program I'm working on. It has game like print. But I want to be able to copy to the clip board and paste from it in my program etc. I'm using Windows 7. I have used a bit of Ubuntu in the past. - Joelcnz
Re: copy and paste in program
Thanks for the reply Jimmy. I was thinking more like SDL (has SDL_GetClipboardText, SDL_SetClipboardText, http://wiki.libsdl.org/moin.cgi/CategoryClipboard). I'm not sure I would be able to get Windows CE Clipboard stuff working for me. - Joelcnz On 12-Sep-11 1:23 PM, Jimmy Cao wrote: Well, it doesn't matter what you've used in the past :-) Take a look: http://msdn.microsoft.com/en-us/library/ms907128.aspx On Sun, Sep 11, 2011 at 5:29 PM, Joel Christensen joel...@gmail.com mailto:joel...@gmail.com wrote: Hi, I've got a text program I'm working on. It has game like print. But I want to be able to copy to the clip board and paste from it in my program etc. I'm using Windows 7. I have used a bit of Ubuntu in the past. - Joelcnz
Re: copy and paste in program
So how would I got about doing it in D? On 12-Sep-11 1:52 PM, Vladimir Panteleev wrote: On Mon, 12 Sep 2011 04:39:52 +0300, Joel Christensen joel...@gmail.com wrote: I'm not sure I would be able to get Windows CE Clipboard stuff working for me. Search engines often return Windows CE results for API searches. Here's the clipboard developer documentation for full Windows versions: http://msdn.microsoft.com/en-us/library/ms648709(v=VS.85).aspx
Re: copy and paste in program
Thanks Jimmy. Your example worked. Or though I haven't managed to get the other way to work. [code] import std.stdio; //import core.stdc.string; import std.c.string; import std.string; import std.conv; extern(Windows) { bool OpenClipboard(void*); void* GetClipboardData(uint); void* SetClipboardData(uint, void*); } void main() { if (OpenClipboard(null)) { auto cstr = cast(char*)GetClipboardData( 1 ); if (cstr) writeln(to!string(cast(char*)cstr[0..strlen(cstr)])); SetClipboardData( 1, cast(char*)toStringz( data set ) ); } } [/code]
toStringz, and memory management, also fromStringz
Hi, In the std.string document at toStringz it has this note: Important Note: When passing a char* to a C function, and the C function keeps it around for any reason, make sure that you keep a reference to it in your D code. Otherwise, it may go away during a garbage collection cycle and cause a nasty bug when the C code tries to use it. What does it mean, and what is an example of how to do it? It's not done like this is it? char* a = cast(char*)toStringz( test ); char* b = cast(char*)toStringz( word ); hold ~= a; hold ~= b; char* cstr2 = al_get_config_value( cfg, a, b ); My programs using a C library do crash when exiting some times. Also, how do I go the other way round, some thing like toDString. I've made my own version. I can't seem to find fromStringz. Thanks for any help. - Joelcnz
Re: toStringz, and memory management, also fromStringz
On 10-Sep-11 3:09 PM, Jonathan M Davis wrote: Jonathan M Davis Ok, now I have a better idea with char pointers. And the std.conv.to worked too. Thanks. - Joelcnz
Re: DMD 2.055
Also I can't compile programs like this any more: \D\dmd2\windows\bin\dmd file1 file2 etc. I've been using Geany (a light IDE), now I have to use the terminal to compile my programs (also clicking on a batch file), before I could compile with the hit of a key. Actually I fix my problem in my previous post. Looks like this: string doToLower( string str ) { return toLower( str ); } - Joelcnz
Re: DMD 2.055
On 08-Sep-11 9:05 PM, Johannes Pfau wrote: cast(string delegate(string)) Thanks Johannes, that's better than my way. :-) - Joelcnz
Multiple subtyping
Hi, Has anyone had much experience with multiple subtyping. //Org: based on page 232 (6.13.1) in The D Programming Language book //#save(); without storeShape does not work import std.stdio; class Shape { void shape() { writeln( Shape ); } } class DataBase { void save() { writeln( I'm the top - save ); } } class StoreShape : Shape { private class MyDataBase : DataBase { override void save() { super.save(); writeln( Data base: save ); } } private MyDataBase _store; alias _store this; this() { _store = this.new MyDataBase; } } void main() { auto storeShape = new StoreShape; with( storeShape ) { shape(); storeShape.save(); //#save(); without storeShape. does not work } } - Joel
Re: Reading by character and by line from stdin
On 26-Aug-11 10:20 AM, Timon Gehr wrote: On 08/26/2011 12:19 AM, Timon Gehr wrote: On 08/25/2011 11:34 PM, bellinom wrote: whoops, this is better: auto arr=to!(int[])(split(strip!(readln(; Or, auto arr2=to!(int[])( readln.strip.split ); Got rid of the second ! too (does not work with it). I not sure about having no () for 3 of the functions though. - Joel
Re: delegate object instead of a literal
On 15-Aug-11 5:21 PM, Joel Christensen wrote: On 15-Aug-11 2:55 PM, Jonathan M Davis wrote: On Sunday, August 14, 2011 20:50:03 Joel Christensen wrote: Hi, This program loops through a string until it finds a number and gives the position of it. The first assert works, but not the second one. import std.algorithm; void main() { static bool isNumber( char input, char dummy ) { if ( ( input= '0' input= '9' ) || input == '.' ) return true; else return false; } string str = abc123; assert( countUntil!( ( input, b ) { if ( ( input= '0' input= '9' ) || input == '.' ) return true; else return false; } )(str, 0) == 3 ); // works assert( countUntil!( isNumber, string, string )( str, 0 ) == 3 ); } This is the error: parse.d(15): Error: template instance countUntil!(isNumber,string,string) does not match template declaration countUntil(alias pred = a == b,R1,R2) if (is(typeof(startsWith!(pred)(haystack,needle By the way, it looks like std.algorithm.count will do what you want to do (though you'll have to negate the predicate for it to work - either with std.functional.not or by changing it appropriately). - Jonathan M Davis Ok, cool. I think this is nice: immutable isNum = `a = '0' a = '9' a != ''`; auto input = abc123; auto indexEnd = count!( not!isNum )( input ); assert( indexEnd == 3 ); - Joel Oops, should be. -- immutable isNum = `( a = '0' a = '9' ) || a == '.'`; But that's the idea any way. Also forgot to have the variable 'input' declared in a post. - Joel
Re: delegate object instead of a literal
Ok, this is a good one I think. import std.string, std.algorithm, std.functional; bool isANum( dchar chr ) { return inPattern( chr, digits ~ `+-.` ); } void main() { auto input = `abc123`; auto indexEnd = -1; indexEnd = count!( not!isANum )( input ); assert( indexEnd == 3 ); }
Re: delegate object instead of a literal
On 16-Aug-11 10:22 AM, Jonathan M Davis wrote: On Monday, August 15, 2011 14:28 Jonathan M Davis wrote: On Monday, August 15, 2011 02:25 Joel Christensen wrote: Ok, this is a good one I think. import std.string, std.algorithm, std.functional; bool isANum( dchar chr ) { return inPattern( chr, digits ~ `+-.` ); } void main() { auto input = `abc123`; auto indexEnd = -1; indexEnd = count!( not!isANum )( input ); assert( indexEnd == 3 ); } Actually, it looks like count counts it for the whole range, not just how many before it finds one which doesn't match. So, it's not quite what you were looking for. I misread what it did. The next release will have a version of countUntil that does what you want though. - Jonathan M Davis Ok, good. Thanks Jonathan. - Joel
delegate object instead of a literal
Hi, This program loops through a string until it finds a number and gives the position of it. The first assert works, but not the second one. import std.algorithm; void main() { static bool isNumber( char input, char dummy ) { if ( ( input = '0' input = '9' ) || input == '.' ) return true; else return false; } string str = abc123; assert( countUntil!( ( input, b ) { if ( ( input = '0' input = '9' ) || input == '.' ) return true; else return false; } )(str, 0) == 3 ); // works assert( countUntil!( isNumber, string, string )( str, 0 ) == 3 ); } This is the error: parse.d(15): Error: template instance countUntil!(isNumber,string,string) does not match template declaration countUntil(alias pred = a == b,R1,R2) if (is(typeof(startsWith!(pred)(haystack,needle - Joel
Re: delegate object instead of a literal
On 14-Aug-11 10:44 PM, Jonathan M Davis wrote: On Sunday, August 14, 2011 03:23:39 Jonathan M Davis wrote: On Sunday, August 14, 2011 20:50:03 Joel Christensen wrote: Hi, This program loops through a string until it finds a number and gives the position of it. The first assert works, but not the second one. import std.algorithm; void main() { static bool isNumber( char input, char dummy ) { if ( ( input= '0' input= '9' ) || input == '.' ) return true; else return false; } string str = abc123; assert( countUntil!( ( input, b ) { if ( ( input= '0' input= '9' ) || input == '.' ) return true; else return false; } )(str, 0) == 3 ); // works assert( countUntil!( isNumber, string, string )( str, 0 ) == 3 ); } This is the error: parse.d(15): Error: template instance countUntil!(isNumber,string,string) does not match template declaration countUntil(alias pred = a == b,R1,R2) if (is(typeof(startsWith!(pred)(haystack,needle Okay. Several things here. One, don't ever declare an individual char. char is a UTF-8 code unit, not a code point. And characters are code points. ASCII characters only require one UTF-8 code unit, so they can be held in a single char, but that's not true of characters in general. When dealing with individual characters, always use dchar. So, if you're using foreach for a string, use dchar as the iteration type. e.g. foreach(dchar c; str) {...} Youre code will be wrong if it iterates over char or wchar, since those aren't full characters. And because of that, _all_ strings are ranges of dchar, not char or wchar. So, the fact that you're using string instead of dstring with a range-based function like countUntil is irrelevant. You're still dealing with a range of dchars. So, isNumber should definitely be taking dchars, not chars. Two, don't pass 0 as a string. 0 is an int. _None_ of those countUntil calls shouldn't be compiling at all. It's actually a bit disturbing thath the first one compiles. It definitely looks like a bug. countUntil takes two ranges with the same element type. 0 is not a range, let alone a range of dchars. 0 shouldn't even really be used as a dchar, since 0 is an int, not a character. Third, you really shouldn't be using if statements like that. It looks like you don't know what you're doing if you do if(condition) return true; else return false; The condition is already a bool. You can simply do return condition; Plenty of newbie programmers make that mistake, and I don't know how experienced a programmer you are, but I'd advise you not to do that anymore. In any case, I'm a bit shocked that the first call to countUntil compiles, let alone works. That's quite disturbing actually. It looks like countUntil has a bug. However, your usage of countUntil here does imply that it could use an overload which takes a unary function and only one range. Okay. countUntil is _supposed_ to be able to take a single value as its second argument. However, the names for the templated types implied that it took a range for its second value (it could take either a range or just an element, just so long as startsWith(haystack, needle) compiles). So, that may need some clarifying in the documentation. I misread it. In any case, if you change isNumber to two dchars, your code will work. The problem you're having is because a string is a range of dchars, not chars. But still, you probably shouldn't be passing 0. Apparently, the compiler is doing an implicit conversion from int to dchar to allow it to work, but it's generally better to not do that. - Jonathan M Davis Hi, Thanks Jonathan for your help. I've taken the things you've said on board. I think I'm getting some where with D. I also mean to work more at C# too. So this works: import std.algorithm; bool isNumber( dchar chr, dchar dummy ) { return ( ( chr = '0' chr = '9' ) || chr == '.' || chr == '-' || chr == '+' || chr == '' ); } void fun() { dchar dummy = '\0'; auto indexEnd = countUntil!( isNumber )( input, dummy ); } - Joel
Re: delegate object instead of a literal
On 15-Aug-11 2:55 PM, Jonathan M Davis wrote: On Sunday, August 14, 2011 20:50:03 Joel Christensen wrote: Hi, This program loops through a string until it finds a number and gives the position of it. The first assert works, but not the second one. import std.algorithm; void main() { static bool isNumber( char input, char dummy ) { if ( ( input= '0' input= '9' ) || input == '.' ) return true; else return false; } string str = abc123; assert( countUntil!( ( input, b ) { if ( ( input= '0' input= '9' ) || input == '.' ) return true; else return false; } )(str, 0) == 3 ); // works assert( countUntil!( isNumber, string, string )( str, 0 ) == 3 ); } This is the error: parse.d(15): Error: template instance countUntil!(isNumber,string,string) does not match template declaration countUntil(alias pred = a == b,R1,R2) if (is(typeof(startsWith!(pred)(haystack,needle By the way, it looks like std.algorithm.count will do what you want to do (though you'll have to negate the predicate for it to work - either with std.functional.not or by changing it appropriately). - Jonathan M Davis Ok, cool. I think this is nice: immutable isNum = `a = '0' a = '9' a != ''`; auto input = abc123; auto indexEnd = count!( not!isNum )( input ); assert( indexEnd == 3 ); - Joel
Re: ref int value() { return m_value; } - uses?
http://www.d-programming-language.org/property.html @property makes it so that the function is used syntactically as a variable rather than a function. And while it's not currently enforced, eventually, you will _have_ to use property functions with the variable syntax. For instance, empty on ranges is marked with @property: assert(range.empty); You could currently do assert(empty(range)); but eventually that will be illegal. Property functions allow you to have public member variables become functions (or functions become public member variables) without having to change the code which uses them. They're generally used instead of getters and setters. In this particular case, the property function returns a ref, so it's both a getter and a setter. - Jonathan M Davis Thanks for the reply Davis. With the getter/setter method you don't have much control, like knowing what value it being set to at the method definition (could with 'ref auto xpos( int value ) { ... return m_xpos; }' :-/). And having two methods, one for getter and one for setter, you can't do stuff like 'xpos++;' - Joel Christensen
ref int value() { return m_value; } - uses?
What use is the property thing? class Test { private int m_value; @property ref int value() { return m_value; } } void main() { auto test = new Test; test.value += 1; } Or this: import std.stdio: writeln; import std.conv: to; class Test { private string m_text; ref auto text( string tx ) { if ( tx.length 4 ) m_text = m_text[ 0 .. 4 ]; return m_text; } override string toString() { return text( m_text ); } } void main() { auto test = new Test; with( test ) { text( to!string( test ) ) = feet; writeln( test ); text( to!string( test ) ) ~= @; writeln( test ); } }
Re: r/w binary
Ok, I get you. A whole int*, not one byte of the int* data. - Joel On 01-Jul-11 6:07 AM, Ali Çehreli wrote: On Fri, 01 Jul 2011 05:28:56 +1200, Joel Christensen wrote: Shouldn't file.rawWrite((i)[0..1]); have [0..4]? Or am I missing some thing? [0..1] follows the regular slicing syntax there: those are element indexes. Sincei is an int*, [0..1] slices the first int. It would be different if it were ubyte* or void*. Ali
Re: r/w binary
Yes, portability, I hadn't thought of that. Shouldn't file.rawWrite((i)[0..1]); have [0..4]? Or am I missing some thing? - Joel On 30-Jun-11 7:53 PM, Ali Çehreli wrote: On Thu, 30 Jun 2011 15:52:59 +1200, Joel Christensen wrote: I'm thinking more about handling binary files. With the C version I would write a int for how many letters in the string, then put in the the string along side ([0005][house]). That way I can have any character at all (though I just thinking of char's). I would still use a portable text format myself. For binary, you should consider rawWrite() and rawRead(). Here is just a start: import std.stdio; void main() { int i = 42; auto file = File(deleteme.bin, w); file.rawWrite((i)[0..1]); } (Aside: The 'b' for binary mode does nothing in POSIX systems; so it's not necessary.) The parameter to rawWrite() above is a nice feature of D: slicing a raw pointer produces a safe slice: http://digitalmars.com/d/2.0/arrays.html quote Slicing is not only handy for referring to parts of other arrays, but for converting pointers into bounds-checked arrays: int* p; int[] b = p[0..8]; /quote For strings (actually arrays), you would need .length and .ptr properties. I've never used it but you might want to consider the serialization library Orange as well: http://www.dsource.org/projects/orange Ali
Re: r/w binary
Thanks for your reply Ali. Your right about changing create to open when reading. And, yes, I was thinking of trying std.stdio myself. - Joel On 29-Jun-11 6:48 PM, Ali Çehreli wrote: I've settled on std.stdio as opposed to std.stream and std.cstream. On Wed, 29 Jun 2011 10:07:13 +1200, Joel Christensen wrote: I want to save and load levels for my game. The std.stream module doesn't have much examples. Here is my code: void saveLevel( string fileName ) { auto bfile = new std.stream.File; int ver = 1; string verStr = version:; with( bfile ) { scope( exit ) close; create( fileName ); write( verStr ); write( ver ); // version } int ver2; char[] verStr2; auto bfile2 = new std.stream.File; with( bfile2 ) { scope( exit ) close; create( fileName ); That is copy-paste mistake, right? You don't want create() before reading. You must have meant open: open( fileName ); It works with that change. read( verStr2 ); read( ver2 ); // version } writeln( verStr, ver ); } And this is the result: std.stream.ReadException@std\stream.d(46): Stream is not readable - Joel Ali
Re: r/w binary
With the char[], I can't use spaces in it the way I've got it here, (like if I tried using a phrase): void saveLevel( string fileName ) { int ver = 1; auto house = two.dup; double rnum = 3.0; { auto fout = File( fileName, wb); // open for binary writing scope( exit ) fout.close; fout.writef( %d %s %f, ver, house, rnum ); } ver = 593; house = asdfghf.dup; rnum = 57.23; { auto fin = File( fileName, rb); // open for binary reading scope( exit ) fin.close; fin.readf( %d %s %f, ver, house, rnum ); } writeln( \nint: , ver, string: ', house, ' rnum: , rnum ); } - Joel
Re: r/w binary
I'm thinking more about handling binary files. With the C version I would write a int for how many letters in the string, then put in the the string along side ([0005][house]). That way I can have any character at all (though I just thinking of char's). Actually, I've just looked the output file and it's a text file. So in that case I would use read line to have spaces in strings, though what if I wanted to have new line character(s) in the one string. I still want to work with binary files. On 30-Jun-11 2:23 AM, Ali Çehreli wrote: On Wed, 29 Jun 2011 19:55:38 +1200, Joel Christensen wrote: With the char[], I can't use spaces in it the way I've got it here, (like if I tried using a phrase): There has been a thread very recently about reading strings. Look for the thread readf with strings (dated 22-Jun-2011 in my reader). Or, if it works here: http://www.digitalmars.com/webnews/newsgroups.php? art_group=digitalmars.D.learnarticle_id=27762 Reading the entire line: string s = chomp(readln()); Kai Meyer suggested parsing the string directly: string[] buffer; int a; float b; string c; buffer = chomp(readln()).split( ); a = to!(int)(buffer[0]); b = to!(float)(buffer[1]); c = buffer[2..$].join( ); writef(Read in: '%d' '%f' '%s'\n, a, b, c); void saveLevel( string fileName ) { int ver = 1; auto house = two.dup; double rnum = 3.0; { auto fout = File( fileName, wb); // open for binary writing scope( exit ) fout.close; You are not supposed to need to close the File object yourself. Being a struct, its destructor should be called automatically. Ali
r/w binary
I want to save and load levels for my game. The std.stream module doesn't have much examples. Here is my code: void saveLevel( string fileName ) { auto bfile = new std.stream.File; int ver = 1; string verStr = version:; with( bfile ) { scope( exit ) close; create( fileName ); write( verStr ); write( ver ); // version } int ver2; char[] verStr2; auto bfile2 = new std.stream.File; with( bfile2 ) { scope( exit ) close; create( fileName ); read( verStr2 ); read( ver2 ); // version } writeln( verStr, ver ); } And this is the result: std.stream.ReadException@std\stream.d(46): Stream is not readable - Joel
Re: sort!(a b)( arr ); - opCmp
Yeah, it works now. Thanks David :-) I have actually used type o = cast(type)variable; But had forgotten about it. Though the super part of what you said is more subtle.
Physics engine, eg Blaze
I've got a GUI (GtkD) and a game library (DAllegro5) going. But I'm thinking a physics library would be wanted. I had a go at making Blaze work with D2.0. I got it to compile and had things fall down the screen with it, but the original it hasn't been updated for 2 years, I think. Blaze is based off Box2D. C# can use Box2D. -- Joel Ezra Christensen
Re: Next Release
Ok, I was just making sure. I guess you would surely know about that. I actually made a program that used date and time before your library. Not nice. I guess I should go and revisit it. I use the program of mine too, it boots with Windows.
Re: Next Release
Well, then I'd better make sure that I get my most recent updates to std.datetime in soon. - Jonathan M Davis Does your library take into account that there's no year 0?
Re: I seem to be able to crash writefln
On 15/03/2011 1:57 a.m., Steven Schveighoffer wrote: On Fri, 11 Mar 2011 18:57:32 -0500, Spacen Jasset spacenjas...@yahoo.co.uk wrote: On 10/03/2011 12:18, Steven Schveighoffer wrote: On Wed, 09 Mar 2011 18:19:55 -0500, Joel Christensen joel...@gmail.com wrote: This is on Windows 7. Using a def file to stop the terminal window coming up. win.def EXETYPE NT SUBSYSTEM WINDOWS bug.d import std.stdio; import std.string; void main() { auto f = File( z.txt, w ); scope( exit ) f.close; string foo = bar; foreach( n; 0 .. 10 ) { writefln( %s, foo ); f.write( format( count duck-u-lar: %s\n, n ) ); } } output (from in z.txt): count duck-u-lar: 0 If I dust off my rusty old Windows hat, I believe if you try to write to stdout while there is no console window, you will encounter an error. So don't do that ;) I'm not sure what you were expecting... -Steve You normally get no output AFAIR using c++ type compiled programs with printf or cout -- and perhaps an error set in cout, but I can't remember about that now. But don't forget, D uses DMC's runtime, not Visual Studio. Make sure you are comparing to DMC compiled programs. -Steve writeln works, just not writefln so much. Haven't tried eg. writeln( format( %s, value ) ); Can have a version system for with, and with out the terminal. Just don't think I need to do more than just adding and removing the .def file from the compiler arguments. -Joel
I seem to be able to crash writefln
This is on Windows 7. Using a def file to stop the terminal window coming up. win.def EXETYPE NT SUBSYSTEM WINDOWS bug.d import std.stdio; import std.string; void main() { auto f = File( z.txt, w ); scope( exit ) f.close; string foo = bar; foreach( n; 0 .. 10 ) { writefln( %s, foo ); f.write( format( count duck-u-lar: %s\n, n ) ); } } output (from in z.txt): count duck-u-lar: 0
Re: I seem to be able to crash writefln
On 10-Mar-11 1:04 PM, spir wrote: On 03/10/2011 12:19 AM, Joel Christensen wrote: This is on Windows 7. Using a def file to stop the terminal window coming up. win.def EXETYPE NT SUBSYSTEM WINDOWS bug.d import std.stdio; import std.string; void main() { auto f = File( z.txt, w ); scope( exit ) f.close; string foo = bar; foreach( n; 0 .. 10 ) { writefln( %s, foo ); f.write( format( count duck-u-lar: %s\n, n ) ); } } output (from in z.txt): count duck-u-lar: 0 What do you mean, crashing writefln? What do you get on the terminal? About the file, there seems to be a bug --but unrelated to writefln. The file is closed, I guess because of scope(exit), before the output stream is flushed. If this is the right interpretation, then there is a precedence issue; scope's action should not be performed before the func's own action is actually completed. Denis It quits out the at about the 2nd attempt at printing text (that doesn't go to the terminal because of the def file argument in the compile arguments). I didn't see any problem with the File stuff, I can use writeln and it does all ten iterations, (not printing any thing of course). I used write instead of writeln, write doesn't flush like writeln, maybe. I noticed my program that had been running fine before, but suddenly bailed out almost strait away since I used the def file in the compile arguments. Joel
Re: Icons
Thanks, Chapman :-), I followed your instructions and they worked.
Re: Icons
I got it working with the DAllegro (Allegro 4.2) game library as well!
Icons
I noticed in windows with D you can use .res (eg. dmd main.d smile.res) files for icons any way. but how do you make icon .res files?
Re: Icons
On 27-Feb-11 12:56 AM, J Chapman wrote: == Quote from Joel Christensen (joel...@gmail.com)'s article I noticed in windows with D you can use .res (eg. dmd main.d smile.res) files for icons any way. but how do you make icon .res files? With a resource compiler. Digital Mars supplies one as part of its C++ utilities package: http://ftp.digitalmars.com/bup.zip. Documentation is here: http://www.digitalmars.com/ctg/rcc.html Thanks Chapman. :-)
Re: Icons
On 27-Feb-11 11:24 AM, Joel Christensen wrote: On 27-Feb-11 12:56 AM, J Chapman wrote: == Quote from Joel Christensen (joel...@gmail.com)'s article I noticed in windows with D you can use .res (eg. dmd main.d smile.res) files for icons any way. but how do you make icon .res files? With a resource compiler. Digital Mars supplies one as part of its C++ utilities package: http://ftp.digitalmars.com/bup.zip. Documentation is here: http://www.digitalmars.com/ctg/rcc.html Hmm. Can't seem to get it to work.
Re: Error when exiting program
On 19-Feb-11 6:53 PM, Jesse Phillips wrote: Joel Christensen Wrote: I'm using some one else's bindings to a C library. The problem seems to be limited to D2 programs. Error as follows: An exception was thrown while finalizing an instance of class jec2.bmp.Bmp I also get other errors at program exit. Thanks for any help. :-) I think you are going to have to give us more detail. What library, what error? I don't think any one wants to see my code (a mess). I've started a new library thingy, and so far no problem.
Error when exiting program
I'm using some one else's bindings to a C library. The problem seems to be limited to D2 programs. Error as follows: An exception was thrown while finalizing an instance of class jec2.bmp.Bmp I also get other errors at program exit. Thanks for any help. :-)
Exiting program problems, DAllegro
I'm using a wrapper (or what ever it's called ) that I made on top of DAllegro binding of the C library Allegro). But I get this error when exiting a DAllegro program with my JEC2 library. It's a long standing problem I've had. I think it's my JEC2 library that makes it fail. An exception was thrown while finalizing an instance of class jec2.bmp.Bmp Thanks for any help. :-)
Re: ASM access to array
What about my edited version: import std.stdio; uint rotl_d(uint value,ubyte rotation){ return (valuerotation) | (value(value.sizeof*8 - rotation)); } uint rotl_asm(uint value,ubyte rotation){ asm{ mov EAX, value; // get first argument mov CL , rotation; // how many bits to move rol EAX, CL; }// return with result in EAX } void bin_writeln(string info,uint value, bool nl){ writefln(%1s: %02$32b%3$s,info,value,nl?\n:); } int main(string[] argv){ uint a=0xc0def00d; bin_writeln(value a,a ,false); bin_writeln(value b,rotl_d(a,1),true); // bin_writeln(value a,a ,false); bin_writeln(value b,rotl_asm(a,1),true); uint b; ubyte c = 0; while ( 1 == 1 ) { // Press Ctrl + C to quit b = rotl_asm(0xc0def00d, c); foreach (rst; 0 .. 5_000 ) writef(%032b %2d\r,b, c ); c = cast(ubyte)( c + 1 == 32 ? 0 : c + 1 ); } return 0; }
Re: [D1] assert failure expression.c
Looks like there's no problem to me, except with the code. char[] foo() { char[2] res = 1 ; res[1] = ;; // should be res[1] = ';'; return res; } I don't think you can have an incomplete mixin.
Re: linked list
Thanks for the long winded reply Jonathan. I don't know how to avoid using my own linked list, I have next/prev in each class (Ball, Lazer and Mine ) in the list. Thanks bearophile, I had a bit of a look at that site. My game is simple so just maybe the easiest way is the way to go, though if I use the most tightest way and so my game would be an prototype for bigger games to reference.
Re: intrusive linked list
That's called intrusive linked list, and I find using it quite viable: zero-allocation O(1) add/removal is a very strong characteristics. They are very useful especially for lock-free algorithms. That's for the info Denis. I got the idea from a friend who is interested in how to make games.
Re: std.c.stdio, std.stream std.c.file, ranges
Thanks for your reply Jonathan. Yes, I heard about stream being replaced, but since my code with binary files isn't very much, I can just redo it if I have to. I think I'll continue using std.c.file for the time being. I should learn about ranges. I tried std.stdio already. It's been been good getting replies here. :-)
Re: linked list, ranges
Thanks again for the reply Jonathan. I'm using doublely linked list I made for a game where ships and there lazer bolts are in the same list. Without linked list I couldn't do things like create a lazer bolt or remove one while trans-versing the linked list. I had to use my own linked list, having a next and prev node in each object that goes in the list.
Re: linked list
I am looking for use cases of singly|doubly linked lists, I (nearly) never need them in my code. Few questions: 1) What's a typical (or average) length of your list? Thanks for your interest bearophile. I haven't used linked list much more than just trying them out. And my game is at its earlier stages. Not very much, 2 players, mines ad lazer bolts are added and removed when used. I guess around 10. 2) Are items sorted (like from the bigger to the smaller one)? I've got the player objects fixed at the head of the array. 3) Is the item order important (so is it OK to shuffle them in some other ways)? I'm thinking of having then sorted as objects are added. I'm also thinking of having a pointer to the start and end of each kind of object (like sub lists). 4a) How often/many do you need to add items to the list? My game is only small at the moment, so not a good sample. I guess every time a player fires a lazer bolt or lays a mine, but those objects don't last long. 4b) How often/many do you need to remove items to the list? About as often as I add them, eg. the mines and lazers are added and taken away often. How many, two at a about the same time with two players.
Re: linked list
I normally use D's built in dynamic arrays. but it doesn't work with adding and removing with the foreach loop (like removing an object from the list while still going through the list).
date and time
I'm using D2.049. I have a program in which I want to be able to get the current time as one number, also be able to change the hour and stuff then convert it back to one number. I'm saving just the one number to file. Thanks in advance. :-)
Re: date and time
I've tried that module. I was putting: long dt = UTCtoLocalTime(getUTCtime - (msPerDay / 2)); Then when daylight savings came it was wrong, (computer was right mind). long datetime = UTCtoLocalTime(getUTCtime); It is 1 hour and half a day out. It was the right hour till daylight savings. I live in New Zealand. Some one said that module was a mine field. std.datetime is your friend. http://www.digitalmars.com/d/2.0/phobos/std_date.html
Re: date and time, core access
Thanks for the replies Jonathan M Davis and Yao G. :-) Good to hear it's being worked on. I've other programs that are done with D1.0 that are all right. I'm using Windows, would like it to work on Linux too though. I think I'll use year month etc. separately instead of just having a big number (for converting to the time measurements). How do you access the core library? I wanted to look at the core time module and couldn't, (C/C++ sites of course have that information any way).
Re: date and time, std.c.stdio
Thanks Jonathan. My plan is to use the C version, and not use the big time_t number. I'm actually using std.c.stdio module too, for binary files, I probably should use std.stream or some thing.
Re: Dynamic method example in TDPL
Thanks for the fix up Philippe. Just a little note. Where it says 'DynMethod m', you can put 'auto m', but I'm wondering is it some times clearer to have the class name even though 'auto' works.
Reading stdin in Windows 7
Stanislav Blinov blinov loniir.ru writes: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hello, I'm receiving strange results with reading stdin on Windows 7. Consider this code: module test; import std.stdio; void main(string[] args) { foreach (int i, string line; lines(stdin)) { write(line); } } On Linux, if I do 'cat test.d | ./test' I get test.d contents on stdout. But on Windows 7, ('type test.d | ./test.exe') the output is this: std.stdio.StdioException: Bad file descriptor module test; import std.stdio; void main(string[] args) { foreach (int i, string line; lines(stdin)) { writef(line); } } So I too get type.d contents on stdout, but preceeded by StdioException string. This happens with dmd 2.047 and 2.048. Is this my error, dmd's, or Windows's piping? -- Aug 17 Jesse Phillips jessekphillips+D gmail.com In my experience Windows hasn't gotten piping right. And it has been known to have bugs, this might be related: http://stackoverflow.com/questions/466801/python-piping-on-windows-why-does-this-not-work Aug 18 Joel Christensen joelcnz gmail.com: Just dug up this problem. I have trouble with Thunderbird and so couldn't put reply. I've tried that solution on my Windows 7, but got no effect at all. Sept 1
Dynamic method example in TDPL
I've typed this example program in, but it doesn't compile. I looked up the The D programming language errata but it wasn't listed. I'm using DMD v2.048. /** Date: Aug 20, 2010 This was copied from TDPL book pages 386 - 387 */ module dynamicmethods; import std.stdio; import std.variant; alias Variant delegate(Dynamic self, Variant[] args...) DynMethod; class Dynamic { private DynMethod[string] methods; void addMethod(string name, DynMethod m) { methods[name] = m; } void removeMethod(string name) { methods.remove(name); } // Dispatch dynamically on method Variant call(string methodName, Variant[] args...) { return methods[methodName](this, args); } // Provide syntactic sugar with opDispatch Variant opDispatch(string m, Args)(Args args...) { Variant[] packedArgs = new Variant[args.length]; foreach (i, arg; args) { packedArgs[i] = Variant(arg); } return call(m, args); } } void main() { auto obj = new Dynamic; obj.addMethod(sayHello, Variant(Dynamic, Variant[]) { //#error here. (found '{' expecting ',' writeln(Hello, world!); return Variant(); }); obj.sayHello(); // Prints Hello, world! }
Programming test - using strings
Any one interested in doing D versions of this program? http://www.rubyquiz.com/quiz14.html
Re: Explicit ordering with std.format
Tomek Sowiński wrote: An extract from java.util.Formatter docs: // Explicit argument indices may be used to re-order output. formatter.format(%4$2s %3$2s %2$2s %1$2s, a, b, c, d) // - d c b a How do I achieve this with std.format? The ddocs only say that variadic arguments are consumed in order. Any way to change that order? Tomek With the D Tango library you can put: Stdout.format({3} {2} {1} {0}, a, b, c, d);
Re: anonymous function/deleget usage
Sam Hu wrote: How can I reach something like below code: int a=1; int b=2; int c=(int a,int b){ return a+b;} writefln(Result:%d,c); Thanks in advance. int a=1; int b=2; int add(int a,int b) { return a+b; } int c=add(a,b); writefln(Result:%d,c); Nested functions are cool. :-)
Re: FMOD working with Windows
Now I get the error using coffimplib.exe 'Error: missing archive signature'.
Re: FMOD working with Windows
grauzone wrote: Joel Christensen wrote: FMOD sound (record and play) is off D Programming web site. http://wiki.dprogramming.com/FMod/HomePage I followed instructions from the web site. But one instruction said to use 'coffimplib.exe' but I couldn't see where it is to download it, and one link wasn't found (Dr.Dobb). You can avoid the whole crap with linking to a .lib and use derelict. Derelict simply dynamically loads the DLL. I've already tried derelict. I don't know how to use it to either record or even play audio files. I have in the past gotten FMOD working (record and play I think, record at lessed) with C++. Using the tools 'copy' and 'paste'. Also there's a library I use that has recording ability, but I don't how to use it either.
Re: Descent eclipse plugin - auto code completion
Do you have something in the Error Log (Window - Show View - Error Log)? How is your project configured? Do you have phobos or Tango in the include path? My Eclipse doesn't have a thing called Error Log. I can't see more than 'D Build Path' to configure. I've been testing with Tangos 'Stdout'. It's been working in my little test programs, but not aways with a proper program, I just get the Object class stuff, not Stdouts stuff. Other things work like structs and 'this.' and other classes work. Even other Tango class's work (if I put the full name). I'm using 'tango\import' in my include path. Another note: I couldn't get an external software to compile from eclipse either.
Re: cast(int) getting an unexpected number
To be safe, whenever converting to int, always add a small epsilon. I think you can use float.epsilon, but I don't have any experience with whether that is always reasonable. -Steve Thanks every one for the replies. I still have problems. How do I use epsilon? 'real' helps in my example program but not in my money program. I think there's a function out there that does dollars and cents (eg. .89 - 89c and 1.00 - $1), but I'm interested how to solve this problem.
Re: FMOD working with Windows
Moritz Warning wrote: On Wed, 28 Oct 2009 14:37:22 +1300, Joel Christensen wrote: FMOD sound (record and play) is off D Programming web site. http://wiki.dprogramming.com/FMod/HomePage I followed instructions from the web site. But one instruction said to use 'coffimplib.exe' but I couldn't see where it is to download it, and one link wasn't found (Dr.Dobb). ftp://ftp.digitalmars.com/coffimplib.zip I wonder where it is linked from the digitalmars.com website Thanks Moritz. :-)
FMOD working with Windows
FMOD sound (record and play) is off D Programming web site. http://wiki.dprogramming.com/FMod/HomePage I followed instructions from the web site. But one instruction said to use 'coffimplib.exe' but I couldn't see where it is to download it, and one link wasn't found (Dr.Dobb).
Re: Trying to get DMD bundled with libs
Jarrett Billingsley wrote: On Mon, Sep 7, 2009 at 6:44 AM, Joel Christensenjoel...@gmail.com wrote: div0 wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Joel Christensen wrote: I noticed you can get DMD bundled with various libraries. I found you had to login to another web site, but the registery page has 3 must fill in textbox's that are crazy. Where's that? AFAIK nobody has permission to distribute DMD other than Walter. http://www.digitalmars.com/d/download.html It's a Windows one, it's for dmd 1.030. Oh, that's EasyD I think. By crazy textboxes do you mean the login screen? I don't remember having to log in before. Chris hasn't posted on the NGs in a while either. In any case, 1.030 is *rather* old, and the libraries that would come with would be just as old. I mean by crasy text boxes three of the ones in the registery page, (for getting a log in), and I couldn't register because of them. If it's old and stuff, then why is it in the digital mars web site?
Trying to get DMD bundled with libs
I noticed you can get DMD bundled with various libraries. I found you had to login to another web site, but the registery page has 3 must fill in textbox's that are crazy.
Re: Should be easy
For 2 dim array I like auto a=new char[][](40,25); so that a[39][24]='B'; 'B' is at the bottom right of the 2D array.
Errors since dmd 1.045
Joel Christensen wrote: See previous post.
Error 1: Previous Definition Different, Error 42: Symbol Undefined
I get this error with dmd 1.045. The _errno seems to be with the DAllegro (http://www.dsource.org/projects/dallegro) library. And the 42 one to do with some thing of mine. OPTLINK (R) for Win32 Release 8.00.1 Copyright (C) Digital Mars 1989-2004 All rights reserved. C:\jpro\dmd45\windows\bin\..\lib\SNN.lib(cinit) Offset 08C2CH Record Type 0090 Error 1: Previous Definition Different : _errno main.obj(main) Error 42: Symbol Undefined _D22TypeInfo_C3jec3snd3Snd6__initZ