Re: writeln Function while reading a Text File is printing appending text "before text" and "after text" at the same position
On Wednesday, 3 June 2020 at 20:05:52 UTC, ttk wrote: On Wednesday, 3 June 2020 at 19:53:03 UTC, BoQsc wrote: Removing the last element of the string got it resolved. Might not be the best way and adding additional check for carriage return before removing the element would be better, so this is only initial proof. Improved example with the above comments resolved. That works, but consider using chomp() instead. https://dlang.org/phobos/std_string.html#.chomp Chomp sounds kind of funny hahaha. Who came up with these function names? Walter Bright? Anyways, Chomp's way looks way more simple. Thanks. import std.stdio; import std.algorithm; import std.string; import std.uni : lineSep; int lineNumber; void main(){ File exampleFile = File("exampleText.txt"); lineNumber = 0; foreach(line; exampleFile.byLine){ if (line == " Sphinx of black quartz, judge my vow.\u000D"){ writeln(lineNumber, ". hahahahahahaha", chomp(line, "\r"), " nononono"); } else { writeln( lineNumber, ". ", line); } lineNumber++; } }
Re: writeln Function while reading a Text File is printing appending text "before text" and "after text" at the same position
Removing the last element of the string got it resolved. Might not be the best way and adding additional check for carriage return before removing the element would be better, so this is only initial proof. Improved example with the above comments resolved. testingGround.d import std.stdio; import std.algorithm; int lineNumber; void main(){ File exampleFile = File("exampleText.txt"); lineNumber = 0; foreach(line; exampleFile.byLine){ if (line == " Sphinx of black quartz, judge my vow.\u000D"){ if (line[line.length -1] == '\u000D'){ line = line.remove(line.length - 1); } writeln(lineNumber, ". hahahahahahaha", line, " nononono"); } else { writeln( lineNumber, ". ", line[line.length -1]); } lineNumber++; } }
Re: writeln Function while reading a Text File is printing appending text "before text" and "after text" at the same position
On Wednesday, 3 June 2020 at 18:49:38 UTC, ttk wrote: On Wednesday, 3 June 2020 at 18:23:51 UTC, BoQsc wrote: Here you can see ". hahahahahahaha" and "nononono" and even lineNumber is being merged into the same position. Why is this happening and can this be simply resolved? Your string in "line" has a carriage return character at the end, which moves the cursor to the beginning of the display row. If you remove this trailing carriage return character (0x0D) it will display correctly. With the carriage return character in place, everything written to your terminal after the carriage return starts at the beginning of the row. It seems to be correct. Removing the last element of the string got it resolved. Might not be the best way and adding additional check for carriage return before removing the element would be better, so this is only initial proof. Command Prompt Output C:\Users\vaida\Desktop\Associative Array Sorting> rdmd associativeArraySorting.d 0. The quick brown fox jumps over the lazy dog 1. hahahahahahaha Sphinx of black quartz, judge my vow.nononono 2. # How vexingly quick daft zebras jump! 3. # The five boxing wizards jump quickly 4. # Maecenas consectetur risus a lacus sodales iaculis. 5. # Morbi sed tortor sollicitudin, pharetra massa egestas, congue massa. 6. # Sed sit amet nisi at ligula ultrices posuere quis nec est. 7. # Mauris vel purus viverra, pellentesque elit id, consequat felis. testingGround.d import std.stdio; import std.algorithm; int lineNumber; void main(){ File exampleFile = File("exampleText.txt"); lineNumber = 0; foreach(line; exampleFile.byLine){ if (line == " Sphinx of black quartz, judge my vow.\u000D"){ writeln(lineNumber, ". hahahahahahaha", line.remove(line.length - 1), " nononono"); } else { writeln( lineNumber, ". ", line); } lineNumber++; } }
writeln Function while reading a Text File is printing appending text "before text" and "after text" at the same position
C:\Users\vaida\Desktop\Associative Array Sorting> rdmd testingGround.d 0. The quick brown fox jumps over the lazy dog nonononoahahahaha Sphinx of black quartz, judge my vow. 2. # How vexingly quick daft zebras jump! 3. # The five boxing wizards jump quickly 4. # Maecenas consectetur risus a lacus sodales iaculis. 5. # Morbi sed tortor sollicitudin, pharetra massa egestas, congue massa. 6. # Sed sit amet nisi at ligula ultrices posuere quis nec est. 7. # Mauris vel purus viverra, pellentesque elit id, consequat felis. Here you can see ". hahahahahahaha" and "nononono" and even lineNumber is being merged into the same position. Why is this happening and can this be simply resolved? testingGround.d import std.stdio; import std.algorithm; int lineNumber; void main(){ File exampleFile = File("exampleText.txt"); lineNumber = 0; foreach(line; exampleFile.byLine){ if (line == " Sphinx of black quartz, judge my vow.\u000D"){ writeln(lineNumber, ". hahahahahahaha", line, "nononono"); } else { writeln( lineNumber, ". ", line); } lineNumber++; } } exampleText.txt The quick brown fox jumps over the lazy dog Sphinx of black quartz, judge my vow. # How vexingly quick daft zebras jump! # The five boxing wizards jump quickly # Maecenas consectetur risus a lacus sodales iaculis. # Morbi sed tortor sollicitudin, pharetra massa egestas, congue massa. # Sed sit amet nisi at ligula ultrices posuere quis nec est. # Mauris vel purus viverra, pellentesque elit id, consequat felis.
How to efficiently resolve Associative Arrays not being sorted?
I want to read a file, put it into an array, make some search and replace on the content and output the modified text. However Associative Arrays seem to be unsorted by default. Should I drop the Associative Arrays and use something else? What are the ways to resolve this randomness in Associative Arrays? ReadfileAndCopyContentIntoArray.d import std.stdio; int lineNumber = 0; char[][int] fileInArray; void main(){ File exampleFile = File("exampleText.txt"); foreach(line; exampleFile.byLine){ lineNumber++; fileInArray[lineNumber] ~= line; } writeln(fileInArray); } exampleText.txt The quick brown fox jumps over the lazy dog Sphinx of black quartz, judge my vow. How vexingly quick daft zebras jump! The five boxing wizards jump quickly Maecenas consectetur risus a lacus sodales iaculis. Morbi sed tortor sollicitudin, pharetra massa egestas, congue massa. Sed sit amet nisi at ligula ultrices posuere quis nec est. Mauris vel purus viverra, pellentesque elit id, consequat felis. The Command Prompt Output [6:"Morbi sed tortor sollicitudin, pharetra massa egestas, congue massa.\r", 7:"Sed sit amet nisi at ligula ultrices pos uere quis nec est.\r", 2:"Sphinx of black quartz, judge my vow.\r", 3:"How vexingly quick daft zebras jump!\r", 1:"The q uick brown fox jumps over the lazy dog\r", 8:"Mauris vel purus viverra, pellentesque elit id, consequat felis.", 5:"Maec enas consectetur risus a lacus sodales iaculis.\r", 4:"The five boxing wizards jump quickly\r"] As can be seen in the Command Prompt Output, the array is not ordered correctly. It goes: 6: 7: 2: 3: 1: 8: 5: 4: Instead of 1: 2: 3: 4: 5: 6: 7: 8:
[Windows]Need an example: How to read and list names of USB devices via Windows API without using Utilities
I always wanted to know if there is any proven example on how to interface with USB devices by using Windows operating system. Any explanations, snippets in relation to topic would help. What I expect: Being able to detect if a new USB device is connected. Being able to read USB device name. Being able to read USB device partition/s name/s. Being able to list all USB devices. What is required and are there any critical problems with achieving any of this?
Re: Unable to access a variable declared inside an if statement (Error: is shadowing variable)
On Wednesday, 27 May 2020 at 11:13:09 UTC, Simen Kjærås wrote: On Wednesday, 27 May 2020 at 11:03:51 UTC, BoQsc wrote: I'm lacking knowledge on how to achieve what I want and getting an error. What is the correct way to do what I tried to achieve in this code? Everything was intuitive until I started to add notice variable to the writeln. Rdmd says variable `notice` is shadowing variable. if (driveLetter.exists){ auto directory = "/Backup"; if ((driveLetter ~ directory).exists){ auto notice = "Backup directory exists."; } writeln(driveLetter, notice); } Variables only live in a specified scope, starting from where they are declared, and ending when they reach the '}' indicating the end of said scope. In you case, 'notice' only lives inside the if ((driveLetter ~ directory).exists) scope, and doesn't exist outside. In order to fix this, you will need to declare it outside: if (driveLetter.exists) { auto directory = "/Backup"; auto notice = "Backup directory does not exist."; if ((driveLetter ~ directory).exists) { notice = "Backup directory exists."; } writeln(driveLetter, notice); } This also makes it clearer what value 'notice' will have when the backup directory doesn't exist - in your case you haven't assigned it any value in that case. -- Simen That's correct. Thanks Simen. import std.stdio : writeln; import std.file; void main(){ auto drivesLetters = [ "A:", "I:", "Q:", "Y:", "B:", "J:", "R:", "Z:", "C:", "K:", "S:", "D:", "L:", "T:", "E:", "M:", "U:", "F:", "N:", "V:", "G:", "O:", "W:", "H:", "P:", "X:", ]; foreach (string driveLetter; drivesLetters) { if (driveLetter.exists) { auto notice = ""; if ((driveLetter ~ "/Boot").exists) { notice ~= "\\Boot directory exists"; notice ~= " "; } if ((driveLetter ~ "/Windows").exists) { notice ~= "\\Windows folder exists"; notice ~= " "; } writeln(driveLetter, notice); } } }
Unable to access a variable declared inside an if statement (Error: is shadowing variable)
I'm lacking knowledge on how to achieve what I want and getting an error. What is the correct way to do what I tried to achieve in this code? Everything was intuitive until I started to add notice variable to the writeln. Rdmd says variable `notice` is shadowing variable. rdmd output: C:\Users\vaida\Desktop>rdmd searchDirectory.d searchDirectory.d(21): Error: variable `notice` is shadowing variable `searchDirectory.main.notice` Failed: ["C:\\D\\dmd2\\windows\\bin\\dmd.exe", "-v", "-o-", "searchDirectory.d", "-I."] searchDirectory.d import std.stdio : writeln; import std.file; void main(){ auto drivesLetters = [ "A:", "I:", "Q:", "Y:", "B:", "J:", "R:", "Z:", "C:", "K:", "S:", "D:", "L:", "T:", "E:", "M:", "U:", "F:", "N:", "V:", "G:", "O:", "W:", "H:", "P:", "X:", ]; foreach (string driveLetter; drivesLetters) { string notice; if (driveLetter.exists){ auto directory = "/Backup"; if ((driveLetter ~ directory).exists){ auto notice = "Backup directory exists."; } writeln(driveLetter, notice); } } }
Re: Spawn a Command Line application Window and output log information
On Tuesday, 19 May 2020 at 10:05:00 UTC, BoQsc wrote: On Monday, 18 May 2020 at 20:00:51 UTC, BoQsc wrote: I'm kind of stuck right now on how. Some more Updates and it seems that it is impossible to scroll the history of the output. Some relevant discussion: https://stackoverflow.com/a/5779422/3789797
Re: Spawn a Command Line application Window and output log information
On Monday, 18 May 2020 at 20:00:51 UTC, BoQsc wrote: I'm kind of stuck right now on how. Some more Updates and it seems that it is impossible to scroll the history of the output. import std.stdio : write, writeln, readln, writefln; import std.process : spawnShell, wait, executeShell, kill, thisProcessID; import core.thread.osthread : getpid; import std.process : environment; import std.file : getcwd; import std.file : thisExePath; void main() { spawnShell( "cls" ).wait; executeShell("title HelloWorld"); executeShell("chcp 65001"); executeShell("mode con: cols=120 lines=30"); writeln("Hello, World!"); writeln(" ▄ . .▄▄▌ ▄▄▌▄▄▌ ▐ ▄▌ ▄▄▄ ▄▄▌ · ██▪▐█▀▄.▀·██• ██• ▪ ██· █▌▐█▪ ▀▄ █·██• ██▪ ██ ██▀▐█▐▀▀▪▄██▪ ██▪ ▄█▀▄ ██▪▐█▐▐▌ ▄█▀▄ ▐▀▀▄ ██▪ ▐█· ▐█▌ ██▌▐▀▐█▄▄▌▐█▌▐▌▐█▌▐▌▐█▌.▐▌▐█▌██▐█▌▐█▌.▐▌▐█•█▌▐█▌▐▌██. ██ ▀▀▀ · ▀▀▀ .▀▀▀ .▀▀▀ ▀█▄▀▪ ▀▪ ▀█▄▀▪.▀ ▀.▀▀▀ ▀• The Adventures of HelloWorld"); writeln(" ┌──┐ ▒░░░┼┐ ≡▒░ ¦ ___▒▒┼┤┼▒▒▓"); writeln(" ~¨(··)¸ <│ > ‗┌═¬‗´ "); writeln("Path to executable and the filename: ", thisExePath()); writeln("Current Working Directory: ", getcwd()); writeln(); writeln("Accessible files from these Environment Paths"); writeln(environment["PATH"]); writeln(); writeln("Access TEMP environmental variable: ", environment.get("TEMP")); writefln("Current process id: %s", getpid()); writeln("This process id: ", thisProcessID()); string line; write("Your Input: "); while ((line = readln()) !is null) { if (line == "exit\x0a") { writeln("Going down"); return; } write(line); write("Your Input: "); } }
Re: None of the overloads of kill are callable using argument types:
On Monday, 18 May 2020 at 20:40:47 UTC, Adam D. Ruppe wrote: On Monday, 18 May 2020 at 20:11:25 UTC, BoQsc wrote: I'm trying to kill my own process Don't kill yourself, just `return` from main. Returning does what I need, however I still need to get a working example on killing/terminating for the future reference, just in case. However as Ali Çehreli stated, there seems to be a bigger problem, to why it is not possible right now. import std.stdio : write, writeln, readln, writefln; import std.process : spawnShell, wait, executeShell, kill, thisProcessID; import core.thread.osthread : getpid; void main() { spawnShell( "cls" ).wait; executeShell("title HelloWorld"); executeShell("chcp 65001"); executeShell("mode con: cols=120 lines=30"); writeln("Hello, World!"); writeln(" ▄ . .▄▄▌ ▄▄▌▄▄▌ ▐ ▄▌ ▄▄▄ ▄▄▌ · ██▪▐█▀▄.▀·██• ██• ▪ ██· █▌▐█▪ ▀▄ █·██• ██▪ ██ ██▀▐█▐▀▀▪▄██▪ ██▪ ▄█▀▄ ██▪▐█▐▐▌ ▄█▀▄ ▐▀▀▄ ██▪ ▐█· ▐█▌ ██▌▐▀▐█▄▄▌▐█▌▐▌▐█▌▐▌▐█▌.▐▌▐█▌██▐█▌▐█▌.▐▌▐█•█▌▐█▌▐▌██. ██ ▀▀▀ · ▀▀▀ .▀▀▀ .▀▀▀ ▀█▄▀▪ ▀▪ ▀█▄▀▪.▀ ▀.▀▀▀ ▀• A Tale of HelloWorld"); writeln(" ┌──┐ ▒░░░┼┐ ≡▒░ ¦ ___▒▒┼┤┼▒▒▓"); writeln(" ~¨(··)¸ <│ > ‗┌═¬‗´ "); writefln("Current process id: %s", getpid()); writeln("This process id: ", thisProcessID()); string line; write("Your Input: "); while ((line = readln()) !is null) { if (line == "exit\x0a") { writeln("Going down"); return; } write(line); write("Your Input: "); } }
None of the overloads of kill are callable using argument types:
I'm trying to kill my own process, but I'm being unsuccessful at the compilation of the program. It seems that neither getpid nor thisProcessID returns a correct type value for the kill function. HelloWorld.d(24): Error: none of the overloads of kill are callable using argument types (int), candidates are: C:\D\dmd2\windows\bin\..\..\src\phobos\std\process.d(2327): std.process.kill(Pid pid) C:\D\dmd2\windows\bin\..\..\src\phobos\std\process.d(2338): std.process.kill(Pid pid, int codeOrSignal) HelloWorld.d import std.stdio : write, writeln, readln, writefln; import std.process : executeShell, kill, thisProcessID; import core.thread.osthread : getpid; void main() { executeShell("title HelloWorld"); executeShell("chcp 65001"); writeln("Hello, World!"); writeln(" ▄ . .▄▄▌ ▄▄▌▄▄▌ ▐ ▄▌ ▄▄▄ ▄▄▌ · ██▪▐█▀▄.▀·██• ██• ▪ ██· █▌▐█▪ ▀▄ █·██• ██▪ ██ ██▀▐█▐▀▀▪▄██▪ ██▪ ▄█▀▄ ██▪▐█▐▐▌ ▄█▀▄ ▐▀▀▄ ██▪ ▐█· ▐█▌ ██▌▐▀▐█▄▄▌▐█▌▐▌▐█▌▐▌▐█▌.▐▌▐█▌██▐█▌▐█▌.▐▌▐█•█▌▐█▌▐▌██. ██ ▀▀▀ · ▀▀▀ .▀▀▀ .▀▀▀ ▀█▄▀▪ ▀▪ ▀█▄▀▪.▀ ▀.▀▀▀ ▀• "); writefln("Current process id: %s", getpid()); writeln("This process id: ", thisProcessID()); string line; write("Your Input: "); while ((line = readln()) !is null) { writeln(line); kill(thisProcessID()); write("Your Input: "); } }
Re: Spawn a Command Line application Window and output log information
On Monday, 18 May 2020 at 18:10:06 UTC, BoQsc wrote: Also, if you want some kind of Fancy ASCII art in your application Since I started this thread, I might share some more improvements. In this Update I managed to get the PID of the current process and in the future I hope the HelloWorld program process could be killed, I'm kind of stuck right now on how. Right now a complete Command Line command to compile HelloWorld example with a working Command Line Interface looks like this: dmd HelloWorld.d whatever.res && start "" "HelloWorld.exe" whatever.res - look at above posts on how to generate whatever.res HelloWorld.d import std.stdio : write, writeln, readln, writefln; import std.process : executeShell, kill, thisProcessID; import core.thread.osthread : getpid; void main() { executeShell("title HelloWorld"); executeShell("chcp 65001"); writeln("Hello, World!"); writeln(" ▄ . .▄▄▌ ▄▄▌▄▄▌ ▐ ▄▌ ▄▄▄ ▄▄▌ · ██▪▐█▀▄.▀·██• ██• ▪ ██· █▌▐█▪ ▀▄ █·██• ██▪ ██ ██▀▐█▐▀▀▪▄██▪ ██▪ ▄█▀▄ ██▪▐█▐▐▌ ▄█▀▄ ▐▀▀▄ ██▪ ▐█· ▐█▌ ██▌▐▀▐█▄▄▌▐█▌▐▌▐█▌▐▌▐█▌.▐▌▐█▌██▐█▌▐█▌.▐▌▐█•█▌▐█▌▐▌██. ██ ▀▀▀ · ▀▀▀ .▀▀▀ .▀▀▀ ▀█▄▀▪ ▀▪ ▀█▄▀▪.▀ ▀.▀▀▀ ▀• "); writefln("Current process id: %s", getpid()); writeln("This process id: ", thisProcessID()); string line; write("Your Input: "); while ((line = readln()) !is null) { writeln(line); write("Your Input: "); } }
Re: Spawn a Command Line application Window and output log information
On Monday, 18 May 2020 at 17:51:54 UTC, BoQsc wrote: On Monday, 18 May 2020 at 17:20:17 UTC, BoQsc wrote: It would be great if we could change/customise the icon of the Command line application that run the HelloWorld application. But I have a bad feeling that it is probably not possible without a GUI library. Forever thankful to Adam D. Ruppe It is possible to embed icon into the Windows executable. The Original Adam's thread: https://forum.dlang.org/post/enrmidvsfdugqmudo...@forum.dlang.org The instructions: Download a valid Windows 3.0 icon resource Examples: http://files.alexmeub.com.s3.amazonaws.com/other/win98_icons.zip Download the tools to embed the Icon for the .exe executable. http://ftp.digitalmars.com/bup.zip Create a new text file named whatever.rc with the content similar to this: IDI_ICON1 ICONDISCARDABLE "iconfil.ico" Use rcc.exe tool and whatever.rc file to generate whatever.res file. rcc.exe whatever.rc Use dmd.exe compiler to embed newly created whatever.res file into your .exe file while compiling: dmd.exe whatever.res You should see that the newly compiled .exe file is now with an Icon. And when launched the icon will be used by the Command Prompt. Also, if you want some kind of Fancy ASCII art in your application: Look at the Google for any ASCII Art generator: http://patorjk.com/software/taag/#p=display=Elite=Hello%20World Add this line and insert your ASCII art in a writeln function. executeShell("chcp 65001"); to your D language program source code More about chcp can be found here: https://ss64.com/nt/chcp.html Or here: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/chcp import std.stdio : write, writeln, readln; import std.process : executeShell; void main() { executeShell("title HelloWorld"); executeShell("chcp 65001"); writeln("Hello, World!"); writeln(" ▄ . .▄▄▌ ▄▄▌▄▄▌ ▐ ▄▌ ▄▄▄ ▄▄▌ · ██▪▐█▀▄.▀·██• ██• ▪ ██· █▌▐█▪ ▀▄ █·██• ██▪ ██ ██▀▐█▐▀▀▪▄██▪ ██▪ ▄█▀▄ ██▪▐█▐▐▌ ▄█▀▄ ▐▀▀▄ ██▪ ▐█· ▐█▌ ██▌▐▀▐█▄▄▌▐█▌▐▌▐█▌▐▌▐█▌.▐▌▐█▌██▐█▌▐█▌.▐▌▐█•█▌▐█▌▐▌██. ██ ▀▀▀ · ▀▀▀ .▀▀▀ .▀▀▀ ▀█▄▀▪ ▀▪ ▀█▄▀▪.▀ ▀.▀▀▀ ▀• "); string line; while ((line = readln()) !is null) write(line); }
Re: Spawn a Command Line application Window and output log information
On Monday, 18 May 2020 at 17:20:17 UTC, BoQsc wrote: It would be great if we could change/customise the icon of the Command line application that run the HelloWorld application. But I have a bad feeling that it is probably not possible without a GUI library. Forever thankful to Adam D. Ruppe It is possible to embed icon into the Windows executable. The Original Adam's thread: https://forum.dlang.org/post/enrmidvsfdugqmudo...@forum.dlang.org The instructions: Download a valid Windows 3.0 icon resource Examples: http://files.alexmeub.com.s3.amazonaws.com/other/win98_icons.zip Download the tools to embed the Icon for the .exe executable. http://ftp.digitalmars.com/bup.zip Create a new text file named whatever.rc with the content similar to this: IDI_ICON1 ICONDISCARDABLE "iconfil.ico" Use rcc.exe tool and whatever.rc file to generate whatever.res file. rcc.exe whatever.rc Use dmd.exe compiler to embed newly created whatever.res file into your .exe file while compiling: dmd.exe whatever.res You should see that the newly compiled .exe file is now with an Icon. And when launched the icon will be used by the Command Prompt.
Re: Spawn a Command Line application Window and output log information
On Monday, 18 May 2020 at 17:08:41 UTC, Kagamin wrote: On Monday, 18 May 2020 at 17:02:02 UTC, BoQsc wrote: The important question is: how can we change the name/title of this Command Line application. As the simplest solution, you can set the window title in shortcut properties. It seems that all the Command Prompt Batch command of windows such as "title" do work well. By using executeShell I was able to change the title of the Command Line that runs my program. import std.stdio : write, writeln, readln; import std.process : executeShell; void main() { writeln("Hello, World!"); executeShell("title HelloWorld"); string line; while ((line = readln()) !is null) write(line); } import std.file : mkdir; It would be great if we could change/customise the icon of the Command line application that run the HelloWorld application. But I have a bad feeling that it is probably not possible without a GUI library.
Re: Spawn a Command Line application Window and output log information
On Monday, 18 May 2020 at 16:40:24 UTC, Panke wrote: On Monday, 18 May 2020 at 16:36:11 UTC, BoQsc wrote: I'd like to have application as small as possible with a simple Command Line Window. I'd use that Window to output notices, log information and the like. Would this require GUI library and how can this be achieved? If you do not want to create the library yourself, you could spawn a terminal application like konsole or kitty and start a simple cli app. You'd need to have some form of inter process communication setup for this though. On Windows 10, this example, when compiled and clicked on the executable - spawns a command line with the "Hello World" output shown. import std.stdio; void main() { write("Hello, World!"); string line; while ((line = readln()) !is null) write(line); } The important question is: how can we change the name/title of this Command Line application.
Spawn a Command Line application Window and output log information
I'd like to have application as small as possible with a simple Command Line Window. I'd use that Window to output notices, log information and the like. Would this require GUI library and how can this be achieved?
Re: After compiling Hello World with DMD Compiler, .EXE file takes 1-3 seconds to run for the first time
On Monday, 18 May 2020 at 15:49:06 UTC, Adam D. Ruppe wrote: On Monday, 18 May 2020 at 15:47:40 UTC, BoQsc wrote: It seems strange that on the first run after D language compilation. Hello World program takes 1-3 seconds to launch. That's the Windows virus scanner again. It sees D programs as unusual and gives them additional scrutiny... You can set an exception in the windows virus scanner settings for the folder where you work with D. That's exactly what it was. I disabled the Windows Security Real-Time Protection, and tested few more times. The execution was immediate. Thanks Adam.
After compiling Hello World with DMD Compiler, .EXE file takes 1-3 seconds to run for the first time
I use Windows 10. I tried exactly like mentioned here: http://ddili.org/ders/d.en/hello_world.html It seems strange that on the first run after D language compilation. Hello World program takes 1-3 seconds to launch. While C Hello World program simply executes in a second or less. Why is that, and what can we do about it.
[GTK-D] dub run leads to lld-link: error: could not open libcmt.lib: no such file or directory
A simple example I tried to run. #!/usr/bin/env dub /+ dub.sdl: name "hello" dependency "gtk-d" version="~>3.9.0" +/ import gtk.MainWindow; import gtk.Label; import gtk.Main; void main(string[] args) { Main.init(args); MainWindow win = new MainWindow("Hello World"); win.setDefaultSize(200, 100); win.add(new Label("Hello World")); win.showAll(); Main.run(); } This is how I tried to run it. C:\Users\vaida\Desktop\Command prompt shell>dub run --single gui.d Performing "debug" build using C:\D\dmd2\windows\bin\dmd.exe for x86_64. gtk-d:gtkd 3.9.0: target for configuration "library" is up to date. gtk-d:gstreamer 3.9.0: target for configuration "library" is up to date. gtk-d:peas 3.9.0: target for configuration "library" is up to date. gtk-d:sv 3.9.0: target for configuration "library" is up to date. gtk-d:vte 3.9.0: target for configuration "library" is up to date. hello ~master: building configuration "application"... Linking... lld-link: error: could not open libcmt.lib: no such file or directory lld-link: error: could not open OLDNAMES.lib: no such file or directory Error: linker exited with status 1 C:\D\dmd2\windows\bin\dmd.exe failed with exit code 1.
Concatenation/joining strings together in a more readable way
Are there any other ways to join two strings without Tilde ~ character? I can't seems to find anything about Tilde character concatenation easily, nor the alternatives to it. Can someone share some knowledge on this or at least point out useful links/resources?
What would it take to bring preinstalled D language compiler in the major Linux Distributions?
I would love to see D language available out of box in major Linux distributions and use without much care of installation. Anyone have a though about it? Was there any serious efforts to bring D language to Major distributions?
What kind of Editor, IDE you are using and which one do you like for D language?
There are lots of editors/IDE's that support D language: https://wiki.dlang.org/Editors What kind of editor/IDE are you using and which one do you like the most?
Should I stop being interested in D language if I don't like to see template instantiation in my code?
I don't like to see exclamation marks in my code in as weird syntax as these ones: to!ushort(args[1]) s.formattedRead!"%s!%s:%s"(a, b, c); I'm not sure why, but template instantiation syntax is prevalent in the documentation examples of d lang libraries. It almost seems like every other example contains at least one or two of them. It look horrible, and I'm feeling like I'm being forced/coerced to learn from examples that do not provide alternatives to the template instantiation syntax. Even if the alternative examples were provided, why would anyone want to have syntax as ugly and weird as current template instantiation syntax with exclamation point in the middle of the statement with all other things that come with it.
When should we use Modules and when Should we use Classes?
Would be nice to have a short summary or detailed answer on this. Some resources to discuss this topic: https://dlang.org/spec/class.html https://dlang.org/spec/module.html
Make executable archive just like Java's .jar archive?
Is there a way to archive multiple .d source code files and make that archive executable, or something similar?
Re: Make executable archive just like Java's .jar archive?
On Thursday, 12 September 2019 at 12:52:48 UTC, BoQsc wrote: Is there a way to archive multiple .d source code files and make that archive executable, or something similar? https://en.wikipedia.org/wiki/JAR_(file_format)
What is "dmd" Internal API, can I use it just like std Library Reference?
Hello everyone, again, I had an idea that I want some colors in the output of Command Line (For Windows) and the Terminal (For Linux) I found https://dlang.org/phobos/dmd_console.html and wanted to use it. But it seems I'm not being successful, and I do not understand why. Here, you can see that I'm trying to import dmd.console; import std.stdio : writeln; import dmd.console; void main() { writeln("Hello World"); } And the output says that, dmd.console; do not exist? What are these Internal APIs for? C:\Users\Juozas\Desktop>rdmd color.d color.d(2): Error: module `console` is in file 'dmd\console.d' which cannot be read
Re: Downloading a file and showing progress via curl.
On Tuesday, 20 August 2019 at 11:51:03 UTC, Daniel Kozak wrote: For that you can use https://dlang.org/phobos/std_file#append Thank you, seems to work. import std.net.curl : HTTP; import std.stdio: writeln; import std.file : append; void main() { auto http = HTTP(); // Track progress http.method = HTTP.Method.get; http.url = "https://upload.wikimedia.org/wikipedia/commons/5/53/Wikipedia-logo-en-big.png;; http.onReceive = (ubyte[] data) { append("Wikipedia-logo-en-big.png", data); return data.length; }; http.onProgress = (size_t dltotal, size_t dlnow, size_t ultotal, size_t ulnow) { writeln("Progress ", dltotal, ", ", dlnow, ", ", ultotal, ", ", ulnow); return 0; }; http.perform(); }
Downloading a file and showing progress via curl.
Hello everyone, I found this snippet on https://dlang.org/phobos/std_net_curl.html#.HTTP import std.net.curl : HTTP; import std.stdio : writeln; void main() { auto http = HTTP(); // Track progress http.method = HTTP.Method.get; http.url = "https://upload.wikimedia.org/wikipedia/commons/5/53/Wikipedia-logo-en-big.png;; http.onReceive = (ubyte[] data) { return data.length; }; http.onProgress = (size_t dltotal, size_t dlnow, size_t ultotal, size_t ulnow) { writeln("Progress ", dltotal, ", ", dlnow, ", ", ultotal, ", ", ulnow); return 0; }; http.perform(); } This snippet is showing Download Progress in bytes, but I'm unsure how to save the downloaded file into filesystem after download is completed.
Re: How to setup D language with Apache httpd cgi?
On Wednesday, 31 July 2019 at 14:19:20 UTC, bachmeier wrote: is going to compile every time it runs, which makes the program unnecessarily slow If only I could add dub --single --rdmd to the shebang, I think dub might stop compiling every time. However as pointed out in the above post, I'm unable to use options in shebang since apache is throwing header error for unknown reasons.
Re: How to setup D language with Apache httpd cgi?
However I tried to add options (--single) to the dub shebang and apache now throwing: "bad header error" Without "--single" option seems to work. #!/usr/bin/env -vS dub --single /+ dub.sdl: name "application" dependency "arsd-official:dom" version="4.0.2" +/ import std.stdio; import arsd.dom; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`test`); } split -S: 'dub --single' into:'dub' &'--single' executing: dub arg[0]= 'dub' arg[1]= '--single' arg[2]= '/usr/lib/cgi-bin/example.d' [Wed Jul 31 19:57:56.892522 2019] [cgid:error] [pid 833:tid 140583783876352] [client >127.0.0.1:43598] malformed header from script 'example.d': Bad header: Performing "debug" >build using
Re: How to setup D language with Apache httpd cgi?
is going to compile every time it runs, which makes the program unnecessarily slow, and if it's used heavily, will add quite a load to the server. I finally done it, and I'm not sure if it compiles every time. It opens the page lightning fast since I use SSD drive. I'm not sure how to check if it compiles every time. Right now, I'm logged in as root and chmoded recursively the whole /usr/lib/cgi-bin/ folder and it succeed. #!/usr/bin/env dub /+ dub.sdl: name "application" dependency "arsd-official:dom" version="4.0.2" subConfiguration "arsd-official:cgi" "cgi" +/ import std.stdio; import arsd.dom; void main() { writeln(`Content-type: text/html`); writeln(``); auto document = new Document("paragraph"); document.root.innerHTML = "hey"; writeln(document); //writeln(`CGI D Example`); }
Re: How to setup D language with Apache httpd cgi?
Hmm, it seems that once I remove sudo from the shebang, the error disappears and Internal Server Error disappears. example.d - does not work #!/usr/bin/env -S sudo dub /+ dub.sdl: name "hello" +/ import std.stdio; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`CGI D Example`); } /var/log/apache2/error.log [Wed Jul 31 15:48:07.769766 2019] [cgid:error] [pid 4012:tid 140324198397696] [client >127.0.0.1:51736] End of script output before headers: example.d example.d - Works perfectly, no errors in the log #!/usr/bin/env -S dub /+ dub.sdl: name "hello" +/ import std.stdio; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`CGI D Example`); }
Re: How to setup D language with Apache httpd cgi?
On Wednesday, 31 July 2019 at 09:09:12 UTC, BoQsc wrote: On Wednesday, 31 July 2019 at 09:03:47 UTC, BoQsc wrote: And this is the error I get now: [Wed Jul 31 11:51:15.341790 2019] [cgid:error] [pid 870:tid 140153708345088] [client >127.0.0.1:50318] End of script output before headers: example.d And I have no idea how to deal with it. Cgi shows Internal Server Error, because of that "End of script output before headers" error. It seems like apache does not like what dub package manager is doing, as dub does something before cgi script outputs anything. https://stackoverflow.com/questions/22307610/end-of-script-output-before-headers-error-in-apache
Re: How to setup D language with Apache httpd cgi?
On Wednesday, 31 July 2019 at 09:03:47 UTC, BoQsc wrote: And this is the error I get now: [Wed Jul 31 11:51:15.341790 2019] [cgid:error] [pid 870:tid 140153708345088] [client >127.0.0.1:50318] End of script output before headers: example.d And I have no idea how to deal with it. Cgi shows Internal Server Error, because of that "End of script output before headers" error. #!/usr/bin/env -S sudo dub run --quiet --single /+ dub.sdl: name "hello" dependency "arsd-official" version="~>4.0.1" +/ import std.stdio; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`CGI D Example`); } Maybe it is not possible to use dub this way.
Re: How to setup D language with Apache httpd cgi?
On Wednesday, 31 July 2019 at 08:32:43 UTC, BoQsc wrote: Added sudo to the shebang, it started to say that sudo requires tty, meaning that there is no graphical interface for user to input the password. So, I remove the need to type password when using sudo command, by following these instructions: https://www.cyberciti.biz/faq/linux-unix-running-sudo-command-without-a-password/ And this is the error I get now: [Wed Jul 31 11:51:15.341790 2019] [cgid:error] [pid 870:tid 140153708345088] [client >127.0.0.1:50318] End of script output before headers: example.d
Re: How to setup D language with Apache httpd cgi?
On Wednesday, 31 July 2019 at 07:57:01 UTC, BoQsc wrote: [Wed Jul 31 10:44:26.887024 2019] [cgid:error] [pid 846:tid 140090256426752] [client >127.0.0.1:57052] malformed header from script 'example.d': Bad header: Fetching arsd-official 4.0.1 ( /usr/lib/cgi-bin/.dub/packages/: Permission denied Added sudo to the shebang, it started to say that sudo requires tty, meaning that there is no graphical interface for user to input the password. [Wed Jul 31 11:14:53.183607 2019] [cgid:error] [pid 6207:tid 140374439274240] [client >127.0.0.1:57400] End of script output before headers: example.d sudo: no tty present and no askpass program specified Script: #!/usr/bin/env -S sudo dub run --single /+ dub.sdl: name "hello" dependency "arsd-official" version="~>4.0.1" +/ import std.stdio; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`CGI D Example`); }
Re: How to setup D language with Apache httpd cgi?
On Wednesday, 31 July 2019 at 07:42:22 UTC, BoQsc wrote: This seems to work well when running not from cgi, so there is That was not true, it didn't work even from Linux Shell, I corrected shebang, now it works from Linux Shell. An, unexpected thing: It did require permissions: sudo ./example.d which was not the case with rdmd. cgi still shows Internal Server Error. Maybe cgi cannot run this script due to lacking sudo permissions required by dub? Unsure. #!/usr/bin/env -S dub run --single /+ dub.sdl: name "hello" dependency "arsd-official" version="~>4.0.1" +/ import std.stdio; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`CGI D Example`); } It seems that /var/log/apache2/error.log shows Permission denied error. [Wed Jul 31 10:44:26.887024 2019] [cgid:error] [pid 846:tid 140090256426752] [client >127.0.0.1:57052] malformed header from script 'example.d': Bad header: Fetching arsd-official 4.0.1 ( /usr/lib/cgi-bin/.dub/packages/: Permission denied
Re: How to setup D language with Apache httpd cgi?
This seems to work well when running not from cgi, so there is That was not true, it didn't work even from Linux Shell, I corrected shebang, now it works from Linux Shell. An, unexpected thing: It did require permissions: sudo ./example.d which was not the case with rdmd. cgi still shows Internal Server Error. Maybe cgi cannot run this script due to lacking sudo permissions required by dub? Unsure. #!/usr/bin/env -S dub run --single /+ dub.sdl: name "hello" dependency "arsd-official" version="~>4.0.1" +/ import std.stdio; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`CGI D Example`); }
Re: How to setup D language with Apache httpd cgi?
I tried to change shebang, but: Internal Server Error still appears. #!/usr/bin/env dub run --single /+ dub.sdl: name "hello" dependency "arsd-official" version="~>4.0.1" +/ import std.stdio; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`CGI D Example`); }
Re: How to setup D language with Apache httpd cgi?
There are some other bad news, I switched from rdmd to dub package manager since I need a package from Adam D. Ruppe. It is all good and well: this one works perfectly. #!/usr/bin/env dub /+ dub.sdl: name "hello" +/ import std.stdio; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`CGI D Example`); } But, once I add dub dependency, the error appears: Internal Server Error #!/usr/bin/env dub /+ dub.sdl: name "hello" dependency "arsd-official" version="~>4.0.1" +/ import std.stdio; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`CGI D Example`); } This seems to work well when running not from cgi, so there is no syntax error.
Re: How to setup D language with Apache httpd cgi?
On Wednesday, 31 July 2019 at 06:52:46 UTC, 0xEAB wrote: On Wednesday, 31 July 2019 at 06:30:03 UTC, BoQsc wrote: This can be solved by using single quotes in the argument content places #!/usr/bin/env rdmd import std.stdio; void main() { writeln("Content-type: text/html"); writeln(""); writeln("CGI D Example"); } Does the job but is a bad fix. Use `` quotes for the string literal instead. Further info: https://dlang.org/spec/lex.html#wysiwyg - Elias I wasn't aware of Wysiwyg Strings, thanks, seems to work very well. #!/usr/bin/env rdmd import std.stdio; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`CGI D Example`); }
Re: How to setup D language with Apache httpd cgi?
On Wednesday, 31 July 2019 at 06:55:06 UTC, 0xEAB wrote: On Wednesday, 31 July 2019 at 06:30:03 UTC, BoQsc wrote: On Wednesday, 31 July 2019 at 05:56:46 UTC, BoQsc wrote: what causes the Internal Server Error. Internal Server Error might as well appear when D language syntax is not correct. Maybe you want to use some wrapper around rdmd that does output a proper CGI response on error. Since this error occurs because rdmd's error message as-is is not valid for CGI. - Elias I'm kind of new to everything, I'm not sure how this have to be done.
Re: How to setup D language with Apache httpd cgi?
On Wednesday, 31 July 2019 at 05:56:46 UTC, BoQsc wrote: what causes the Internal Server Error. Internal Server Error might as well appear when D language syntax is not correct. Considering this: this example has Internal Server Error, since writeln argument and argument content cannot contain the same type quotes: Internal Server Error #!/usr/bin/env rdmd import std.stdio; void main() { writeln("Content-type: text/html"); writeln(""); writeln("CGI D Example"); } This can be solved by using single quotes in the argument content places #!/usr/bin/env rdmd import std.stdio; void main() { writeln("Content-type: text/html"); writeln(""); writeln("CGI D Example"); } Or even escaping argument content quotes: #!/usr/bin/env rdmd import std.stdio; void main() { writeln("Content-type: text/html"); writeln(""); writeln("CGI D Example"); } That is good to know.
Re: How to setup D language with Apache httpd cgi?
On Tuesday, 30 July 2019 at 21:55:00 UTC, Adam D. Ruppe wrote: the required blank line to separate headers from content. That's exactly what causes the Internal Server Error. This is a working example.d #!/usr/bin/env rdmd import std.stdio; void main() { writeln(""); } And this one, even produce HTML content to the HTML body tag: #!/usr/bin/env rdmd import std.stdio; void main() { writeln("Content-type: text/html"); writeln(""); writeln("CGI D Example"); } Thanks, Adam D. Ruppe, it works.
How to setup D language with Apache httpd cgi?
Hello, I would like to know how to setup D language project, so that it would work with Apache httpd cgi. Do I need some kind of cgi library for D language? Right now all I'm getting is internal server error. Btw. Unix Bash script examples seems to work well with with Apache httpd cgi, they do not show internal server error. Before trying examples below, it is required that you install apache httpd: sudo apt-get install apache2 And enable cgi module sudo a2enmod cgi sudo service apache2 restart Here are examples: D language example, this one does not work. Give internal error. /usr/lib/cgi-bin/example.d #!/usr/bin/env rdmd import std.stdio; void main() { writeln("Hello, world with automated script running!"); } Bash example, this one working perfectly. /usr/lib/cgi-bin/example.sh #!/bin/bash echo "Content-type: text/html" echo '' echo 'CGI Bash Example' Also remember to chmod the examples, before opening them: sudo chmod 755 /usr/lib/cgi-bin/example.sh sudo chmod 755 /usr/lib/cgi-bin/example.d
Calling / running / executing .d script from another .d script
Right now, I'm thinking what is correct way to run another .d script from a .d script. Do you have any suggestions?
Is it possible to disallow import for certain functions?
I would like to make sure that function in module that I have won't be imported, is this possible to achieve? Test subject: mainFile.d import otherFile; void main(){ } otherFile.d import std.stdio : writeln; import std.file : mkdir; int main(){ writeln("test "); return 0; } Error, main() method has been imported: how to disallow main() method from being imported? otherFile.d(5): Error: only one main, WinMain, or DllMain allowed. Previously found main at mainFile.d(3)
Re: Blog Post #0052: MVC V - ComboBox with Integers
On Friday, 12 July 2019 at 11:13:31 UTC, Ron Tarrant wrote: Today's post deals with integers in a ComboBox. It's not exactly tricky, but a little clarification never hurts, right? Here's where you'll find it: https://gtkdcoding.com/2019/07/12/0052-mvc-v-int-combobox.html Gnome project should just rewrite everything in D language, especially the Gnome Shell. At least that would be a right direction. Thanks for the texts Ron, it is so nice to see images - visuals, showing the result and they fit so nicely with your article. The more visuals and working examples - the easier for some of us to understand. :)
Re: Is it possible to execute a function inside .d script that has no main function?
On Thursday, 11 July 2019 at 10:41:38 UTC, Alex wrote: On Thursday, 11 July 2019 at 09:43:55 UTC, BoQsc wrote: Here I have a file named: module.d [...] There is no main() function since, I want to import this module, into another .d file. ( If I try to import and module.d does have main() function I get this error: ) [...] I would like to launch function "interestingFunction()" directly using rdmd. Is it possible to achieve that by any way? I tried to launch the whole file, but it gave me some weird output: [...] If you are trying to test a function separately from other functions, e.g. for testing, then you are approaching unit testing. You could write a unit test block just under the function to test like unittest { interestingFunction; } and launch it via rdmd... don't know the syntax right now. But here is something: https://stackoverflow.com/questions/10694994/rdmd-is-not-running-unit-tests So, I assume something like rdmd -unittest --main module.d Hmm, maybe I'll just rename module.d to module_library.d and place it in a folder, then create a new module_run.d file that would launch the functions of module_library.d module\module_library.d module\module_run.d README.md Maybe even place a README.md file explaining how I come up with this idea. And when in need of executing it, I'll just type: rdmd module\module_run.d
Is it possible to execute a function inside .d script that has no main function?
Here I have a file named: module.d import std.stdio : writeln; void interestingFunction(){ writeln("Testing"); } There is no main() function since, I want to import this module, into another .d file. ( If I try to import and module.d does have main() function I get this error: ) otherFile.d(13): Error: only one main, WinMain, or DllMain allowed. Previously found main at module.d(3) I would like to launch function "interestingFunction()" directly using rdmd. Is it possible to achieve that by any way? I tried to launch the whole file, but it gave me some weird output: C:\Users\User\Desktop\Environment variables>rdmd module.d OPTLINK (R) for Win32 Release 8.00.17 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html OPTLINK : Warning 134: No Start Address
How to use std.windows.registry, there are no documentations.
https://dlang.org/phobos/std_windows_registry.html https://github.com/dlang/phobos/blob/master/std/windows/registry.d Can someone provide some examples on how to: set, change, receive something from the Windows registry using Phobos std.windows.registry library?
Re: SendMessageTimeoutW requires casting string to uint?
On Tuesday, 9 July 2019 at 13:10:57 UTC, a11e99z wrote: On Tuesday, 9 July 2019 at 12:14:38 UTC, BoQsc wrote: On Tuesday, 9 July 2019 at 11:11:53 UTC, Dejan Lekic wrote: auto result = SendMessageTimeoutW( HWND_BROADCAST, WM_SETTINGCHANGE, 0, envi.toUTF16z, SMTO_ABORTIFHUNG, timeout, null ); C:\Users\User\Desktop>rdmd ref.d ref.d(19): Error: function `core.sys.windows.winuser.SendMessageTimeoutW(void*, uint, uint, int, uint, uint, uint*)` is not callable using argument types `(void*, int, int, const(wchar)*, int, uint, typeof(null))` ref.d(19):cannot pass argument `toUTF16z(cast(const(char)[])envi)` of type `const(wchar)*` to parameter `int` Failed: ["C:\\D\\dmd2\\windows\\bin\\dmd.exe", "-v", "-o-", "ref.d", "-I."] // add cast to LPARAM for SendMessageTimeoutW cast( LPARAM )envi.toUTF16z, // import lib too somewhere out of main() or in command line version(Windows) pragma(lib, "user32.lib"); You are absolutely right. Here is a working example code on how to broadcast environment variables changes from D language to Windows XP, 7, 8, 10 systems, if anyone searches for it. To launch the code: rdmd broadcastSignal.d broadcastSignal.d import std.utf; version(Windows) pragma(lib, "user32.lib"); import core.sys.windows.windows : SendMessageTimeoutW; import core.sys.windows.windows : GetLastError; import core.sys.windows.windows : ERROR_SUCCESS; import core.sys.windows.windows : SMTO_ABORTIFHUNG; import core.sys.windows.windows : LPARAM; import core.sys.windows.windows : HWND_BROADCAST; import core.sys.windows.windows : WM_SETTINGCHANGE; void main(){ broadcastSettingChange(); } /** Broadcasts a signal to update All Environment variables On Windows XP, 7, 8, 10 systems. Mostly used update changes to Path environment variable. After broadcast of this signal, reopen applications, for changes to be visible. Date: 07/09/2019 License: use freely for any purpose Params: addressBroadcast = "Policy" When the system sends this message as a result of a change in policy settings, this parameter points to this string. "intl"When the system sends this message as a result of a change in locale settings, this parameter points to this string. "Environment" To effect a change in the environment variables for the system or the user, broadcast this message with lParam set to this string Returns: does not return See_Also: https://docs.microsoft.com/lt-lt/windows/win32/api/winuser/nf-winuser-sendmessagetimeouta https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-settingchange */ void broadcastSettingChange (string addressBroadcast="Environment", uint timeout=1) { void* hWnd = HWND_BROADCAST; uint Msg = WM_SETTINGCHANGE; uint wParam = 0; int lParam = cast( LPARAM )addressBroadcast.toUTF16z; uint fuFlags = SMTO_ABORTIFHUNG; uint uTimeout = timeout; uint* lpdwResult = null; int result = SendMessageTimeoutW( hWnd, Msg, wParam, lParam, SMTO_ABORTIFHUNG, uTimeout, lpdwResult ); if(result == 0) { auto errCode = GetLastError(); } }
Re: SendMessageTimeoutW requires casting string to uint?
On Tuesday, 9 July 2019 at 11:11:53 UTC, Dejan Lekic wrote: Now that I browsed the std.utf more, I realised what fits your need best is the https://dlang.org/phobos/std_utf.html#toUTF16z So far, this is what I have: Filename: myVersion.d import core.sys.windows.windows : SendMessageTimeoutW; import core.sys.windows.windows : GetLastError; import core.sys.windows.windows : ERROR_SUCCESS; import core.sys.windows.windows : SMTO_ABORTIFHUNG; import core.sys.windows.windows : LPARAM; import core.sys.windows.windows : HWND_BROADCAST; import core.sys.windows.windows : WM_SETTINGCHANGE; import std.utf; void main(){ broadcastSettingChange(); } void broadcastSettingChange (string envi="Environment", uint timeout=1) { auto result = SendMessageTimeoutW( HWND_BROADCAST, WM_SETTINGCHANGE, 0, envi.toUTF16z, SMTO_ABORTIFHUNG, timeout, null ); if(result == 0) { auto errCode = GetLastError(); } } The dmd output: C:\Users\User\Desktop>rdmd ref.d ref.d(19): Error: function `core.sys.windows.winuser.SendMessageTimeoutW(void*, uint, uint, int, uint, uint, uint*)` is not callable using argument types `(void*, int, int, const(wchar)*, int, uint, typeof(null))` ref.d(19):cannot pass argument `toUTF16z(cast(const(char)[])envi)` of type `const(wchar)*` to parameter `int` Failed: ["C:\\D\\dmd2\\windows\\bin\\dmd.exe", "-v", "-o-", "ref.d", "-I."]
SendMessageTimeoutW requires casting string to uint?
I'm quite new to the programming, and I'm getting unsure how to make SendMessageTimeoutW to work with D lang. Most of my attention right now resides around the Argument of the SendMessageTimeoutW function: "Environment", It seems that SendMessageTimeoutW accepts only uint type, and string can't be directly used. I think that I have to convert string characters to "C-style 0 terminated string". And everything should work? But I'm unsure how to do that. All I know that there was toString16z function from tango project, that made it all work. http://www.dsource.org/projects/tango/docs/stable/tango.stdc.stringz.html#toString32z cast(LPARAM)(settingName.toString16z()) Here is how the method was before my modifications: void broadcastSettingChange (string settingName, uint timeout=1) { auto result = SendMessageTimeoutW( HWND_BROADCAST, WM_SETTINGCHANGE, 0, cast(LPARAM)(settingName.toString16z(), SMTO_ABORTIFHUNG, timeout, null ); And finally, here is myVersion.d that throws an error (that I use incorrect variable type for the argument) myVersion.d import core.sys.windows.windows : SendMessageTimeoutW; import core.sys.windows.windows : GetLastError; import core.sys.windows.windows : ERROR_SUCCESS; import core.sys.windows.windows : SMTO_ABORTIFHUNG; import core.sys.windows.windows : LPARAM; import core.sys.windows.windows : HWND_BROADCAST; import core.sys.windows.windows : WM_SETTINGCHANGE; void main(){ broadcastSettingChange(); } void broadcastSettingChange (uint timeout=1) { auto result = SendMessageTimeoutW( HWND_BROADCAST, WM_SETTINGCHANGE, 0, "Environment", SMTO_ABORTIFHUNG, timeout, null ); if(result == 0) { auto errCode = GetLastError(); } }
Re: Changing Environment Paths using D language's Phobos Library
On Saturday, 29 June 2019 at 09:50:12 UTC, BoQsc wrote: On Saturday, 29 June 2019 at 09:28:03 UTC, BoQsc wrote: I checked the documentation and it seems that, you assumed the wrong syntax for "environment.opIndexAssign()" The correct syntax is: environment.opIndexAssign("Some Random Value Here", "variableName"); And not this one: environment.opIndexAssign("variableName", "Some Random Value Here"); Take a look at this documentation once more: https://dlang.org/library/std/process/environment.op_index_assign.html You are absolutely correct, however, it seems that these new variables that we create by using environment.opIndexAssign("Some Random Value Here", "variableName"); Are not accessible in Windows 10 settings, at all, as far as I see now. Is that suppose to be that way? I tried to open command prompt and the environment variable that we just created using D lang Phobos "opIndexAssign()" function seems to be not accessible nor created. What is happening, does anyone know?
Re: Changing Environment Paths using D language's Phobos Library
On Saturday, 29 June 2019 at 09:28:03 UTC, BoQsc wrote: However, setting the variable via "environment.opIndexAssign" seems to not work. What should we do? I don't know. I'm glad I'm on this forum, I know exactly what you did wrong mr. BoQsc I checked the documentation and it seems that, you assumed the wrong syntax for "environment.opIndexAssign()" The correct syntax is: environment.opIndexAssign("Some Random Value Here", "variableName"); And not this one: environment.opIndexAssign("variableName", "Some Random Value Here"); Take a look at this documentation once more: https://dlang.org/library/std/process/environment.op_index_assign.html import std.stdio : writeln; import std.array : replace; import std.process : environment; void main(){ // Retrieve environment variable "path" for testing if it is possible // to retrieve it by using D language Phobos Library auto environmentPaths = environment.get("path"); writeln(environmentPaths); // Works as expected: we can see the output of Paths. // Create a new Environement variable for testing if it is possible // to Create it with D language Phobos Library environment.opIndexAssign("Some Random Value Here", "variableName"); auto environmentalVariable = environment.get("variableName"); writeln(environmentalVariable); //Unexpected: absolutely no output. }
Changing Environment Paths using D language's Phobos Library
I would like to remove/add/change Environment Paths using D language's Phobos. https://en.wikipedia.org/wiki/PATH_(variable) I saw in the documentation that there is a class file "std.process : environment" that has the supposed ability to minipulate environment variables. https://dlang.org/library/std/process/environment.html I couldn't find a good documentation on how to search and replace strings using Phobos Library. However it seems that it might be possbile by importing "std.array : replace" function. https://forum.dlang.org/post/jnua50$1e4a$1...@digitalmars.com https://dlang.org/library/std/array/replace.html So, here we are, testing if it is possible to retrieve and set the Environmental Variables. import std.stdio : writeln; import std.array : replace; import std.process : environment; void main(){ // Retrieve environment variable "path" for testing if it is possible // to retrieve it by using D language Phobos Library auto environmentPaths = environment.get("path"); writeln(environmentPaths); // Works as expected: we can see the output of Paths. // Create a new Environement variable for testing if it is possible // to Create it with D language Phobos Library environment.opIndexAssign("variableName", "Some Random Value Here"); auto environmentalVariable = environment.get("variableName"); writeln(environmentalVariable); //Unexpected: absolutely no output. Alright, now that we see it is possible to retrieve environmental variable, that's great. However, setting the variable via "environment.opIndexAssign" seems to not work. What should we do? I don't know.
How to prepare and generate a simple lightweight binary?
There are lots of talks on this forum about Statical linking, Dynamic linking. There are even shouts: "use the ldc compiler instead, it can do all that and even more than the default dmd compiler!!!" and bunch of compiler flags, no instructions on how to start or even steps on how to reproduce a simple program that wouldn't weight megabytes. I would like receive all the steps in this thread, with all the obvious download links and little commenting - the walkthrough. What I would expect: A simple executable program that does a writeln and do not weight tons of megabytes. Thanks. (1 ton of megabyte == 1 megabyte == 1MB)
Is it possible to escape a reserved keyword in Import/module?
I would like to make sure that my modules do not interfere with d lang. Is there any way to escape reserved words? https://dlang.org/spec/lex.html#keywords import alias; C:\Users\Juozas\Desktop\om.d(2): Error: identifier expected following import C:\Users\Juozas\Desktop\om.d(2): Error: ; expected module abstract; C:\Users\Juozas\Desktop\commands\alias.d(1): Error: identifier expected following module
Re: Blog Post #0043 - File Dialog IX - Custom Dialogs (2 of 3)
On Tuesday, 11 June 2019 at 09:06:10 UTC, Ron Tarrant wrote: This is the second in a series (Custom Dialogs) within a series (Dialogs) and deals with the action area. It's available here: http://gtkdcoding.com/2019/06/11/0043-custom-dialog-ii.html Aw man, your content have. "© Copyright 2019 Ron Tarrant"
Re: Suggest aesthetic way to Naming a module or a package with illegal lexical D lang keywords
On Sunday, 16 June 2019 at 11:38:27 UTC, rikki cattermole wrote: The style guide has an opinion about this (you don't have to follow it). https://dlang.org/dstyle.html#naming_keywords So if I follow dstyle guidelines on keywords, this would be a correct non-conflicting result: module _auto._alias._abstract; void main(){ } The underscore way, I kind of liking it, thanks for sourcing the idea.
Suggest aesthetic way to Naming a module or a package with illegal lexical D lang keywords
Do not ask why I want to do that, you can however suggest alternative variations. As you all might know, 2. The Identifiers preceding the rightmost are the Packages that the module is in. The packages correspond to directory names in the source file path. Package and module names cannot be Keywords. https://dlang.org/spec/module.html#module_declaration The D Spec literally says that we cannot use these words in the Module Names: https://dlang.org/spec/lex.html#Keyword Example, we can't Name Modules or Packages like that: module auto.alias.abstract; void main(){ } I would like to know if there is any way to make it possible to name Modules/Packages via preoccupied lexical words, or at least receive some suggestions on some aesthetic naming for a module/package that includes these lexical d words. Examples: module dauto.dalias.dabstract; void main(){ } module CustomAuto.CustomAlias.CustomAbstract; void main(){ }
File Exception, Access is denied - prompting for administrator's rights
Hello everyone, I'm Windows 10 as of right now, I have this situation where I would like to update /hosts file, however sometimes I do not have the required permissions, since sometimes I forget to run the .d script with administrator's rights. Is there any way to prompt for administrator's rights, to save the additional effort of lots of clicks? import std.file; void main(){ append("C:/Windows/System32/drivers/etc/hosts", "hahaha"); } std.file.FileException@std\file.d(859): C:/Windows/System32/drivers/etc/hosts: Access is denied. 0x00404223 0x00402295 0x00403751 0x004035EB 0x00402DE7 0x75688494 in BaseThreadInitThunk 0x773741C8 in RtlAreBitsSet 0x77374198 in RtlAreBitsSet
Re: rdmd takes 2-3 seconds on a first-run of a simple .d script
On Tuesday, 28 May 2019 at 06:06:24 UTC, Seb wrote: On Tuesday, 28 May 2019 at 05:11:15 UTC, Andre Pany wrote: On Monday, 27 May 2019 at 07:16:37 UTC, BoQsc wrote: [...] I can confirm, without measuring the exact timing, "dmd -run test.d" feels much faster than "rdmd test.d". I would say 1 second instead of 2 seconds. Kind regards André Well, that's because rdmd is an old legacy tool that runs the compiler twice. Use dmd -i or rund (https://github.com/dragon-lang/rund). FOR WINDOWS OPERATING SYSTEMS ONLY Since I run simple D scripts a lot of time, as an experiment I molded a registry tweak that associate .d files with dmd compiler, with those options in combination: http://dlang.k3.1azy.net/dmd-windows.html#switch-i[ http://dlang.k3.1azy.net/dmd-windows.html#switch-run Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Applications\dmd.exe\shell\open\command] @="\"C:\\D\\dmd2\\windows\\bin\\dmd.exe\" \"-i\" \"-run\" \"%1\"" What this Registry Tweak does: Adds file association for .d file type, so that you can run a .d file by double clicking .d file. To use it: 1. create a simple empty text file 2. change its file extension from .txt to .reg 3. copy the above registry instructions into previously created file. 4. double click this newly created .reg file. 5. confirm that you want to apply these registry changes. Downsides I experienced by using dmd -i and -run switches: .obj and .exe file can be seen generated in the same folder as .d file script, while dmd is running your script. However, they are deleted after the .d script is finished running uninterupted. If dmd is interupted while processing .d script - by being terminated, .obj and .exe files might be left undeleted.
Re: rdmd takes 2-3 seconds on a first-run of a simple .d script
On Sunday, 26 May 2019 at 20:37:36 UTC, Jon Degenhardt wrote: On Saturday, 25 May 2019 at 22:18:16 UTC, Andre Pany wrote: On Saturday, 25 May 2019 at 08:32:08 UTC, BoQsc wrote: I have a simple standard .d script and I'm getting annoyed that it takes 2-3 seconds to run and see the results via rdmd. Also please keep in mind there could be other factors like slow disks, anti virus scanners,... which causes a slow down. I have seen similar behavior that I attribute to virus scan software. After compiling a program, the first run takes several seconds to run, after that it runs immediately. I'm assuming the first run of an unknown binary triggers a scan, though I cannot be completely sure. Try compiling a new binary in D or C++ and see if a similar effect is seen. --Jon The desktop computer I'm testing this on contains Solid State Drive, a Windows 10 Home Operating system and about 7-9 years old of hardware. But remember, we are living in a 21 century, the hardware performance is great, even for the old hardware that is 10 years old, especially the desktops. I tried to disable Windows Defender real-time protection, it didn't helped to speed up rdmd. However until I test it on Linux, I can't be sure if Windows do not have other less obvious quirks that could slow down third party programs such as D compiler or rdmd.
rdmd takes 2-3 seconds on a first-run of a simple .d script
rdmd is a companion to the dmd compiler that simplifies the typical edit-compile-link-run or edit-make-run cycle to a rapid edit-run cycle. Like make and other tools, rdmd uses the relative dates of the files involved to minimize the amount of work necessary. Unlike make, rdmd tracks dependencies and freshness without requiring additional information from the user. Source: https://dlang.org/rdmd.html I have a simple standard .d script and I'm getting annoyed that it takes 2-3 seconds to run and see the results via rdmd. This might sound like insanely laughable time to be annoyed by, but it is a enough of a problem for me to make a Thread in a D lang Forum. Every time I make a change to a script it takes at least 2 seconds on my computer for it to run, if you are beginner like me - you know it is not very pleasant to wait out that duration. I wonder if anything can be done about it, why it takes so "much" time, and why can't the results show up in a few milliseconds instead? #!/usr/bin/env rdmd import std.stdio, std.process; void main() { writeln("This writeln is taking long time "); executeShell("pause"); }
Why GNU coreutils/dd is creating a dummy file more efficiently than D's For loop?
This code of D creates a dummy 47,6 MB text file filled with Nul characters in about 9 seconds import std.stdio, std.process; void main() { writeln("Creating a dummy file"); File file = File("test.txt", "w"); for (int i = 0; i < 5000; i++) { file.write("\x00"); } file.close(); } While GNU coreutils dd can create 500mb dummy Nul file in a second. https://github.com/coreutils/coreutils/blob/master/src/dd.c What are the explanations for this?
Re: How to "Clear the Screen" for Windows Command Processor? (Windows 10)
On Tuesday, 21 May 2019 at 12:51:41 UTC, Adam D. Ruppe wrote: On Tuesday, 21 May 2019 at 07:16:29 UTC, Boqsc wrote: I'm getting unsure why executeShell works on the pause command, but cls that is responsible for clearing the text do not. When you ran pause, did it print the text "press any key to continue"? You are absolutely correct. There was no output, it was captured, as executeShell is used for capturing command output. auto commandOutput = executeShell("pause"); writeln("Here is the output: ", commandOutput); // Here is the output: Tuple!(int, "status", string, "output")(0, "Press any key to continue . . . \r\n") executeShell captures the output of the program, so I'm guessing no. And that is why cls does nothing - its output is captured into a string instead of displayed on screen. spawnShell keeps the output connected unless you ask it not to. http://dpldocs.info/experimental-docs/std.process.spawnShell.1.html Thanks for summarising.
Re: How to "Clear the Screen" for Windows Command Processor? (Windows 10)
On Tuesday, 21 May 2019 at 10:03:38 UTC, KnightMare wrote: try next: spawnShell( "cls" ).wait; Wow, spawnShell indeed does the job as I would expect, as of right now. Thanks. spawnShell Function indeed sounds like it would spawn a new shell instead of what it does, at first I didn't look into it very seriously while checking documentation. https://dlang.org/library/std/process/spawn_shell.html
How to "Clear the Screen" for Windows Command Processor? (Windows 10)
I'm getting unsure why executeShell works on the pause command, but cls that is responsible for clearing the text do not. import std.stdio, std.process; void main() { writeln("Some text that will appear in cmd"); executeShell("cls"); // Does not clear the text? executeShell("pause"); // Pauses the cmd.exe to keep from closing itself. }
Parsing URL, Extracting Authority from the URL string
I wonder if there is a simple way to extract Authority from an URL string. What is Authority of URL: https://en.wikipedia.org/wiki/URL#Syntax https://dlang.org/phobos/std_path.html I was able to gather the filename of URL via std.path package function: baseName. import std.stdio, std.path; void main() { string url = "https://github.com/BoQsc/notes/archive/master.zip;; // Output: url filename: master.zip writeln("url filename: ", url.baseName); // Output: url path: https://github.com/BoQsc/notes/archive writeln("url path: ", url.dirName); } However it seems that std.path lacks ability to extract Authority part that URL contains. https://dlang.org/phobos/std_path.html#rootName I tried std.path.rootName, but it didn't return Authority part of URL. import std.stdio, std.path; void main() { string url = "https://github.com/BoQsc/notes/archive/master.zip;; // Output: url path: writeln("url path: ", url.rootName); } I'm questioning, if D lang will ever include simple URL parsing into their std Phobos library?
Is using floating point type for money/currency a good idea?
https://dlang.org/spec/float.html I'm frozen in learning basics of D lang since I want to create a simple game and I really would like a clean and simple code, however to me floating points are magic. https://wiki.dlang.org/Review_Queue Since std.decimal is still work in progress and apparently its development is stuck for a while, should I just somehow use floating point to store currency or wait until Decimal package will be finally included into std Phobos of D lang?
Re: Why does D language do not support BigDecimal type?
On Tuesday, 12 March 2019 at 08:48:33 UTC, Cym13 wrote: On Monday, 11 March 2019 at 15:23:34 UTC, BoQsc wrote: There is Money datatype that can be provided by using a third party package: https://code.dlang.org/packages/money But that's only for money, what about math? Why such fundamental as BigDecimal is still not included into the D language itself? There is BigInt. If it is unavoidable to use Floating point, how can I quickly and simply understand the rules of using float to make the least error, or should I just find a third party package for that as well? There is an article on that, but it is not that straight forward: https://dlang.org/articles/d-floating-point.html Basically any thing that I find on Google, that include explaining floating point are badly written and hard to understand for the outsider lacking ability to understand advanced concepts. How much precision is enough in your use case? There's always a limit to how precise you need to be and how precise you can be, be it only because our memory is finite. I've never had a use case for BigDecimal myself, so forgive my ignorance, but wouldn't you get the exact same result by using BigInt? For example, if you need 20 decimals of precisions then any value times 10^20 will be a BigInt on which you can work, it's just a matter of displaying it correctly when outputing the result but it doesn't change the operations you have to perform. Is there anything that can't be done with BigInt really? Please attach quick working examples for every sentence you write or it's just a waste of time. People want to see the results and direct actions first before anything else, it's more efficient communication. We are in the subforum of Dlang learn, after all. Do not write "For Example". I'm interested in writing a simple game prototype and I imagine that I would like to include some item parts in decimal. (100.00) To keep everything simple I would like to make my code as clean and simple as possible. Floating points seems to require additional arithmetics - rounding and are inprecise when comparing. I do not want to deal with it every time. But if there is any standard simple documentation that I could include into my own game documentation to avoid confusion and make everything consisten, I would like to know. For now it seems that the only way to make it all simple is to use some kind of library to handle decimals for me, as I can't find any concise references on how to correctly use and understand floating points.
Why does D language do not support BigDecimal type?
There is Money datatype that can be provided by using a third party package: https://code.dlang.org/packages/money But that's only for money, what about math? Why such fundamental as BigDecimal is still not included into the D language itself? There is BigInt. If it is unavoidable to use Floating point, how can I quickly and simply understand the rules of using float to make the least error, or should I just find a third party package for that as well? There is an article on that, but it is not that straight forward: https://dlang.org/articles/d-floating-point.html Basically any thing that I find on Google, that include explaining floating point are badly written and hard to understand for the outsider lacking ability to understand advanced concepts.
Re: Executing a D script without an [extension in the filename] leads to an error
On Friday, 1 March 2019 at 09:27:33 UTC, Cym13 wrote: On Friday, 1 March 2019 at 09:00:43 UTC, BoQsc wrote: I've installed D compiler, and when i try to run a D script with filename without an extension/file type named: program via: ./program I'm getting and error: vaidas@SATELLITE-L855:~/Desktop$ ./program Error: module `program` is in file './program.d' which cannot be read import path[0] = . import path[1] = /snap/dmd/49/bin/../import/druntime import path[2] = /snap/dmd/49/bin/../import/phobos Failed: ["/snap/dmd/49/bin/dmd", "-v", "-o-", "./program.d", "-I."] Now, when I rename my scirpt file : program To: program.d and execute it by: ./program.d I no longer have an error. Is this an intended behaviour? In such questions it's important to show your shebang since that's what runs your script. Given your symptoms I guess you're using the following: #!/bin/env rdmd And indeed rdmd won't call your script if it doesn't have the proper extension. Try using this instead: #!/bin/dmd -run The shebang I used: #!/usr/bin/env rdmd I was visiting Dlang Tour and that's where I've got an example of shebang usage, directly from there: https://tour.dlang.org/tour/en/welcome/run-d-program-locally#/on-the-fly-compilation-with-rdmd The shebang you suggested actually works perfectly: #!/bin/dmd -run "And indeed rdmd won't call your script if it doesn't have the proper extension." Then why does Dlang Tour includes shebang: #!/usr/bin/env rdmd Instead of the one you mentioned, that is fool proof. (#!/bin/dmd -run) Is that an error/mistake in Dlang Tour guide?
Executing a D script without an [extension in the filename] leads to an error
I've installed D compiler, and when i try to run a D script with filename without an extension/file type named: program via: ./program I'm getting and error: vaidas@SATELLITE-L855:~/Desktop$ ./program Error: module `program` is in file './program.d' which cannot be read import path[0] = . import path[1] = /snap/dmd/49/bin/../import/druntime import path[2] = /snap/dmd/49/bin/../import/phobos Failed: ["/snap/dmd/49/bin/dmd", "-v", "-o-", "./program.d", "-I."] Now, when I rename my scirpt file : program To: program.d and execute it by: ./program.d I no longer have an error. Is this an intended behaviour?
Why The D Style constants are written in camelCase?
The D Style suggest to camelCase constants, while Java naming conventions always promoted uppercase letter. Is there an explanation why D Style chose to use camelCase instead of all UPPERCASE for constants, was there any technical problem that would appear while writing in all UPPERCASE? Java language references: https://en.wikipedia.org/wiki/Naming_convention_(programming)#Java https://www.javatpoint.com/java-naming-conventions http://www.oracle.com/technetwork/java/codeconventions-135099.html https://medium.com/modernnerd-code/java-for-humans-naming-conventions-6353a1cd21a1 D lang reference: https://dlang.org/dstyle.html#naming_constants
Re: "Start a Minimal web server" example do not work.
On Tuesday, 8 May 2018 at 19:19:26 UTC, Seb wrote: On Tuesday, 8 May 2018 at 18:40:34 UTC, BoQsc wrote: On Tuesday, 8 May 2018 at 18:38:10 UTC, BoQsc wrote: On Tuesday, 8 May 2018 at 17:35:13 UTC, Jesse Phillips wrote: [...] Tested with these versions so far, and had all the same errors: C:\Users\Vaidas>dmd --version DMD32 D Compiler v2.079.1 C:\Users\Vaidas>dub --version DUB version 1.8.1, built on Apr 14 2018 C:\Users\Vaidas>dmd --version DMD32 D Compiler v2.080.0 C:\Users\Vaidas>dub --version DUB version 1.9.0, built on May 1 2018 Linking... C:\D\dmd2\windows\bin\lld-link.exe: warning: eventcore.lib(sockets_106c_952.obj): undefined symbol: SetWindowLongPtrA C:\D\dmd2\windows\bin\lld-link.exe: warning: eventcore.lib(sockets_106c_952.obj): undefined symbol: GetWindowLongPtrA error: link failed Error: linker exited with status 1 C:\D\dmd2\windows\bin\dmd.exe failed with exit code 1. That's with DMD's bundled LLD linker. Have you tried: 1) installing MS Visual Studio (as others have mentioned their linker works) 2) Using LDC (they usually ship a newer version of the LLD linker) I have installed the one suggested by the dmd-2.080.0.exe installer: Microsoft Visual Studio Community 2017 Version 15.7.0 VisualStudio.15.Release/15.7.0+27703.1 Microsoft .NET Framework Version 4.7.02556 Installed Version: Community Mago Native Debug Engine 1.0.0 A debug engine dedicated to debugging applications written in the D programming language. See the project website at http://www.dsource.org/projects/mago_debugger for more information. Copyright (c) 2010-2014 Aldo J. Nunez ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info Visual D 0.46.0 Integration of the D Programming Language into Visual Studio
Re: "Start a Minimal web server" example do not work.
On Tuesday, 8 May 2018 at 18:38:10 UTC, BoQsc wrote: On Tuesday, 8 May 2018 at 17:35:13 UTC, Jesse Phillips wrote: On Tuesday, 8 May 2018 at 16:34:53 UTC, BoQsc wrote: On Tuesday, 8 May 2018 at 16:18:27 UTC, bachmeier wrote: On Tuesday, 8 May 2018 at 12:13:56 UTC, BoQsc wrote: This is the code example, that was presented on the https://dlang.org frontpage: Maybe that isn't the best choice of beginner example if even the D experts can't figure out how to get it to run. Might be a bug, I have already reported it and saw some bug duplicates like mine. However, since 2017 report, it seems to be - still not going well. If I have a chance I'll try to download latest dlang distribution and install on a completely clean Windows 10 Operating system. But I'm not hoping for any luck, but still in need of try trial. So I gave this a try and this command worked: >dub --arch=x86_64 --single start_minimal_server.d I'm on Windows 8 with All the visual studio versions installed DMD32 D Compiler v2.080.0-beta.1 DUB version 1.9.0-beta.1, built on Apr 17 2018 Tested with these versions so far, and had all the same errors: C:\Users\Vaidas>dmd --version DMD32 D Compiler v2.079.1 C:\Users\Vaidas>dub --version DUB version 1.8.1, built on Apr 14 2018 C:\Users\Vaidas>dmd --version DMD32 D Compiler v2.080.0 C:\Users\Vaidas>dub --version DUB version 1.9.0, built on May 1 2018 Linking... C:\D\dmd2\windows\bin\lld-link.exe: warning: eventcore.lib(sockets_106c_952.obj): undefined symbol: SetWindowLongPtrA C:\D\dmd2\windows\bin\lld-link.exe: warning: eventcore.lib(sockets_106c_952.obj): undefined symbol: GetWindowLongPtrA error: link failed Error: linker exited with status 1 C:\D\dmd2\windows\bin\dmd.exe failed with exit code 1.
Re: "Start a Minimal web server" example do not work.
On Tuesday, 8 May 2018 at 17:35:13 UTC, Jesse Phillips wrote: On Tuesday, 8 May 2018 at 16:34:53 UTC, BoQsc wrote: On Tuesday, 8 May 2018 at 16:18:27 UTC, bachmeier wrote: On Tuesday, 8 May 2018 at 12:13:56 UTC, BoQsc wrote: This is the code example, that was presented on the https://dlang.org frontpage: Maybe that isn't the best choice of beginner example if even the D experts can't figure out how to get it to run. Might be a bug, I have already reported it and saw some bug duplicates like mine. However, since 2017 report, it seems to be - still not going well. If I have a chance I'll try to download latest dlang distribution and install on a completely clean Windows 10 Operating system. But I'm not hoping for any luck, but still in need of try trial. So I gave this a try and this command worked: >dub --arch=x86_64 --single start_minimal_server.d I'm on Windows 8 with All the visual studio versions installed DMD32 D Compiler v2.080.0-beta.1 DUB version 1.9.0-beta.1, built on Apr 17 2018 Tested with these versions so far, and had all the same errors: C:\Users\Vaidas>dmd --version DMD32 D Compiler v2.079.1 C:\Users\Vaidas>dub --version DUB version 1.8.1, built on Apr 14 2018 C:\Users\Vaidas>dmd --version DMD32 D Compiler v2.080.0 C:\Users\Vaidas>dub --version DUB version 1.9.0, built on May 1 2018
Re: "Start a Minimal web server" example do not work.
On Tuesday, 8 May 2018 at 16:18:27 UTC, bachmeier wrote: On Tuesday, 8 May 2018 at 12:13:56 UTC, BoQsc wrote: This is the code example, that was presented on the https://dlang.org frontpage: Maybe that isn't the best choice of beginner example if even the D experts can't figure out how to get it to run. Might be a bug, I have already reported it and saw some bug duplicates like mine. However, since 2017 report, it seems to be - still not going well. If I have a chance I'll try to download latest dlang distribution and install on a completely clean Windows 10 Operating system. But I'm not hoping for any luck, but still in need of try trial.
Re: "Start a Minimal web server" example do not work.
On Tuesday, 8 May 2018 at 16:02:02 UTC, rjframe wrote: On Tue, 08 May 2018 13:23:07 +, BoQsc wrote: On Tuesday, 8 May 2018 at 13:04:12 UTC, Seb wrote: Did you try the newer MSCOFF format dub --arch=x86_mscoff start_minimum_server.d or dub --arch=x64 start_minimum_server.d C:\Users\Vaidas\Desktop>dub --arch=x86_mscoff start_minimum_server.d Failed to find a package named 'start_minimum_server.d'. C:\Users\Vaidas\Desktop>dub --arch=x64 start_minimum_server.d Unsupported architecture: x64 Try the 64-bit build as "--arch=x86_64"; dub doesn't recognize x64 (at least on Windows). dub --arch=x86_64 --single start_minimum_server.d For your first attempt above, adding the --single flag might work. --Ryan C:\Users\Vaidas\Desktop>dub --arch=x86_64 --single start_minimum_server.d Performing "debug" build using C:\D\dmd2\windows\bin\dmd.exe for x86_64. taggedalgebraic 0.10.11: building configuration "library"... eventcore 0.8.34: building configuration "winapi"... stdx-allocator 2.77.1: building configuration "library"... vibe-core 1.4.0: building configuration "winapi"... vibe-d:utils 0.8.3: building configuration "library"... vibe-d:data 0.8.3: building configuration "library"... vibe-d:crypto 0.8.3: building configuration "library"... diet-ng 1.4.5: building configuration "library"... vibe-d:stream 0.8.3: building configuration "library"... vibe-d:textfilter 0.8.3: building configuration "library"... vibe-d:inet 0.8.3: building configuration "library"... vibe-d:tls 0.8.3: building configuration "openssl-mscoff"... vibe-d:http 0.8.3: building configuration "library"... vibe-d:mail 0.8.3: building configuration "library"... vibe-d:mongodb 0.8.3: building configuration "library"... vibe-d:redis 0.8.3: building configuration "library"... vibe-d:web 0.8.3: building configuration "library"... vibe-d 0.8.3: building configuration "vibe-core"... hello_vibed ~master: building configuration "application"... Linking... C:\D\dmd2\windows\bin\lld-link.exe: warning: eventcore.lib(sockets_1034_952.obj): undefined symbol: SetWindowLongPtrA C:\D\dmd2\windows\bin\lld-link.exe: warning: eventcore.lib(sockets_1034_952.obj): undefined symbol: GetWindowLongPtrA error: link failed Error: linker exited with status 1 C:\D\dmd2\windows\bin\dmd.exe failed with exit code 1. C:\Users\Vaidas\Desktop>
Re: "Start a Minimal web server" example do not work.
On Tuesday, 8 May 2018 at 13:33:51 UTC, drug wrote: 08.05.2018 16:23, BoQsc пишет: On Tuesday, 8 May 2018 at 13:04:12 UTC, Seb wrote: On Tuesday, 8 May 2018 at 12:37:42 UTC, BoQsc wrote: On Tuesday, 8 May 2018 at 12:19:14 UTC, Adam D. Ruppe wrote: On Tuesday, 8 May 2018 at 12:13:56 UTC, BoQsc wrote: [...] This one needs to be compiled+run with the dub package manager instead of with rdmd, which is why it has that shebang line. It has external library dependencies rdmd can't handle. My intuition now says to use dub this way: -- C:\Users\Vaidas\Desktop>dub start_minimum_server.d EC:\D\dmd2\windows\bin\dmd.exe failed with exit code 1. And got an error: Unexpected OPTLINK Termination at EIP=0040F60A EAX=06CB EBX=00438C70 ECX=02C2 EDX=030D ESI=00257000 EDI=06CB34F8 EBP=0019FF38 ESP=0019FEF0 First=00402000 Similar to this one: https://issues.dlang.org/show_bug.cgi?id=18799 Did you try the newer MSCOFF format dub --arch=x86_mscoff start_minimum_server.d or dub --arch=x64 start_minimum_server.d C:\Users\Vaidas\Desktop>dub --arch=x86_mscoff start_minimum_server.d Failed to find a package named 'start_minimum_server.d'. C:\Users\Vaidas\Desktop>dub --arch=x64 start_minimum_server.d Unsupported architecture: x64 didn't you forget `--single` option? ``` dub --arch=x64 --single start_minimum_server.d ``` C:\Users\Vaidas\Desktop>dub --arch=x86_mscoff --single start_minimum_server.d Performing "debug" build using C:\D\dmd2\windows\bin\dmd.exe for x86, x86_mscoff. taggedalgebraic 0.10.11: building configuration "library"... eventcore 0.8.34: building configuration "winapi"... stdx-allocator 2.77.1: building configuration "library"... vibe-core 1.4.0: building configuration "winapi"... vibe-d:utils 0.8.3: building configuration "library"... vibe-d:data 0.8.3: building configuration "library"... vibe-d:crypto 0.8.3: building configuration "library"... diet-ng 1.4.5: building configuration "library"... vibe-d:stream 0.8.3: building configuration "library"... vibe-d:textfilter 0.8.3: building configuration "library"... vibe-d:inet 0.8.3: building configuration "library"... vibe-d:tls 0.8.3: building configuration "openssl-mscoff"... vibe-d:http 0.8.3: building configuration "library"... vibe-d:mail 0.8.3: building configuration "library"... vibe-d:mongodb 0.8.3: building configuration "library"... vibe-d:redis 0.8.3: building configuration "library"... vibe-d:web 0.8.3: building configuration "library"... vibe-d 0.8.3: building configuration "vibe-core"... hello_vibed ~master: building configuration "application"... Linking... C:\D\dmd2\windows\bin\lld-link.exe: warning: phobos32mscoff.lib(crc32.obj): undefined symbol: __allshr error: link failed Error: linker exited with status 1 C:\D\dmd2\windows\bin\dmd.exe failed with exit code 1. C:\Users\Vaidas\Desktop>
Re: "Start a Minimal web server" example do not work.
On Tuesday, 8 May 2018 at 13:04:12 UTC, Seb wrote: On Tuesday, 8 May 2018 at 12:37:42 UTC, BoQsc wrote: On Tuesday, 8 May 2018 at 12:19:14 UTC, Adam D. Ruppe wrote: On Tuesday, 8 May 2018 at 12:13:56 UTC, BoQsc wrote: [...] This one needs to be compiled+run with the dub package manager instead of with rdmd, which is why it has that shebang line. It has external library dependencies rdmd can't handle. My intuition now says to use dub this way: -- C:\Users\Vaidas\Desktop>dub start_minimum_server.d EC:\D\dmd2\windows\bin\dmd.exe failed with exit code 1. And got an error: Unexpected OPTLINK Termination at EIP=0040F60A EAX=06CB EBX=00438C70 ECX=02C2 EDX=030D ESI=00257000 EDI=06CB34F8 EBP=0019FF38 ESP=0019FEF0 First=00402000 Similar to this one: https://issues.dlang.org/show_bug.cgi?id=18799 Did you try the newer MSCOFF format dub --arch=x86_mscoff start_minimum_server.d or dub --arch=x64 start_minimum_server.d C:\Users\Vaidas\Desktop>dub --arch=x86_mscoff start_minimum_server.d Failed to find a package named 'start_minimum_server.d'. C:\Users\Vaidas\Desktop>dub --arch=x64 start_minimum_server.d Unsupported architecture: x64
Re: "Start a Minimal web server" example do not work.
On Tuesday, 8 May 2018 at 12:19:14 UTC, Adam D. Ruppe wrote: On Tuesday, 8 May 2018 at 12:13:56 UTC, BoQsc wrote: This is the code example, that was presented on the https://dlang.org frontpage: - #!/usr/bin/env dub This one needs to be compiled+run with the dub package manager instead of with rdmd, which is why it has that shebang line. It has external library dependencies rdmd can't handle. My intuition now says to use dub this way: -- C:\Users\Vaidas\Desktop>dub start_minimum_server.d EC:\D\dmd2\windows\bin\dmd.exe failed with exit code 1. And got an error: Unexpected OPTLINK Termination at EIP=0040F60A EAX=06CB EBX=00438C70 ECX=02C2 EDX=030D ESI=00257000 EDI=06CB34F8 EBP=0019FF38 ESP=0019FEF0 First=00402000 Similar to this one: https://issues.dlang.org/show_bug.cgi?id=18799
"Start a Minimal web server" example do not work.
This is the code example, that was presented on the https://dlang.org frontpage: - #!/usr/bin/env dub /+ dub.sdl: name "hello_vibed" dependency "vibe-d" version="~>0.8.0" +/ void main() { import vibe.d; listenHTTP(":8080", (req, res) { res.writeBody("Hello, World: " ~ req.path); }); runApplication(); } - I have copied this example code into start_minimum_server.d file. Ran it as script with rdmd.exe And got an output: -- C:\Users\Vaidas\Desktop>rdmd start_minimum_server.d start_minimum_server.d(8): Error: module `d` is in file 'vibe\d.d' which cannot be read import path[0] = . import path[1] = C:\D\dmd2\windows\bin\..\..\src\phobos import path[2] = C:\D\dmd2\windows\bin\..\..\src\druntime\import Failed: ["dmd", "-v", "-o-", "start_minimum_server.d", "-I."] --
Re: Making an .exe that executes source file inside itself.
On Friday, 27 April 2018 at 04:30:32 UTC, IntegratedDimensions wrote: On Thursday, 26 April 2018 at 06:18:25 UTC, BoQsc wrote: On Wednesday, 25 April 2018 at 20:44:10 UTC, u0_a183 wrote: On Wednesday, 25 April 2018 at 19:54:26 UTC, BoQsc wrote: On Wednesday, 25 April 2018 at 19:43:31 UTC, Jonathan M Davis wrote: [...] Thank you Jonathan for a response. I was aware of this, and it certainly perfectly works where command line/terminal interface is the main tool to control the system, a good example would be linux/gnu distributions and macOS. However in Windows while installing D language, I noticed that .d source file extension is not associated with neither D compiler (dmd.exe) nor D script interpretator (rdmd.exe) So they can't be ran directly by clicking on those, nor they have any icons that show that these source codes are actually executable. This is a huge problem, because people that are not aware of D language migh be harder to understand that source script could be executable, at least - without help from some more experienced user. If the purpose is to make scripts run by clicking them you can assign a file type to .d files. On Windows 10. https://www.digitaltrends.com/computing/how-to-set-default-programs-and-file-types-in-windows-10/ Doing so would make the script engine the default program instead of a text editor so you might not want to. Or maybe assign .dxe and changing the filename before running. Executable has executable file type for a reason - it self-implies that the main function of the file - is to be executed. The problem with making source code files executable is that, source code files, might not always be monolithic executable code, but a part of a bigger interconnected program. That would lead to partily working program execution, and most of the times guess work of whether source code file was supposed to be executed. This is wrong. All code must be included. All library source code is included. If this is infeasible then simply the binaries are included. It would be no different than dynamic linking that already exists. It doesn't create any new problems. Sure certain things would need to be worked out properly to optimize the experience, but that is obvious. One can't make everything perfect though and one shouldn't expect it... The clear alternative would be: .exe file on which, if rightclicked - would open context menu showing posibility of "edit/improve this executable". Which would not create additional problem mentioned above. Yes, all the source code and required source code to make everything work must be included. And where would all the code mentioned before should be stored? It must be stored in a an single self extracting archive, self executing archive, that is self-implying that it is an executable code, which means it can't be .d file extension, but an .exe file extension. (or any other, if anyone come up with more common or self explaining extension name) If we use the same .d file extension on this self-exectuable, self-extracting archive, it would confused people weather it is executable or some novice programmer's written module/script.
Re: Making an .exe that executes source file inside itself.
On Wednesday, 25 April 2018 at 20:44:10 UTC, u0_a183 wrote: On Wednesday, 25 April 2018 at 19:54:26 UTC, BoQsc wrote: On Wednesday, 25 April 2018 at 19:43:31 UTC, Jonathan M Davis wrote: On Wednesday, April 25, 2018 19:19:58 BoQsc via Digitalmars-d-learn wrote: So there has been idea I've got for around few months now: making a software which executable would contain a source file. A software that anyone could modify by opening an executable and quickly change a few lines of it, rerun an executable, see the changes. Could this be easily possible with D language, considering that sources files can be ran without long slow compilation process? The normal way to do that is to just write a script. In the case of D, you can just use rdmd to do it. e.g. if you're on a POSIX system, just put #!/usr/bin/env rdmd at the top of your .d file and chmod it so that it's executable, and it'll run like any other script. - Jonathan M Davis Thank you Jonathan for a response. I was aware of this, and it certainly perfectly works where command line/terminal interface is the main tool to control the system, a good example would be linux/gnu distributions and macOS. However in Windows while installing D language, I noticed that .d source file extension is not associated with neither D compiler (dmd.exe) nor D script interpretator (rdmd.exe) So they can't be ran directly by clicking on those, nor they have any icons that show that these source codes are actually executable. This is a huge problem, because people that are not aware of D language migh be harder to understand that source script could be executable, at least - without help from some more experienced user. If the purpose is to make scripts run by clicking them you can assign a file type to .d files. On Windows 10. https://www.digitaltrends.com/computing/how-to-set-default-programs-and-file-types-in-windows-10/ Doing so would make the script engine the default program instead of a text editor so you might not want to. Or maybe assign .dxe and changing the filename before running. Executable has executable file type for a reason - it self-implies that the main function of the file - is to be executed. The problem with making source code files executable is that, source code files, might not always be monolithic executable code, but a part of a bigger interconnected program. That would lead to partily working program execution, and most of the times guess work of whether source code file was supposed to be executed. The clear alternative would be: .exe file on which, if rightclicked - would open context menu showing posibility of "edit/improve this executable". Which would not create additional problem mentioned above.
Re: Making an .exe that executes source file inside itself.
On Wednesday, 25 April 2018 at 19:43:31 UTC, Jonathan M Davis wrote: On Wednesday, April 25, 2018 19:19:58 BoQsc via Digitalmars-d-learn wrote: So there has been idea I've got for around few months now: making a software which executable would contain a source file. A software that anyone could modify by opening an executable and quickly change a few lines of it, rerun an executable, see the changes. Could this be easily possible with D language, considering that sources files can be ran without long slow compilation process? The normal way to do that is to just write a script. In the case of D, you can just use rdmd to do it. e.g. if you're on a POSIX system, just put #!/usr/bin/env rdmd at the top of your .d file and chmod it so that it's executable, and it'll run like any other script. - Jonathan M Davis Thank you Jonathan for a response. I was aware of this, and it certainly perfectly works where command line/terminal interface is the main tool to control the system, a good example would be linux/gnu distributions and macOS. However in Windows while installing D language, I noticed that .d source file extension is not associated with neither D compiler (dmd.exe) nor D script interpretator (rdmd.exe) So they can't be ran directly by clicking on those, nor they have any icons that show that these source codes are actually executable. This is a huge problem, because people that are not aware of D language migh be harder to understand that source script could be executable, at least - without help from some more experienced user.
Making an .exe that executes source file inside itself.
So there has been idea I've got for around few months now: making a software which executable would contain a source file. A software that anyone could modify by opening an executable and quickly change a few lines of it, rerun an executable, see the changes. Could this be easily possible with D language, considering that sources files can be ran without long slow compilation process?