Re: What's dxml DOMEntity(R) type ?
On Monday, 5 June 2023 at 10:43:27 UTC, Ferhat Kurtulmuş wrote: On Monday, 5 June 2023 at 10:01:01 UTC, John Xu wrote: The parseDOM returns a DOMEntity(R) type, how do I write a xmlRoot as global variable? I need its detailed type (auto / Variant doesn't work). import dxml.dom; ?? xmlRoot; int main() { string xml = readText("a.xml"); auto dom = parseDOM(xml); xmlRoot = dom.children[0]; } ```d import dxml.dom; import std.stdio; DOMEntity!string xmlRoot; int main() { string xml = ""; auto dom = parseDOM(xml); writeln(typeof(dom.children[0]).stringof); // yields "DOMEntity!string" xmlRoot = dom.children[0]; return 0; } ``` Thanks, that's very helpful. D sometimes drives me crazy, screws up my brain, :-)
What's dxml DOMEntity(R) type ?
The parseDOM returns a DOMEntity(R) type, how do I write a xmlRoot as global variable? I need its detailed type (auto / Variant doesn't work). import dxml.dom; ?? xmlRoot; int main() { string xml = readText("a.xml"); auto dom = parseDOM(xml); xmlRoot = dom.children[0]; }
Re: How get struct value by member name string ?
A correction: string getTMember(T t, string columnName) { foreach(member; __traits(allMembers, T)){ if (member == columnName) { return __traits(getMember, t, member).to!string; } } return ""; }
Re: How get struct value by member name string ?
On Thursday, 1 June 2023 at 15:38:08 UTC, Steven Schveighoffer wrote: On 5/31/23 12:08 AM, John Xu wrote: When render vibe.d diet template, string[] allMembers = __traits(allMembers, t); enum allMembers = __traits(allMembers, t); res.render!("index.dt", t, allMembers) if I don't want write memberName one by one in diet template: table - foreach(memberName; allMembers) tr td #{memberName} td #{getTMember!memberName(t)} Problem: memberName is not known at compile time. The problem is that you stored the member name list as a runtime variable, and that is not known at compile time. Try the enum. Or really, just `foreach(memberName; __traits(allMembers, t))` right in the diet template. -Steve Ok, thanks for all you gentlemen's help. I tried following function, now it works like C/C++/Python way: string getTMember(T t, string columnName) { foreach(member; __traits(allMembers, T)){ if (member == columnName) { return __traits(getMember, mcu, member).to!string; } } return ""; }
Re: How get struct value by member name string ?
On Tuesday, 30 May 2023 at 15:43:12 UTC, Steven Schveighoffer wrote: On 5/30/23 4:46 AM, John Xu wrote: How to put above enum as a function parameter? Following code wouldn't work: string getTMember(T t, enum string memberName) { return __traits(getMember, t, memberName); } compile time parameters come before runtime parameters: ```d string getTMember(string memberName)(T t) { return __traits(getMember, t, memberName); } // used like auto v = getTMember!"name"(t); ``` -Steve When render vibe.d diet template, string[] allMembers = __traits(allMembers, t); res.render!("index.dt", t, allMembers) if I don't want write memberName one by one in diet template: table - foreach(memberName; allMembers) tr td #{memberName} td #{getTMember!memberName(t)} Problem: memberName is not known at compile time.
Re: How get struct value by member name string ?
On Tuesday, 30 May 2023 at 01:33:54 UTC, H. S. Teoh wrote: On Tue, May 30, 2023 at 01:24:46AM +, John Xu via Digitalmars-d-learn wrote: On Monday, 29 May 2023 at 11:21:11 UTC, Adam D Ruppe wrote: > On Monday, 29 May 2023 at 09:35:11 UTC, John Xu wrote: > > Error: variable `column` cannot be read at compile time > > you should generally getMember on a variable > > T t; > __traits(getMember, t, "name") > > like that, that's as if you wrote t.name It seems I can't use variable as member name: struct T {int a; string name;} T t; string s = "name"; writeln(__traits(getMember, t, s)); Above code fails to compile. Any help? Short answer: `s` must be known at compile-time. Or more precisely, known at the time of template expansion. In this case, use `enum`: enum s = "name"; Long answer: https://wiki.dlang.org/Compile-time_vs._compile-time T How to put above enum as a function parameter? Following code wouldn't work: string getTMember(T t, enum string memberName) { return __traits(getMember, t, memberName); } My database table is very wide, with many columns. Above ddbc allows a struct to map db returned data. Then if I want a member's value to show in vibe.d template, how do I use a function to get it?
Re: How get struct value by member name string ?
On Monday, 29 May 2023 at 11:21:11 UTC, Adam D Ruppe wrote: On Monday, 29 May 2023 at 09:35:11 UTC, John Xu wrote: Error: variable `column` cannot be read at compile time you should generally getMember on a variable T t; __traits(getMember, t, "name") like that, that's as if you wrote t.name It seems I can't use variable as member name: struct T {int a; string name;} T t; string s = "name"; writeln(__traits(getMember, t, s)); Above code fails to compile. Any help?
How get struct value by member name string ?
I saw ddbc (https://github.com/buggins/ddbc/blob/master/source/ddbc/pods.d) uses static if (__traits(compiles, (typeof(__traits(getMember, T, m) { __traits(getMember, T, m) } But for my experience, above code sometimes/somewhere works, sometimes/somewhere just doesn't: Error: variable `column` cannot be read at compile time Is there any friend can explain some more details?
How hide console in dub.sdl under windows 11?
For dmd, I can use a no_console.def file, which has: EXETYPE NT SUBSYSTEM WINDOWS Then `dmd my.d no_console.def` to hide console. But how do I realize it with dub.sdl ? Adding no_console.def to "sourceFiles", doesn't help.
Best way to convert between GBK/GB18030 to utf8 ?
What is the best way to convert a GBK/GB18030 file contents, i.e. read via: std.stdio.read(gbkFile).to!string , to utf8 encoding ?
Re: Can dmd compile a favicon.ico to exe file ?
On Friday, 19 May 2023 at 21:19:07 UTC, Richard (Rikki) Andrew Cattermole wrote: On 19/05/2023 9:39 PM, John Xu wrote: On Thursday, 18 May 2023 at 15:39:05 UTC, Richard (Rikki) Andrew Cattermole wrote: On 19/05/2023 2:19 AM, John Xu wrote: On Monday, 15 May 2023 at 03:54:03 UTC, Richard (Rikki) Andrew Cattermole wrote: That is only for OMF target. You need rc that comes with Visual Studio C++ build tools. Alternatively windres from mingw may work (I haven't tested). How can I add this step to dub.sdl ? You would use one of the build commands and then put the result file name into source files. However you may not want to require it in normal builds (since the file it outputs won't change you can just commit that) just to ensure your build is reproducible. sourceFiles ? or libFiles ? sourceFiles. libFiles is for shared libraries. When I put resource.rc in sourceFiles, dub said, "Error: unrecognized file extension rc"; When I put resource.res in sourceFiles, dub said,"resource.res : fatal error LNK1136: Invalid or damaged file. Error: linker exited with status 1136"
Re: Can dmd compile a favicon.ico to exe file ?
On Thursday, 18 May 2023 at 15:39:05 UTC, Richard (Rikki) Andrew Cattermole wrote: On 19/05/2023 2:19 AM, John Xu wrote: On Monday, 15 May 2023 at 03:54:03 UTC, Richard (Rikki) Andrew Cattermole wrote: That is only for OMF target. You need rc that comes with Visual Studio C++ build tools. Alternatively windres from mingw may work (I haven't tested). How can I add this step to dub.sdl ? You would use one of the build commands and then put the result file name into source files. However you may not want to require it in normal builds (since the file it outputs won't change you can just commit that) just to ensure your build is reproducible. sourceFiles ? or libFiles ?
Re: Can dmd compile a favicon.ico to exe file ?
On Monday, 15 May 2023 at 03:54:03 UTC, Richard (Rikki) Andrew Cattermole wrote: That is only for OMF target. You need rc that comes with Visual Studio C++ build tools. Alternatively windres from mingw may work (I haven't tested). How can I add this step to dub.sdl ?
Re: Where can I find D jobs?
On Saturday, 29 April 2023 at 00:31:21 UTC, Neto wrote: On Saturday, 29 April 2023 at 00:29:28 UTC, Neto wrote: I'm thinking in moving from freelancer to some company, but I'd like to use D. Are there any companies hiring where D is used? note: hire without a degree. and remote. I received emails from turing.com before, about remote jobs. But I never tried their real service.0
Re: Can dmd compile a favicon.ico to exe file ?
On Monday, 15 May 2023 at 02:45:17 UTC, John Xu wrote: Found a related link: https://forum.dlang.org/thread/wogdypudrmrgwjysf...@forum.dlang.org Where Adam D Ruppe informed rcc.exe from http://ftp.digitalmars.com/bup.zip ... Any help? My isp.ico was converted from a png with gimp, used in C# programs before, shouldn't have any problem. Searched bing.com about "Windows 3.0 icon", bing didn't give much info. I figured out that the rcc on ftp.digitalmars.com only supports 8-bit non-compressed icon format. We'll need a newer rcc.exe which can support 24-bit/32-bit/compressed-contents icon format.
Re: Can dmd compile a favicon.ico to exe file ?
Found a related link: https://forum.dlang.org/thread/wogdypudrmrgwjysf...@forum.dlang.org Where Adam D Ruppe informed rcc.exe from http://ftp.digitalmars.com/bup.zip But, I got problem: rcc -r .\resource.rc IDI_ICON1 ICON DISCARDABLE "isp.ico" ^ .\resource.rc(1) : Error: 'isp.ico' doesn't contain a valid Windows 3.0 icon resourc Any help? My isp.ico was converted from a png with gimp, used in C# programs before, shouldn't have any problem. Searched bing.com about "Windows 3.0 icon", bing didn't give much info.
Re: Can dmd compile a favicon.ico to exe file ?
On Friday, 12 May 2023 at 02:09:17 UTC, ryuukk_ wrote: create a ``ressource.rc`` file and paste: ``` IDI_ICON1 ICON DISCARDABLE "myicon.ico" ``` then put your ``mycon.ico`` file next to it ``` my_project\ app.d ressource.rc myicon.ico ``` ``` dmd app.d ressource.rc Thanks for your quick reply. I'll give a try.
Can dmd compile a favicon.ico to exe file ?
I saw c# program's exe, often have an favicon.ico image bound together, which can be dragged to desktop. Can dmd compile an icon image to an exe also?
Re: Any working REPL program on windows? DREPL doesn't compile
On Thursday, 23 March 2023 at 13:27:00 UTC, jmh530 wrote: I've composed a simple gui, partially solved my problem: to compile/test simple codes quickly: https://github.com/xucs007/dln
Any working REPL program on windows? DREPL doesn't compile
Anybody know any working REPL program? I failed to find a working one. https://github.com/dlang-community/drepl can't compile on my Windows 10, dub reports: src\drepl\engines\dmd.d(258,16): Error: undefined identifier `dlsym`
How to expand wildchar under dos ?
Under dos, how to get wildchar matched file names? PS E:> dmd a.d PS E:> .\a.exe a.* args=["a.exe", "a.*"] d-glob doesn't function well under windows dos either.
Re: Best way to read/write Chinese (GBK/GB18030) files?
I found this: https://github.com/meatatt/exCode/blob/master/source/excode/package.d There is mention of unicode/GBK conversion, maybe it could be helpful Thanks for quick answers. Now I found I can read both UTF8 and UTF-16LE chinese file: string txt = std.file.read(chineseFile).to!string; and write to UTF8 file: std.file.write(utf8ChineseFile, txt); But still need figure out how to read/write GBK directly.
Best way to read/write Chinese (GBK/GB18030) files?
I'm new to dlang. I didn't find much tutorials on internet about how to read/write Chinese easily. std.encoding doesn't seem to support GBK or GB18030: "Encodings currently supported are UTF-8, UTF-16, UTF-32, ASCII, ISO-8859-1 (also known as LATIN-1), ISO-8859-2 (LATIN-2), WINDOWS-1250, WINDOWS-1251 and WINDOWS-1252." Then what is best way to read GBK/GB18030 contents ? Even GBK/GB18030 file names ?