Re: equivalent of typeid(Class).name at compile-time
On 11/22/19 4:04 AM, Jacob Carlborg wrote: On Thursday, 21 November 2019 at 20:44:19 UTC, Steven Schveighoffer wrote: I thought I could do typeid(Class).name to get the class name that will be returned at runtime if you did typeid(instance).name. But it's not accessible at compile-time. What compile-time string should I use for instance in a constructed switch statement? I'm trying to implement serialization and deserialization of classes, but I really would like to avoid using a class enum if possible, since the type id is already there and generated by the compiler. I solved that by storing the class info as the key in an associative array [1]. But it looks like Adam's solution will work as well. If you ideas, you can always have a look at Orange. [1] https://github.com/jacob-carlborg/orange/blob/90f1dbb0097ba4a319805bfb7d109f7038418ac6/orange/serialization/Serializer.d#L241-L262 Thanks for all the replies, guys. Annoying that the compiler has generated these names but doesn't make them accessible at compile-time. -Steve
Re: How to simulate Window's "Press any key to continue..."
On Friday, 22 November 2019 at 04:10:23 UTC, FireController#1847 wrote: I'm an extreme beginner to DLang (just started using it.. oh, an hour ago?), and I already can't figure out a, what I'd consider, fairly simplistic thing. This is my current code: module DTestApp1; import std.stdio; int main() { write("Press any key to continue..."); stdin.read(); return 0; } I am using Visual Studio to write it, and no matter what I do I cannot get it to work. I attempted to import std.stream;, but it said that while it could find the file, it cannot be read. Am I using the wrong function? For those who don't know, what I'm trying to do is pause the program until literally any key is pressed while in the console. execute(["pause"]);
Re: equivalent of typeid(Class).name at compile-time
On Thursday, 21 November 2019 at 20:48:03 UTC, Adam D. Ruppe wrote: On Thursday, 21 November 2019 at 20:45:16 UTC, Steven Schveighoffer wrote: To clarify, I need the compile time string that will match typeid(instance).name, so I can match the derived type. You have to make sure that the derived type is passed to your register function, but then std.traits.fullyQualifiedName!T ought to give it to you. Please note that fullyQualifiedName can return slightly different string than ClassInfo.name for templated types (typeinfo returns names that are fully expanded for eponymous templates while FQN function does not) and hence won't recommend mixing both of them toghether. Best regards, Alexandru.
Re: How to simulate Window's "Press any key to continue..."
On Friday, 22 November 2019 at 09:25:37 UTC, Ali Çehreli wrote: https://github.com/adamdruppe/arsd/blob/master/terminal.d I have this exact thing as a sample in my docs: http://dpldocs.info/experimental-docs/arsd.terminal.html#single-key You could wrap that up in a function if you don't want anything else. though personally I'd just do "press enter to continue" since it is so much easier and avoids the dependency. you can use my module by copying the whole file to your source and using it, or it is a dub package arsd-official:terminal too
Re: How to simulate Window's "Press any key to continue..."
On Friday, 22 November 2019 at 04:45:21 UTC, Mike Parker wrote: On Friday, 22 November 2019 at 04:22:07 UTC, FireController#1847 wrote: Right, but readln will only wait until the user presses the delimiter (by default Enter/Return). I want it to wait until ANY key is pressed, not a specific key The documentation for std.stdio.File shows two functions for reading input: readln and readf. If readln isn't what you want, then readf probably is: https://dlang.org/phobos/std_stdio.html#.File.readf Also, there's a freely available book online to help get you up to speed: Programming in D. Here's the section on reading from stdin with readf: http://ddili.org/ders/d.en/input.html stdin is buffered and will not be forwarded to the D-library until you press enter. The solution is different on Linux and Windows. On Linux you need to disable the "CANON" mode in the terminal. https://stackoverflow.com/questions/1449324/how-to-simulate-press-any-key-to-continue There are a few suggestions for Windows in the link as well. Annoyingly complicated for such a simple thing but that's how it is.
Blog Post #90: Reader Requests
Readers Peter Pinkness (over on the GtkD Forum) and GreatSam4Sure (the D Forum) requested coverage of some techniques for centering a GTK Window and decorating a Window with a custom icon. That's what today's post is about: https://gtkdcoding.com/2019/11/22/0090-titlebar-icons.html Also, I made an announcement early in the week in the Announce sub-forum which you may or may not have seen: https://forum.dlang.org/thread/gfrxelrpjjiyfbtzw...@forum.dlang.org
Re: How to simulate Window's "Press any key to continue..."
On 11/21/19 9:10 PM, Mike Parker wrote:> On Friday, 22 November 2019 at 04:45:21 UTC, Mike Parker wrote: > You need to call readf with a character > format string (%c): > > import std.stdio; > void main() > { > writeln("Press any key to continue..."); > > char c; > readf("%c", &c); > writeln("Thanks!"); > } Unfortunately, that won't work either as it requires stdin to be unbuffered, which is not the case in most terminals. The main issue here is that a D program cannot know that stdin is bound to a keyword. One needs to use a terminal module like the suggested curses or Adam's terminal.d: https://github.com/adamdruppe/arsd/blob/master/terminal.d If it's too much unnecessary complication, then "Press Enter to continue..." is perfectly fine to me. ;) (But of course you can't move the cursor with that. :/) Ali
Re: equivalent of typeid(Class).name at compile-time
On Thursday, 21 November 2019 at 20:44:19 UTC, Steven Schveighoffer wrote: I thought I could do typeid(Class).name to get the class name that will be returned at runtime if you did typeid(instance).name. But it's not accessible at compile-time. What compile-time string should I use for instance in a constructed switch statement? I'm trying to implement serialization and deserialization of classes, but I really would like to avoid using a class enum if possible, since the type id is already there and generated by the compiler. I solved that by storing the class info as the key in an associative array [1]. But it looks like Adam's solution will work as well. If you ideas, you can always have a look at Orange. [1] https://github.com/jacob-carlborg/orange/blob/90f1dbb0097ba4a319805bfb7d109f7038418ac6/orange/serialization/Serializer.d#L241-L262