Re: Disable wrilten buf in docker
On Tuesday, 12 March 2024 at 15:44:08 UTC, Steven Schveighoffer wrote: On Tuesday, 12 March 2024 at 06:36:09 UTC, zoujiaqing wrote: Hi, my application use writeln in docker don't display. Python add -u disable it. https://stackoverflow.com/questions/29663459/why-doesnt-python-app-print-anything-when-run-in-a-detached-docker-container Use setvbuf to switch to line buffering. Then you don’t have to manually flush everything https://en.cppreference.com/w/c/io/setvbuf -Steve Thank you Steve! how to use it in global?
Re: The std.file rename method fails in the docker environment.
On Wednesday, 13 March 2024 at 22:16:13 UTC, Sergey wrote: On Wednesday, 13 March 2024 at 21:49:55 UTC, zoujiaqing wrote: this is bug in D. It seems like a bug in Hunt-framework. And Hunt - is an abandoned project. Hunt Framework call std.file rename function. but this function can't move file from docker container to host machine.
Re: The std.file rename method fails in the docker environment.
On Wednesday, 13 March 2024 at 21:21:21 UTC, Jonathan M Davis wrote: On Wednesday, March 13, 2024 3:03:30 PM MDT zoujiaqing via Digitalmars-d-learn wrote: upload file to server in docker, but upload directory volume to host machine. Exception error: ``` Invalid cross-device link ``` Have other function like move(a, b) ? https://github.com/huntlabs/hunt-framework/blob/master/source/hunt/framework /file/File.d#L102 Well, the subject of your post mentions std.file, and then you link to a framework that does basically the same thing. So, I don't know what you're actually using. However, both of those functions use the OS function, rename, which renames the file within a file system, but it can't move files across file systems. Strictly speaking, it's not possible to move a file across file systems. What a program like mv does when the destination is on a different file system from the source file is copy the file and then delete the original. So, if you want to "move" a file across file systems within your program, you'll have to do the same thing. There may be a projcet on code.dlang.org which has a function which tries to move the file within the file system and then does a copy and remove instead if moving within the file system doesn't work, but otherwise, you'll have to implement that yourself, which could be as simple as catching the any exceptions from move and then attempting to copy the file and then remove it if an exception was thrown. - Jonathan M Davis this is bug in D. Docker run app code: ```d reanme("/tmp/aaa", "/data/attachments/aaa"); ``` docker volume path: ```txt VOLUME /data/attachments ``` docker compose yml: ```yml volumes: - /data/attachments:/data/attachments ``` Error exception: ``` Invalid cross-device link ```
The std.file rename method fails in the docker environment.
upload file to server in docker, but upload directory volume to host machine. Exception error: ``` Invalid cross-device link ``` Have other function like move(a, b) ? https://github.com/huntlabs/hunt-framework/blob/master/source/hunt/framework/file/File.d#L102
Re: Disable wrilten buf in docker
On Tuesday, 12 March 2024 at 06:39:40 UTC, Richard (Rikki) Andrew Cattermole wrote: On D's side you can use ``stdout.flush;`` to force it to flush. I don't think there is a way to force flushing via CLI. OK, thank you! Problem solved! Use code: ```D std.stdio.stdout.flush(); ```
Disable wrilten buf in docker
Hi, my application use writeln in docker don't display. Python add -u disable it. https://stackoverflow.com/questions/29663459/why-doesnt-python-app-print-anything-when-run-in-a-detached-docker-container
How to use eventcore write an echo server?
I use eventcore latest version write an echo server for test. some error of build. my D code: ```D import eventcore.core; import std.functional : toDelegate; import std.socket : InternetAddress; import std.exception : enforce; import core.time : Duration; import std.stdio : writeln; void main() { auto addr = new InternetAddress("127.0.0.1", ); auto listener = eventDriver.sockets.listenStream(addr, toDelegate(&onClientConnect)); enforce(listener != StreamListenSocketFD.invalid, "Failed to listen for connections."); writeln("Listening for requests on port ..."); while (eventDriver.core.waiterCount) eventDriver.core.processEvents(Duration.max); } void onClientConnect(StreamListenSocketFD listener, StreamSocketFD client, scope RefAddress) { Connection connection = new Connection(client); // Send welcome message to client connection.write("Welcome to use my echo server."); } class Connection { StreamSocketFD client; ubyte[1024] buf = void; this(StreamSocketFD client) { this.client = client; eventDriver.sockets.read(client, buf, IOMode.once, &onRead); } void write(ubyte[] data) { eventDriver.sockets.write(client, data, IOMode.all, &onWriteFinished); } void onWriteFinished(StreamSocketFD fd, IOStatus status, size_t len) { writeln("Send size: ", len); } void onRead(StreamSocketFD, IOStatus status, size_t bytes_read) { if (status != IOStatus.ok) { writeln("Client disconnect"); eventDriver.sockets.shutdown(client, true, true); eventDriver.sockets.releaseRef(client); return; } this.write(buf[0..bytes_read]); eventDriver.sockets.read(client, buf, IOMode.once, &onRead); } } ``` error code: ```log dub build Starting Performing "debug" build using ldc2 for aarch64, arm_hardfloat. Up-to-date taggedalgebraic 0.11.22: target for configuration [library] is up to date. Up-to-date eventcore 0.9.28: target for configuration [cfrunloop] is up to date. Building eventcoredemo ~master: building configuration [application] source/main.d(12,50): Error: none of the overloads of `listenStream` are callable using argument types `(InternetAddress, void delegate(StreamListenSocketFD a0, StreamSocketFD a1, scope RefAddress a2) @system)` ../../../.dub/packages/eventcore/0.9.28/eventcore/source/eventcore/driver.d(213,23): Candidates are: `eventcore.driver.EventDriverSockets.listenStream(scope Address bind_address, StreamListenOptions options, void delegate(StreamListenSocketFD, StreamSocketFD, scope RefAddress remote_address) nothrow @safe on_accept)` ../../../.dub/packages/eventcore/0.9.28/eventcore/source/eventcore/driver.d(215,29): `eventcore.driver.EventDriverSockets.listenStream(scope Address bind_address, void delegate(StreamListenSocketFD, StreamSocketFD, scope RefAddress remote_address) nothrow @safe on_accept)` ../../../.dub/packages/eventcore/0.9.28/eventcore/source/eventcore/drivers/posix/sockets.d(233,38): `eventcore.drivers.posix.sockets.PosixEventDriverSockets!(CFRunLoopEventLoop).PosixEventDriverSockets.listenStream(scope Address address, StreamListenOptions options, void delegate(StreamListenSocketFD, StreamSocketFD, scope RefAddress remote_address) nothrow @safe on_accept)` source/main.d(25,18): Error: function `main.Connection.write(ubyte[] data)` is not callable using argument types `(string)` source/main.d(25,18):cannot pass argument `"Welcome to use my echo server."` of type `string` to parameter `ubyte[] data` source/main.d(38,27): Error: function `eventcore.drivers.posix.sockets.PosixEventDriverSockets!(CFRunLoopEventLoop).PosixEventDriverSockets.read(StreamSocketFD socket, ubyte[] buffer, IOMode mode, void delegate(StreamSocketFD, IOStatus, ulong) nothrow @safe on_read_finish)` is not callable using argument types `(StreamSocketFD, ubyte[1024], IOMode, void delegate(StreamSocketFD, IOStatus status, ulong bytes_read))` source/main.d(38,27):cannot pass argument `&this.onRead` of type `void delegate(StreamSocketFD, IOStatus status, ulong bytes_read)` to parameter `void delegate(StreamSocketFD, IOStatus, ulong) nothrow @safe on_read_finish` source/main.d(43,28): Error: function `eventcore.drivers.posix.sockets.PosixEventDriverSockets!(CFRunLoopEventLoop).PosixEventDriverSockets.write(StreamSocketFD socket, const(ubyte)[] buffer, IOMode mode, void delegate(StreamSocketFD, IOStatus, ulong) nothrow @safe on_write_finish)` is not callable using argument types `(StreamSocketFD, ubyte[], IOMode, void delegate(StreamSocketFD fd, IOStatus status, ulong len))` source/main.d(43,28):cannot pas
Re: Datetime format?
On Friday, 19 January 2024 at 00:22:48 UTC, H. S. Teoh wrote: On Thu, Jan 18, 2024 at 11:58:32PM +, zoujiaqing via Digitalmars-d-learn wrote: On Thursday, 18 January 2024 at 23:43:13 UTC, Jonathan M Davis wrote: > On Thursday, January 18, 2024 4:26:42 PM MST zoujiaqing via > Digitalmars-d- learn wrote: > > ```D > > import std.datetime : Clock, format; > > import std.stdio : writeln; > > > > void main() > > { > > auto currentTime = Clock.currTime; > > > > auto formattedTime = currentTime.format("%Y-%m-%d > > %H:%M:%S"); > > > > writeln("Formatted Time: ", formattedTime); > > } > > ``` [...] So shame! The standard library doesn't have date formatting. [...] It's easy to write your own: d import std; void main() { auto curTime = Clock.currTime; auto dt = cast(DateTime) curTime; auto fmtTime = format("%04d-%02d-%02d %02d:%02d:%02d", dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second); writeln(fmtTime); } Output: 2024-01-18 16:21:51 You have maximum flexibility to format it however you like. T Thank you.
Re: Datetime format?
On Thursday, 18 January 2024 at 23:26:42 UTC, zoujiaqing wrote: ```D import std.datetime : Clock, format; import std.stdio : writeln; void main() { auto currentTime = Clock.currTime; auto formattedTime = currentTime.format("%Y-%m-%d %H:%M:%S"); writeln("Formatted Time: ", formattedTime); } ``` C++ Std library exmaple code: ```CPP // 2019-12-20 19:35:12 std::cout << std::put_time(locNow, "%Y-%m-%d %H:%M:%S") << std::endl; ```
Re: Datetime format?
On Thursday, 18 January 2024 at 23:43:13 UTC, Jonathan M Davis wrote: On Thursday, January 18, 2024 4:26:42 PM MST zoujiaqing via Digitalmars-d- learn wrote: ```D import std.datetime : Clock, format; import std.stdio : writeln; void main() { auto currentTime = Clock.currTime; auto formattedTime = currentTime.format("%Y-%m-%d %H:%M:%S"); writeln("Formatted Time: ", formattedTime); } ``` std.datetime does not currently support custom date/time formats. It only supports the ISO format, the ISO Extended format, and Boost's simple time format. // e.g. 20240118T163806.5813052 auto iso = time.toISOString(); // e.g. 2024-01-18T16:38:06.5813052 auto isoExt = time.toISOExtString(); // e.g. 2024-Jan-18 16:38:06.5813052 auto boostSimple = time.toSimpleString(); So, if you want a different format, you'll either need to make one yourself by calling the various properties on SysTime and passing them to something like std.format's format to create a string, or there are several packages on https://code.dlang.org which have functions for doing custom date/time formatting. - Jonathan M Davis Thank you for your replay. So shame! The standard library doesn't have date formatting. for this example "2024-Jan-18 16:38:06.5813052" Why use Jan? no 01? International standards should all apply numbers. like this: 2024-01-18 16:38:06.5813052
Datetime format?
```D import std.datetime : Clock, format; import std.stdio : writeln; void main() { auto currentTime = Clock.currTime; auto formattedTime = currentTime.format("%Y-%m-%d %H:%M:%S"); writeln("Formatted Time: ", formattedTime); } ```
Re: How to hash SHA256 from string?
Thank u every one ;) Use botan so easy: ```D import std.stdio; import botan; void main() { string appKey = "1"; auto sha256 = retrieveHash("SHA-256").clone(); sha256.update(appKey); string sign = sha256.finished()[].toHexString!(LetterCase.lower); writeln("sign: %s", sign); } ```
How to hash SHA256 from string?
```D import std.stdio; import std.digest.sha; void main() { SHA256 sha256; sha256.start(); string appKey = "1"; ubyte[1024] data = cast(ubyte[])(appKey.dup[0..$]); sha256.put(data); ubyte[32] sign = sha256.finish(); string sign1 = cast(string) sign[0..$]; writeln("sign: %s", sign1); } ``` The result varies when you run the code repeatedly and the display is garbled: ``` zoujiaqing@mac test % ./test Getui access sign: %s>tM?a?j,???ߥm?8l~??uzU?|9?~ˡ zoujiaqing@mac test % ./test Getui access sign: %s1-??U? ?d<3^3??נ? ??P%u/Iv zoujiaqing@mac test % ./test Getui access sign: %s1?ϻN?ށ?`O?p!?O?4U :8J~%ʬ zoujiaqing@mac test % ./test Getui access sign: %s??k#O?;?ڋ?5T?"=??;???e ```
Re: protobuf error: Tag value out of range
I was using a different version of dmd. Problem solved. thank you
protobuf error: Tag value out of range
code: ```d auto req = new ApplyContact(); data.fromProtobuf!ApplyContact(req); ``` protobuf: ```d class ApplyContact { @Proto(1) string fromId = protoDefaultValue!string; @Proto(2) string toId = protoDefaultValue!string; @Proto(3) string message = protoDefaultValue!string; @Proto(4) string chatId = protoDefaultValue!string; @Proto(5) ulong timestamp = protoDefaultValue!ulong; @Proto(6) ContactApplySrc src = protoDefaultValue!ContactApplySrc; @Proto(7) uint tagId = protoDefaultValue!uint; } ``` log: ```log 2023-Oct-16 19:28:51.7708915 | 2772099 | warning | execute | google.protobuf.common.ProtobufException@/root/.dub/packages/protobuf-0.6.2/protobuf/src/google/protobuf/internal.d(199): Tag value out of range /usr/include/dmd/phobos/std/exception.d:515 pure @safe void std.exception.bailOut!(google.protobuf.common.ProtobufException).bailOut(immutable(char)[], ulong, scope const(char)[]) [0x56522c393626] /usr/include/dmd/phobos/std/exception.d:436 pure @safe bool std.exception.enforce!(google.protobuf.common.ProtobufException).enforce!(bool).enforce(bool, lazy const(char)[], immutable(char)[], ulong) [0x56522c3935a2] /root/.dub/packages/protobuf-0.6.2/protobuf/src/google/protobuf/internal.d:199 pure @safe std.typecons.Tuple!(uint, "tag", google.protobuf.internal.WireType, "wireType").Tuple google.protobuf.internal.decodeTag!(ubyte[]).decodeTag(ref ubyte[]) [0x56522c5296ec] /root/.dub/packages/protobuf-0.6.2/protobuf/src/google/protobuf/decoding.d:192 pure privchat.protocol.contacts.ApplyContact google.protobuf.decoding.fromProtobuf!(privchat.protocol.contacts.ApplyContact, ubyte[]).fromProtobuf(ref ubyte[], privchat.protocol.contacts.ApplyContact) [0x56522c535c58] source/executor/friend/ApplyFriendExecutor.d:23 void executor.friend.ApplyContactExecutor.ApplyContactExecutor.applyFriend(msgtrans.TransportContext.TransportContext, msgtrans.MessageBuffer.MessageBuffer) [0x56522c5cfdef] /root/.dub/packages/hunt-reflection-0.2.1/hunt-reflection/source/witchcraft/mixins/methods.d:160 const std.variant.VariantN!(32uL).VariantN msgtrans.executor.AbstractExecutor.AbstractExecutor!(executor.friend.ApplyContactExecutor.ApplyContactExecutor).AbstractExecutor.__mixin3.__mixin8.MethodMixin!(executor.friend.ApplyContactExecutor.ApplyContactExecutor, "applyFriend", 0uL).MethodMixin.invoke(std.variant.VariantN!(32uL).VariantN, std.variant.VariantN!(32uL).VariantN[]...) [0x56522c5a6d18] /root/.dub/packages/hunt-reflection-0.2.1/hunt-reflection/source/witchcraft/invocable.d:90 const std.variant.VariantN!(32uL).VariantN witchcraft.invocable.Invocable.invoke!(std.variant.VariantN!(32uL).VariantN, Object, msgtrans.TransportContext.TransportContext, msgtrans.MessageBuffer.MessageBuffer).invoke(Object, msgtrans.TransportContext.TransportContext, msgtrans.MessageBuffer.MessageBuffer) [0x56522d025a35] /root/.dub/packages/msgtrans-0.1.4/msgtrans/source/msgtrans/executor/ExecutorInfo.d:73 nothrow void msgtrans.executor.ExecutorInfo.ExecutorInfo.execute!().execute(ref msgtrans.TransportContext.TransportContext, msgtrans.MessageBuffer.MessageBuffer) [0x56522d02566f] /root/.dub/packages/msgtrans-0.1.4/msgtrans/source/msgtrans/channel/tcp/TcpServerChannel.d:217 void msgtrans.channel.tcp.TcpServerChannel.TcpServerChannel.dispatchMessage(hunt.net.Connection.Connection, msgtrans.MessageBuffer.MessageBuffer) [0x56522d0208b6] /root/.dub/packages/msgtrans-0.1.4/msgtrans/source/msgtrans/channel/tcp/TcpServerChannel.d:150 hunt.io.channel.Common.DataHandleStatus msgtrans.channel.tcp.TcpServerChannel.TcpServerChannel.initialize().__anonclass4.messageReceived(hunt.net.Connection.Connection, Object) [0x56522d020550] /root/.dub/packages/msgtrans-0.1.4/msgtrans/source/msgtrans/channel/tcp/TcpDecoder.d:112 hunt.io.channel.Common.DataHandleStatus msgtrans.channel.tcp.TcpDecoder.TcpDecoder.decode(hunt.io.ByteBuffer.ByteBuffer, hunt.net.Connection.Connection) [0x56522d035c61] /root/.dub/packages/hunt-net-0.6.6/hunt-net/source/hunt/net/AbstractConnection.d:178 hunt.io.channel.Common.DataHandleStatus hunt.net.AbstractConnection.AbstractConnection.handleReceivedData(hunt.io.ByteBuffer.ByteBuffer) [0x56522d2776c0] /root/.dub/packages/hunt-net-0.6.6/hunt-net/source/hunt/net/AbstractConnection.d:159 hunt.io.channel.Common.DataHandleStatus hunt.net.AbstractConnection.AbstractConnection.onDataReceived(hunt.io.ByteBuffer.ByteBuffer) [0x56522d2775eb] /root/.dub/packages/hunt-1.7.13/hunt/source/hunt/io/channel/posix/AbstractStream.d:83 void hunt.io.channel.posix.AbstractStream.AbstractStream.onDataReceived(hunt.io.ByteBuffer.ByteBuffer) [0x56522d3a362c] /root/.dub/packages/hunt-1.7.13/hunt/source/hunt/io/channel/posix/AbstractStream.d:142 bool hunt.io.channel.posix.AbstractStream.AbstractStream.tryRead() [0x56522d3a37ab] /root/.dub/packages/hunt-1.7.13/hunt/source/hunt/io/TcpStream.d:428 void hunt.io.TcpStream.TcpStream.onRead() [0x56522d3a23a0] /root/.dub/packages/hunt-1.
Re: How to compiler dlang code on Apple M1?
On Saturday, 3 December 2022 at 20:33:59 UTC, Steven Schveighoffer wrote: The issue is dub. Make sure you are using the dub built for ARM. What Apple does is if any program in the same process group is x86 specific, then all the executed programs that are universal (including the linker) will switch to that mode. The linker thinks you are building on x86, even though the compiler is doing ARM64. I ran into this early on too. Switching to the dub that ships with ldc built for ARM solved it! -Steve ```[zoujiaqing@mac server % ~/Programs/ldc/bin/dub run --compiler=ldc2 --arch=arm64-apple-macos Performing "debug" build using ldc2 for aarch64, arm_hardfloat. taggedalgebraic 0.11.22: target for configuration "library" is up to date. eventcore 0.9.20+commit.4.g6744ae7: target for configuration "cfrunloop" is up to date. server ~master: building configuration "application"... Linking... ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers ld: warning: pointer not aligned at address 0x100334231 ('anon' + 561 from .dub/build/application-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-FA51B7352B8B88D87B3B8911362A8A52/server.o) ld: warning: pointer not aligned at address 0x1003350DB ('anon' + 2025 from ../../eventcore/.dub/build/cfrunloop-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-18F6DB0DFA53563841F49715E25DF4FC/libeventcore.a(eventcore.driver.o)) ld: warning: pointer not aligned at address 0x1003398EB ('anon' + 1759 from ../../eventcore/.dub/build/cfrunloop-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-18F6DB0DFA53563841F49715E25DF4FC/libeventcore.a(eventcore.drivers.posix.driver.o)) ld: warning: pointer not aligned at address 0x10033B426 ('anon' + 696 from ../../eventcore/.dub/build/cfrunloop-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-18F6DB0DFA53563841F49715E25DF4FC/libeventcore.a(eventcore.drivers.posix.events.o)) ld: warning: pointer not aligned at address 0x10033C2A1 ('anon' + 618 from ../../eventcore/.dub/build/cfrunloop-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-18F6DB0DFA53563841F49715E25DF4FC/libeventcore.a(eventcore.drivers.posix.kqueue.o)) ld: warning: pointer not aligned at address 0x10033C942 ('anon' + 1186 from ../../eventcore/.dub/build/cfrunloop-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-18F6DB0DFA53563841F49715E25DF4FC/libeventcore.a(eventcore.drivers.posix.pipes.o)) ld: warning: pointer not aligned at address 0x10033EE5E ('anon' + 1258 from ../../eventcore/.dub/build/cfrunloop-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-18F6DB0DFA53563841F49715E25DF4FC/libeventcore.a(eventcore.drivers.posix.processes.o)) ld: warning: pointer not aligned at address 0x100342E2A ('anon' + 872 from ../../eventcore/.dub/build/cfrunloop-debug-posix.osx.darwin-a
How to compiler dlang code on Apple M1?
``` dub build --compiler=ldc2 --arch=arm64-apple-macos Starting Performing "debug" build using ldc2 for aarch64, arm_hardfloat. Building taggedalgebraic 0.11.22: building configuration [library] Building eventcore 0.9.20+commit.4.g6744ae7: building configuration [cfrunloop] Building server ~master: building configuration [application] Linking server ld: warning: ignoring file ../../../.dub/packages/taggedalgebraic-0.11.22/taggedalgebraic/.dub/build/library-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-60F6D8BEA34F8F5E792A98EA27B02D2235262A4E0795062F91FA90871411535D/libtaggedalgebraic.a, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file /opt/homebrew/Cellar/ldc/1.30.0_1/lib/libdruntime-ldc.a, building for macOS-x86_64 but attempting to link with file built for macOS-arm64 ld: warning: ignoring file .dub/build/application-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-7AC1A4B8AFD7D9F59DB01E667A3DCF19DD437F41E741F5937BDCF58FAE6AA922/server.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file ../../eventcore/.dub/build/cfrunloop-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-ED6AFABD5E24BB6BCED6FD74F2DE88CF39B648360CE187983206459095D4677D/libeventcore.a, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file /opt/homebrew/Cellar/ldc/1.30.0_1/lib/libphobos2-ldc.a, building for macOS-x86_64 but attempting to link with file built for macOS-arm64 Undefined symbols for architecture x86_64: "_main", referenced from: implicit entry/start for main executable ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) Error: /usr/bin/cc failed with status: 1 Error ldc2 failed with exit code 1. ```
Re: Does D programming language have work steal queue?
On Sunday, 22 May 2022 at 22:37:43 UTC, Stefan Koch wrote: On Sunday, 22 May 2022 at 21:07:19 UTC, zoujiaqing wrote: Does D language have task steal queue? The requirements are high-performance, lock-free, and thread-safe. I have one called fluffy: https://github.com/UplinkCoder/fluffy I am not 100% sure about the performance I did try to make it reasonable but in the absence of anything else it might be jumping off point for you. Thanks ;)
Re: Does D programming language have work steal queue?
On Sunday, 22 May 2022 at 23:34:19 UTC, mw wrote: On Sunday, 22 May 2022 at 21:07:19 UTC, zoujiaqing wrote: Does D language have task steal queue? The requirements are high-performance, lock-free, and thread-safe. I have a C's liblfds D wrapper: https://github.com/mw66/liblfdsd right now only bmm and bss queue are wrapped. It's not in dub yet, but I have been using it for a while, feel free to give it a try, or even send PRs :-) Thanks :) I will try it.
Re: Does D programming language have work steal queue?
On Sunday, 22 May 2022 at 21:23:24 UTC, zoujiaqing wrote: On Sunday, 22 May 2022 at 21:07:19 UTC, zoujiaqing wrote: Does D language have task steal queue? The requirements are high-performance, lock-free, and thread-safe. I think the final usage scenario is similar to this C++ project: https://github.com/ConorWilliams/Forkpool This project implements many of the ideas in (available in reference/): * F. Schmaus et al., “Nowa: A Wait-Free Continuation-Stealing Concurrency Platform”. In: 2021 IEEE International Parallel and Distributed Processing Symposium (IPDPS). 2021. * C. -X. Lin, T. -W. Huang and M. D. F. Wong, "An Efficient Work-Stealing Scheduler for Task Dependency Graph," 2020 IEEE 26th International Conference on Parallel and Distributed Systems (ICPADS), 2020, pp. 64-71, doi: 10.1109/ICPADS51040.2020.00018.
Re: Does D programming language have work steal queue?
On Sunday, 22 May 2022 at 21:07:19 UTC, zoujiaqing wrote: Does D language have task steal queue? The requirements are high-performance, lock-free, and thread-safe. I think the final usage scenario is similar to this C++ project: https://github.com/ConorWilliams/Forkpool
Does D programming language have work steal queue?
Does D language have task steal queue? The requirements are high-performance, lock-free, and thread-safe.
Re: I need to use delete as the method name. But now it's still a keyword, right?
On Wednesday, 18 May 2022 at 15:33:09 UTC, Steven Schveighoffer wrote: On 5/18/22 2:13 AM, bauss wrote: On Wednesday, 18 May 2022 at 02:12:42 UTC, zoujiaqing wrote: https://dlang.org/changelog/2.100.0.html#deprecation_delete My code: ```D import std.stdio; class HttpClient { string get(string url) { return ""; } string delete(string url) { return ""; } } void main() { auto http = new HttpClient; string content = http.get("https://forum.dlang.org/group/general";); string content = http.delete("https://forum.dlang.org/newpost/general?";); } ``` error message ```bash % dub build --compiler=dmd Performing "debug" build using dmd for x86_64. test ~master: building configuration "application"... source/app.d(10,9): Error: no identifier for declarator `string` source/app.d(10,9): Error: declaration expected, not `delete` source/app.d(14,1): Error: unmatched closing brace dmd failed with exit code 1. ``` I wonder when I can use it. Because this will cause a software naming problem. Considering the deprecation period has ended then IMO it should be able to be used as an identifier. I would consider this a bug. No, it's intentional. https://dlang.org/changelog/2.100.0.html#deprecation_delete > Starting with this release, using the delete *keyword* will result in a *compiler error*. It's still a keyword according to that. I'm assuming a future release will remove the error, and then you can use it as a symbol. -Steve The body is now available, and hopefully the delete keyword will be deprecated soon.
Re: I need to use delete as the method name. But now it's still a keyword, right?
On Wednesday, 18 May 2022 at 06:13:45 UTC, bauss wrote: Considering the deprecation period has ended then IMO it should be able to be used as an identifier. I would consider this a bug. I hope this is a bug ;)
I need to use delete as the method name. But now it's still a keyword, right?
https://dlang.org/changelog/2.100.0.html#deprecation_delete My code: ```D import std.stdio; class HttpClient { string get(string url) { return ""; } string delete(string url) { return ""; } } void main() { auto http = new HttpClient; string content = http.get("https://forum.dlang.org/group/general";); string content = http.delete("https://forum.dlang.org/newpost/general?";); } ``` error message ```bash % dub build --compiler=dmd Performing "debug" build using dmd for x86_64. test ~master: building configuration "application"... source/app.d(10,9): Error: no identifier for declarator `string` source/app.d(10,9): Error: declaration expected, not `delete` source/app.d(14,1): Error: unmatched closing brace dmd failed with exit code 1. ``` I wonder when I can use it. Because this will cause a software naming problem.
Re: Error: variable `impl` cannot be modified at compile time
On Friday, 13 May 2022 at 19:48:04 UTC, Steven Schveighoffer wrote: On 5/13/22 3:46 PM, Steven Schveighoffer wrote: What writeln? Your compile trace is missing the original call line, and I would say probably more. Looking at your last commit, I figured it out: https://github.com/kerisy/archttp/blob/545b3eb738261e92c88b4e4bb664b4fdfb206398/source/archttp/codec/HttpDecoder.d#L31 That's where you are attempting to build an HttpRequestParser at compile time. Just use the `__ctfe` trick. -Steve Thank you my friend.
Error: variable `impl` cannot be modified at compile time
```bash % git clone https://github.com/kerisy/archttp.git % cd archttp/ % dub build --compiler=dmd Performing "debug" build using dmd for x86_64. archttp 0.0.1+commit.3.g70d44ef: building configuration "library"... ../../.dub/packages/nbuff-0.1.14/nbuff/source/nbuff/buffer.d(74,25): Deprecation: `catch` statement without an exception specification is deprecated ../../.dub/packages/nbuff-0.1.14/nbuff/source/nbuff/buffer.d(74,25):use `catch(Throwable)` for old behavior SSE: false /opt/dmd/osx/bin/../../src/phobos/std/stdio.d(5190,5): Error: variable `impl` cannot be modified at compile time /opt/dmd/osx/bin/../../src/phobos/std/stdio.d(4130,12): called from here: `makeGlobal()` /opt/dmd/osx/bin/../../src/phobos/std/stdio.d(4220,18): called from here: `trustedStdout()` ``` Why can't we use writeln in constructors? Comment out writeln so that the code will compile properly!
Re: How to gets multi results using tuple in D?
On Thursday, 23 December 2021 at 08:56:36 UTC, WebFreak001 wrote: On Thursday, 23 December 2021 at 08:33:17 UTC, zoujiaqing wrote: C++ Code: ```cpp std::tuple DoIt() { return {false, 0, 0, "Hello"}; } auto [r1, r2, r3, r4] = DoIt(); if (r1 == false) ``` D Code: ```D Tuple!(bool, int, int, string) DoIt() { return [false, 1, 1, "Hello"]; } auto result = DoIt(); auto r1= result[0]; auto r2= result[1]; auto r3= result[2]; auto r3= result[3]; if (r1 == false) ``` D requires more lines of code. I think this is the best thing you can do: ```d bool r1; int r2, r3; string r4; AliasSeq!(r1, r2, r3, r4) = DoIt(); ``` https://forum.dlang.org/thread/kmugmwmduxeoyfffo...@forum.dlang.org Thanks! It's not concise!
How to gets multi results using tuple in D?
C++ Code: ```cpp std::tuple DoIt() { return {false, 0, 0, "Hello"}; } auto [r1, r2, r3, r4] = DoIt(); if (r1 == false) ``` D Code: ```D Tuple!(bool, int, int, string) DoIt() { return [false, 1, 1, "Hello"]; } auto result = DoIt(); auto r1= result[0]; auto r2= result[1]; auto r3= result[2]; auto r3= result[3]; if (r1 == false) ``` D requires more lines of code.
How to define property type to Array!struct?
My code: ```D module http.HttpRequest; import std.container; import std.array : Appender; struct HttpRequest { struct Header() { Appender!string name; Appender!string value; } string method; string uri; int versionMajor = 0; int versionMinor = 0; Array!Header headers; ubyte[] content; bool keepAlive = false; } ``` Error code: ```D source/http/HttpRequest.d(18,5): Error: struct `std.container.array.Array` does not match any template declaration ```
Re: Bind C++ class to DLang : undefined reference to `Canvas::Foo()'
On Monday, 13 July 2020 at 12:57:52 UTC, Adam D. Ruppe wrote: On Monday, 13 July 2020 at 09:34:35 UTC, zoujiaqing wrote: # dmd source/main.d Canvas.o -L-lstdc++ && ./main [1]49078 segmentation fault ./main On my computer I got this warning out of the compiler: libstdc++ std::__cxx11::basic_string is not yet supported; the struct contains an interior pointer which breaks D move semantics! sounds like it might be a known limitation. Thanks Adam, but D link to C++ very hard?
Re: Bind C++ class to DLang : undefined reference to `Canvas::Foo()'
I changed string to basic_string. /// source/main.d import std.stdio; import core.stdcpp.string; extern(C++) { class Canvas { @disable this(); static Canvas Create(); basic_string!ubyte Foo(); basic_string!ubyte Bar(); }; } void main() { Canvas canvas = Canvas.Create(); writeln(canvas.Foo()); writeln(canvas.Bar()); } Error ... # dmd source/main.d Canvas.o -L-lstdc++ && ./main [1]49078 segmentation fault ./main
Bind C++ class to DLang : undefined reference to `Canvas::Foo()'
/// Canvas.hpp #include ; class Canvas { static Canvas* Create(); std::string Foo(); std::string Bar(); }; /// Canvas.cpp #include "Canvas.hpp" #include Canvas* Canvas::Create() { return new Canvas(); } std::string Canvas::Foo() { return "Foo"; } std::string Canvas::Bar() { return "Bar"; } /// main.d import std.stdio; extern(C++) { class Canvas { @disable this(); static Canvas Create(); string Foo(); string Bar(); }; } void main() { Canvas canvas = Canvas.Create(); writeln(canvas.Foo()); writeln(canvas.Bar()); } # clang++ -I./include/ -fPIE -c src/Canvas.cpp # dmd source/main.d Canvas.o -L-lstdc++ && ./main /usr/bin/ld: main.o:(.data._D4main6Canvas6__vtblZ+0x0): undefined reference to `Canvas::Foo()' /usr/bin/ld: main.o:(.data._D4main6Canvas6__vtblZ+0x8): undefined reference to `Canvas::Bar()' collect2: error: ld returned 1 exit status Error: linker exited with status 1
Re: Dub - vibe.d - hunt framework ... problems
On Saturday, 1 February 2020 at 10:35:52 UTC, seany wrote: Hi I want to start a small server, that will be accessible form outside. Not a huge deal right? Not quite. My machine: 4.15.0-66-generic #75-Ubuntu SMP Tue Oct 1 05:24:09 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux DMD : DMD64 D Compiler v2.090.0 Copyright (C) 1999-2019 by The D Language Foundation, All Rights Reserved written by Walter Bright Now, I try to install dub from the official repo. Then I do * dub init server -t vibe.d * cd server * dub I hit this issue : https://github.com/dlang/dub/issues/1712 As suggested, i try to build dub from github, following: https://github.com/dlang/dub/releases I call ./build.d - and everything stops, and machine crashes. I then try to install DaNode: https://github.com/DannyArends/DaNode It breaks with : module std.algorithm import 'mean' not found Then I try to install the Hunt Framework. It breaks with : basic type expected, not foreach Please help. I really want this issue to be resolved- ## 1. For simple server you can using hunt-http library. Sample code: ``` import hunt.http; void main() { HttpServer server = HttpServer.builder() .setListener(8080, "0.0.0.0") .onPost("/", (RoutingContext context) { context.end("Hello World!"); }) .onGet("/user/:name", (RoutingContext ctx) { string name = ctx.getRouterParameter("name"); ctx.write("Hello " ~ name); ctx.end(); }) .build(); server.start(); } ``` ## 2. For full server, you can using hunt-skeleton (hunt-framework based): ```bash git clone https://github.com/huntlabs/hunt-skeleton.git myproject/ cd myproject/ dub run -v ``` You can Add pages in `config/routes` , like this: ``` GET / index.index GET /user/{name}user.detail ``` Add Controller file `controller/UserController.d` : ``` module app.controller.UserController; import hunt.framework; class UserController : Controller { mixin MakeController; @Action string detail(string name) { return "Hello " ~ name; } } ``` Build and run it: ``` cd myproject/ dub run -v ``` You can see it in the borwser: ``` http://localhost:8080 ```
Re: Dmd install to new Windows 10 system can't run app.d
On Thursday, 21 November 2019 at 08:42:39 UTC, Seb wrote: Note this line: Running .\myproject.exe Program exited with code -1073741515 Your compiled program is crashing. Could you run the compiled binary manually and obtain a stack trace? Install msvcr100.dll for x64 the question is solved, thanks! https://download.microsoft.com/download/3/2/2/3224B87F-CFA0-4E70-BDA3-3DE650EFEBA5/vcredist_x64.exe
Re: Dmd install to new Windows 10 system can't run app.d
On Thursday, 21 November 2019 at 08:42:39 UTC, Seb wrote: Note this line: Running .\myproject.exe Program exited with code -1073741515 Your compiled program is crashing. Could you run the compiled binary manually and obtain a stack trace? x86 is OK, but x64 bad. PS D:\projects\myproject> dub run --arch=x86 Performing "debug" build using D:\Develop\dmd2\windows\bin\dmd.exe for x86. myproject ~master: building configuration "application"... Linking... Running .\myproject.exe Edit source/app.d to start your project.
Re: Dmd install to new Windows 10 system can't run app.d
On Thursday, 21 November 2019 at 08:42:39 UTC, Seb wrote: On Thursday, 21 November 2019 at 08:30:33 UTC, zoujiaqing wrote: 1. Download dmd.2.088.1.windows.7z 2. Unzip it to D:\Develop\dmd2 3. Add ENV D:\Develop\dmd2\windows\bin to System Path 4. Run `dub --version` and `dmd --version` in powershell is OK 5. dub ini myproject (no dependency) 6. Run `cd myproject` and `dub run` is error... [...] Note this line: Running .\myproject.exe Program exited with code -1073741515 Your compiled program is crashing. Could you run the compiled binary manually and obtain a stack trace? I don't install debug tools. but add mscoff flags is OK. PS D:\projects\myproject> cat .\source\app.d import std.stdio; void main() { writeln("Edit source/app.d to start your project."); } PS D:\projects\myproject> dub run --arch=x86_mscoff Performing "debug" build using D:\Develop\dmd2\windows\bin\dmd.exe for x86, x86_mscoff. myproject ~master: target for configuration "application" is up to date. To force a rebuild of up-to-date targets, run again with --force. Running .\myproject.exe Edit source/app.d to start your project.
Dmd install to new Windows 10 system can't run app.d
1. Download dmd.2.088.1.windows.7z 2. Unzip it to D:\Develop\dmd2 3. Add ENV D:\Develop\dmd2\windows\bin to System Path 4. Run `dub --version` and `dmd --version` in powershell is OK 5. dub ini myproject (no dependency) 6. Run `cd myproject` and `dub run` is error... Error Logging infomation: PS D:\projects\myproject> dub run -v Using dub registry url 'https://code.dlang.org/' Refreshing local packages (refresh existing: true)... Looking for local package map at C:\ProgramData\dub\packages\local-packages.json Looking for local package map at C:\Users\zouji\AppData\Local\dub\packages\local-packages.json Note: Failed to determine version of package myproject at .. Assuming ~master. Refreshing local packages (refresh existing: false)... Looking for local package map at C:\ProgramData\dub\packages\local-packages.json Looking for local package map at C:\Users\zouji\AppData\Local\dub\packages\local-packages.json Refreshing local packages (refresh existing: false)... Looking for local package map at C:\ProgramData\dub\packages\local-packages.json Looking for local package map at C:\Users\zouji\AppData\Local\dub\packages\local-packages.json Generating using build Configuring dependent myproject, deps: Performing "debug" build using D:\Develop\dmd2\windows\bin\dmd.exe for x86_64. myproject ~master: target for configuration "application" is up to date. Using existing build in D:\projects\myproject\.dub\build\application-debug-windows-x86_64-dmd_2088-7987457E14148EF60F863BFBCDFB8A1F\. Copying target from D:\projects\myproject\.dub\build\application-debug-windows-x86_64-dmd_2088-7987457E14148EF60F863BFBCDFB8A1F\myproject.exe to D:\projects\myproject To force a rebuild of up-to-date targets, run again with --force. Running .\myproject.exe Program exited with code -1073741515 I think this problem has a great impact on a new person using D language under Windows system.
Re: How to get child class Type and members from parent class?
On Wednesday, 20 November 2019 at 22:26:17 UTC, Adam D. Ruppe wrote: On Wednesday, 20 November 2019 at 20:57:56 UTC, Matheus wrote: This is a different way of designing things, do people use this often? This is really only useful sometimes. It is important to notice that if you do class C : I {} I c = new C(); c.something(); the template this there will show I, not C. All it means is this is being called on an object of that *static* type. So it isn't really a substitute for traditional virtual functions. Sometimes appropriate to use, just often not. Thanks every friends :)
How to get child class Type and members from parent class?
import std.stdio; class A { this(T)(T t) { } void write() { T _this = cast(T) this; writeln(this.v); } } class B : A { string v = "hello"; } void main() { auto b = new B; writeln(b.write()); // print hello }
Re: PHP to D Conversion
On Friday, 18 October 2019 at 06:22:33 UTC, Vino wrote: Hi All, Request your help in converting a PHP code to D equivalent code You can get one connection object and close it :) ```D import hunt.database; class AvmTest { private Database _db; this() { _db = new Database("mysql://testusr:x...@test.srv.com:3910/test"); } string[string][] getHostname() { string[string][] data; auto conn = _db.getConnection(); foreach(row; conn.query("SELECT host_name FROM hosts_coll")) { string[string] host; host["HostName"] = row["host_name"]; data ~= host; } conn.close(); return data; } } ```
Re: PHP to D Conversion
On Monday, 21 October 2019 at 15:36:25 UTC, Andre Pany wrote: On Monday, 21 October 2019 at 15:29:33 UTC, zoujiaqing wrote: On Friday, 18 October 2019 at 06:22:33 UTC, Vino wrote: [...] import hunt.database; class avmtest { private Database db; this() { db = new Database("mysql://testusr:x...@test.srv.com:3910/test"); } string[string][] getHostname() { string[string] data; foreach(row; db.query("SELECT host_name FROM hosts_coll")) { string[string] host; host["HostName"] = row["host_name"]; data ~= host; } return data; } } Is this database library compatible with the fiber programming model of vibe-d? Kind regards Andre Yes. There are no conflicts.
Re: PHP to D Conversion
On Friday, 18 October 2019 at 06:22:33 UTC, Vino wrote: Hi All, Request your help in converting a PHP code to D equivalent code PHP Code: class avmtest { private $con; function __construct() { global $config; $this->con = new mysqli(test.srv.com:3910, testusr, #, test); if($this->con->connect_errno) { die("Connection Failed.\n"); } } function getHostname() { $qdata = $this->con->prepare("SELECT host_name FROM hosts_coll"); $qdata->execute(); $qdata->bind_result($host); while($qdata->fetch()) { $data[] = array("HostName" => $host); } $sdata->close(); return $data; } } D Code: module avm.test; import mysql; import std.array : array; import std.conv; import std.variant; class avmtest { private conn; auto avmconnect() { auto connectionStr = "host=test.srv.com;port=3910;user=testusr;pwd=#;db=test"; Connection conn = new Connection(connectionStr); scope(exit) conn.close(); } auto getHostname() { ResultRange qdata = conn.query("SELECT host_name FROM `hosts_coll`"); Row row = qdata.front; Variant h = row[0]; qdata.close(); return h.to!string; } } Error: Error: no identifier for declarator conn From, Vino.B import hunt.database; class avmtest { private Database db; this() { db = new Database("mysql://testusr:x...@test.srv.com:3910/test"); } string[string][] getHostname() { string[string] data; foreach(row; db.query("SELECT host_name FROM hosts_coll")) { string[string] host; host["HostName"] = row["host_name"]; data ~= host; } return data; } }
Re: D on ARM laptops?
On Thursday, 4 July 2019 at 07:46:53 UTC, Paolo Invernizzi wrote: On Thursday, 4 July 2019 at 01:01:03 UTC, Nicholas Wilson wrote: On Wednesday, 3 July 2019 at 20:49:20 UTC, JN wrote: Does anyone know if and how well D works on ARM laptops (such as Chromebooks and similar)? For example this one https://www.pine64.org/pinebook/ . Can it compile D? Obviously DMD is out because it doesn't have ARM builds. Not sure about GDC. How about LDC? Haven't tried on laptops, but I can't imagine it would be too different to RasPi which LDC worked fine on. We are using LDC on Jetson boards and it's working fine ... LDC on FreeBSD working fine?
Re: How to use template Object in interface?
On Tuesday, 25 June 2019 at 12:11:47 UTC, zoujiaqing wrote: hunt-cache current version use template implemention adapter changes. I want use Interface to define Adapter, this master code unable to comple. How to do it? D programming language design flaws? ```bash git clone https://github.com/huntlabs/hunt-cache cd hunt-cache/example dub run -v ... source/app.d(29,19): Error: no property name for type Nullable!(User) ``` Error in this commit: https://github.com/huntlabs/hunt-cache/commit/1f4ca85b47a7e62b41907152f8c8904e69a09975
Re: is there any micro-service library in D?
On Wednesday, 19 June 2019 at 08:29:15 UTC, dangbinghoo wrote: hi there, Does anyone know the micro-service oriented design library or framework in D? thanks! binghoo dang You can try hunt-service: hunt-service is distributed RPC framework for DLang based on gRPC and neton. https://github.com/huntlabs/hunt-service
Re: How to use template Object in interface?
On Tuesday, 25 June 2019 at 12:11:47 UTC, zoujiaqing wrote: hunt-cache current version use template implemention adapter changes. I want use Interface to define Adapter, this master code unable to comple. How to do it? D programming language design flaws? ```bash git clone https://github.com/huntlabs/hunt-cache cd hunt-cache/example dub run -v ... source/app.d(29,19): Error: no property name for type Nullable!(User) ``` Interface code: https://github.com/huntlabs/hunt-cache/blob/master/source/hunt/cache/adapter/Adapter.d ```D module hunt.cache.adapter.Adapter; import hunt.cache.Nullable; interface Adapter { Nullable!V get(V) (string key); Nullable!V[string] get(V) (string[] keys); void set(V) (string key, V value, uint expired); void set(V) (V[string] maps, uint expired); bool setIfAbsent(V) (string key, V value); bool hasKey(string key); bool remove(string key); void remove(string[] keys); void clear(); } ```
How to use template Object in interface?
hunt-cache current version use template implemention adapter changes. I want use Interface to define Adapter, this master code unable to comple. How to do it? D programming language design flaws? ```bash git clone https://github.com/huntlabs/hunt-cache cd hunt-cache/example dub run -v ... source/app.d(29,19): Error: no property name for type Nullable!(User) ```
Re: How to convert array of structs to JSON
On Tuesday, 25 June 2019 at 05:33:57 UTC, mark wrote: I have the following array of structs: struct Person { string name; int age; }; Person people[]; Person p; Person p1 = { "Bob", 12 }; Person p2 = { "Bob", 12 }; people ~= p1; people ~= p2; I've read through the std.json documentation, but I'm still confused as to how to create an array of objects, especially if the objects are structs. I've included this: JSONValue jj; jj["nodes"].array = []; But I get the error: JSONValue is not an object. Ideally, I'd like to have a json output that looks like this: [ { "name": "Bob", "age": 12 }, { "name": "Bob", "age": 12 }, ] Any help would be greatly appreciated. use hunt library: https://github.com/huntlabs/hunt Sample code: import hunt.serialize; void main() { auto json = toJson(pepole); }
Re: Error: char 0x200b not allowed in identifier
On Monday, 3 June 2019 at 14:41:18 UTC, ag0aep6g wrote: On 03.06.19 15:37, zoujiaqing wrote: Error for code: source/hunt/xml/Element.d(12,13): Error: char 0x200b not allowed in identifier U+200B is: ZERO WIDTH SPACE. Somehow you got that invisible character into your code. You have to get rid of it. To do it manually, navigate to the locations the compiler gives you and find the spot where the cursor seems to get stuck for one key press. That's where a zero width space is. You can also open the file in a different non-Unicode encoding. The zero width spaces should stick out as non-ASCII symbols. Or you could write a program that goes over the file and filters the zero width spaces out. Or just re-write whole lines or the whole file by hand. Thanks :)
Error: char 0x200b not allowed in identifier
Error for code: source/hunt/xml/Element.d(12,13): Error: char 0x200b not allowed in identifier source/hunt/xml/Element.d(12,23): Error: character 0x200b is not a valid token source/hunt/xml/Element.d(17,15): Error: char 0x200b not allowed in identifier source/hunt/xml/Element.d(17,26): Error: character 0x200b is not a valid token source/hunt/xml/Element.d(22,13): Error: char 0x200b not allowed in identifier source/hunt/xml/Element.d(22,29): Error: character 0x200b is not a valid token source/hunt/xml/Element.d(48,13): Error: char 0x200b not allowed in identifier source/hunt/xml/Element.d(48,21): Error: character 0x200b is not a valid token source/hunt/xml/Element.d(55,13): Error: char 0x200b not allowed in identifier source/hunt/xml/Element.d(55,23): Error: character 0x200b is not a valid token source/hunt/xml/Element.d(62,13): Error: char 0x200b not allowed in identifier source/hunt/xml/Element.d(62,20): Error: character 0x200b is not a valid token The Code file Element.d ```D module hunt.xml.Element; import hunt.xml.ElementType; class Element { this(string name) { this._name = name; } Element addElement(string name) { return new Element(name); } Element[] getElements() { return this._elements; } Element getParentELement() { return this._parentElement; } Element removeAttribute(string key) { this._attributes.remove(key); return this; } Element addAttribute(string key, string value) { this._attributes[key] = value; return this; } Element setAttribute(string key, string value) { this._attributes[key] = value; return this; } Element addCDATA(string cdata) { this._cdata = cdata; return this; } Element addComment(string comment) { this._comments ~= comment; return this; } Element addText(string text) { this._text = text; return this; } private { string _name; Element[] _elements; Element _parentElement; string[string] _attributes; string[] _comments; string _text; string _cdata; } } ```