Vibe.d diet template help

2021-02-06 Thread Tim via Digitalmars-d-learn
Hi all, I'm trying to render a diet template out to a WebSocket as a string to be inserted into a specific portion of the currently served page. Does anyone know how to go about this?

How can I stop D from dropping decimals in strings

2021-02-02 Thread Tim via Digitalmars-d-learn
Hi all, I have to serialize an array like [0.0, 0.0, 0.0] to a Json object. During this process, the serializer creates a string of the array, but it creates "[0, 0, 0]", dropping the decimal. How can I stop this?

Re: How can I use UFCS for a loop

2021-01-25 Thread Tim via Digitalmars-d-learn
On Tuesday, 26 January 2021 at 01:38:45 UTC, Q. Schroll wrote: On Tuesday, 26 January 2021 at 00:47:09 UTC, Tim wrote: Hi all, How can I change the following to a more D-like approach by using UFCS? double[3] result; Unless you have a good reason, use a slice and not a static array:

How can I use UFCS for a loop

2021-01-25 Thread Tim via Digitalmars-d-learn
Hi all, How can I change the following to a more D-like approach by using UFCS? double[3] result; Json json = res.readJson; for(int i = 0; i < json.length; i++){ result[i] = json[i].to!double; } I'd prefer to do something like: result = res.readJson[].map!(to!double);

Re: Issue with socket recieve

2021-01-20 Thread Tim via Digitalmars-d-learn
On Thursday, 21 January 2021 at 03:35:05 UTC, Adam D. Ruppe wrote: On Thursday, 21 January 2021 at 03:24:13 UTC, Tim wrote: No, I don't. It should be all garbage collected right? Yeah, but that's where the problem comes. Note that by destructor, I mean *any* function in your code called

Re: Issue with socket recieve

2021-01-20 Thread Tim via Digitalmars-d-learn
On Thursday, 21 January 2021 at 03:21:41 UTC, Adam D. Ruppe wrote: On Wednesday, 20 January 2021 at 21:31:54 UTC, Tim wrote: Unable to open 'recv.c': Unable to read file '/build/glibc-ZN95T4/glibc-2.31/sysdeps/unix/sysv/linux/recv.c' (Error: Unable to resolve non-existing file

Re: Issue with socket recieve

2021-01-20 Thread Tim via Digitalmars-d-learn
On Thursday, 21 January 2021 at 03:21:41 UTC, Adam D. Ruppe wrote: On Wednesday, 20 January 2021 at 21:31:54 UTC, Tim wrote: Unable to open 'recv.c': Unable to read file '/build/glibc-ZN95T4/glibc-2.31/sysdeps/unix/sysv/linux/recv.c' (Error: Unable to resolve non-existing file

Re: Exit code -4

2021-01-20 Thread Tim via Digitalmars-d-learn
On Thursday, 21 January 2021 at 01:07:22 UTC, Paul Backus wrote: On Thursday, 21 January 2021 at 00:49:26 UTC, Tim wrote: Oh, so it's just signal 4, not -4? The signal is 4. The exit status is -4. https://en.wikipedia.org/wiki/Signal_(IPC)#POSIX_signals

Re: Exit code -4

2021-01-20 Thread Tim via Digitalmars-d-learn
On Thursday, 21 January 2021 at 00:47:36 UTC, Adam D. Ruppe wrote: On Thursday, 21 January 2021 at 00:37:19 UTC, Tim wrote: Hi all, From time to time my program crashes with exit code -4. I can't seem to find much on the code. Does anyone know what this means and how to debug the issue?

Exit code -4

2021-01-20 Thread Tim via Digitalmars-d-learn
Hi all, From time to time my program crashes with exit code -4. I can't seem to find much on the code. Does anyone know what this means and how to debug the issue?

Issue with socket recieve

2021-01-20 Thread Tim via Digitalmars-d-learn
Hi all, I'm having a really terrible bug that seemed to come from nowhere and is really hard to narrow down. I have a threaded message service that works via local TcpSocket. Every time I run it, either an error saying: Unable to open 'recv.c': Unable to read file

Re: Generating documentation help

2021-01-19 Thread Tim via Digitalmars-d-learn
On Wednesday, 20 January 2021 at 01:25:28 UTC, Adam D. Ruppe wrote: On Wednesday, 20 January 2021 at 01:00:32 UTC, Tim wrote: But if I deleted index.html then reran the doc gen, it worked just fine. Looks like index.html is not being updated oh yeah i forgot i did that cuz I so often

Re: Generating documentation help

2021-01-19 Thread Tim via Digitalmars-d-learn
On Wednesday, 20 January 2021 at 00:53:54 UTC, Adam D. Ruppe wrote: On Wednesday, 20 January 2021 at 00:16:51 UTC, Tim wrote: They are defined "module simulator" and "module analyzer". I also have "module math" etc. that are added to the index That's weird... There are a bunch of command

Re: Generating documentation help

2021-01-19 Thread Tim via Digitalmars-d-learn
On Wednesday, 20 January 2021 at 00:13:42 UTC, Adam D. Ruppe wrote: On Wednesday, 20 January 2021 at 00:06:35 UTC, Tim wrote: Yeah, they have both. They also contain the main entrypoint What are the module names? If it is like `module foo.main;` it will be listed under `foo` as a submodule

Re: Generating documentation help

2021-01-19 Thread Tim via Digitalmars-d-learn
On Wednesday, 20 January 2021 at 00:03:16 UTC, Adam D. Ruppe wrote: On Tuesday, 19 January 2021 at 23:58:59 UTC, Tim wrote: The main issue is that those scripts aren't being added to index.html Do they have module definitions and doc comments in there somewhere? like here I have all kinds

Re: Generating documentation help

2021-01-19 Thread Tim via Digitalmars-d-learn
On Tuesday, 19 January 2021 at 23:57:21 UTC, Adam D. Ruppe wrote: On Tuesday, 19 January 2021 at 23:51:00 UTC, Tim wrote: I'm creating a u-services based app so my apps need to be documented properly as well. I can get around this by defining them as modules but then adrdox doesn't add them to

Re: Generating documentation help

2021-01-19 Thread Tim via Digitalmars-d-learn
On Sunday, 17 January 2021 at 22:27:13 UTC, Adam D. Ruppe wrote: On Sunday, 17 January 2021 at 21:48:20 UTC, Paul Backus wrote: I recommend using adrdox instead: note you should be able to just dub run adrdox and it will spit out `generated_docs/files...` (assuming i haven't broken that

Re: How can I check to see if template type is an array?

2021-01-19 Thread Tim via Digitalmars-d-learn
On Tuesday, 19 January 2021 at 22:45:19 UTC, Paul Backus wrote: On Tuesday, 19 January 2021 at 22:38:41 UTC, Tim wrote: On Tuesday, 19 January 2021 at 22:36:47 UTC, Paul Backus wrote: On Tuesday, 19 January 2021 at 22:34:04 UTC, Tim wrote: On Tuesday, 19 January 2021 at 22:31:47 UTC, Paul

Re: How can I check to see if template type is an array?

2021-01-19 Thread Tim via Digitalmars-d-learn
On Tuesday, 19 January 2021 at 22:36:47 UTC, Paul Backus wrote: On Tuesday, 19 January 2021 at 22:34:04 UTC, Tim wrote: On Tuesday, 19 January 2021 at 22:31:47 UTC, Paul Backus wrote: You've almost got it. The correct syntax is `is(T == U[], U)`. You can read it as "there exists some type U

Re: How can I check to see if template type is an array?

2021-01-19 Thread Tim via Digitalmars-d-learn
On Tuesday, 19 January 2021 at 22:31:47 UTC, Paul Backus wrote: You've almost got it. The correct syntax is `is(T == U[], U)`. You can read it as "there exists some type U such that T == U[]". Thanks! Do I need to specify U in the template function?

How can I check to see if template type is an array?

2021-01-19 Thread Tim via Digitalmars-d-learn
Hi all, I need to be able to check in a template whether the type given is an array type so that I can do some different logic. How can I do this? I would have thought that if(is(T == [])) would work, but no. Thanks in advance

Generating documentation help

2021-01-17 Thread Tim via Digitalmars-d-learn
Hi there, I have a couple of (probably) fairly simple questions. First, when I generate documentation files (-Dd docs) for my project, it also generates documentation for the library Mir. How can I fix the compiler pulling in those docs as well? It seems that D won't let me document class

Re: How to define delegate with needed parameters

2021-01-13 Thread Tim via Digitalmars-d-learn
On Thursday, 14 January 2021 at 00:29:23 UTC, Paul Backus wrote: Easiest way is to use a lambda: doSomething(() => foo(q)) This worked perfectly, thank you for your timely response~

How to define delegate with needed parameters

2021-01-13 Thread Tim via Digitalmars-d-learn
I would like to be able to create a delegate but also supply the function parameters to be used for the function call. How can I go about doing this? Example: void foo(int i){ } void bar(string m){ } doSomething((q)); doSomething(("test");

Re: Member variables in method are null when called as delegate from thread

2021-01-12 Thread Tim via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 01:49:11 UTC, tsbockman wrote: The compiler and the physical CPU are both allowed to change the order in which instructions are executed to something different from what your code specifies, as long as the visible, "official" results and effects of the chosen

Re: Member variables in method are null when called as delegate from thread

2021-01-11 Thread Tim via Digitalmars-d-learn
On Monday, 11 January 2021 at 08:21:21 UTC, Arafel wrote: It's also possible that you'll have to make Foo itself `shared`, or at least convert your constructor into a `shared this ()` to get a shared instance that you can pass to a different thread, but I'm not sure how function pointers /

Re: Member variables in method are null when called as delegate from thread

2021-01-10 Thread Tim via Digitalmars-d-learn
Ok, so it seems that it isn't null now. But I stall can't call db.getCollection().findAndModify() from vibe.d successfully here. Works just fine in the constructor. When it's called form the MessengerService thread it never returns from the function call

Member variables in method are null when called as delegate from thread

2021-01-10 Thread Tim via Digitalmars-d-learn
Hi there, I have something like this: class Foo{ MongoClient db; this(){ db = connectMongoDB("127.0.0.1"); void delegate()[string] commands = ["start": ]; MessageService messenger = new MessageService(8081, commands); } void start(){ // Do

Re: Dub platform probes

2020-05-27 Thread Tim via Digitalmars-d-learn
On Wednesday, 27 May 2020 at 21:17:54 UTC, Andre Pany wrote: I read through the source code. The probe file is created here https://github.com/dlang/dub/blob/master/source/dub/compilers/utils.d#L296 The function getTempFile determines a new random temp file name and stores the file path in a

Re: Dub platform probes

2020-05-26 Thread Tim via Digitalmars-d-learn
On Tuesday, 26 May 2020 at 09:17:52 UTC, Andre Pany wrote: Hi, What version of dub do you use? I am not 100 % sure but thought platform probes do not longer write files with recent dub version. Do you use DMD or LDC or GDC? Kind regards Andre Hi there I'm using Dub 1.19.0-1build2 with dmd

Dub platform probes

2020-05-25 Thread Tim via Digitalmars-d-learn
Hi all I end up with a directory flooded with platform probes. How can I make sure that old ones are deleted automatically? Thanks

Re: Asserting that a base constructor is always called

2020-05-24 Thread Tim via Digitalmars-d-learn
On Sunday, 24 May 2020 at 00:51:17 UTC, Jonathan M Davis wrote: On Saturday, May 23, 2020 4:43:04 PM MDT Tim via Digitalmars-d-learn wrote: It is but I want to make sure for other cases in the future where I create a new class that inherits from GameObject. This was I can avoid future bugs

Re: Asserting that a base constructor is always called

2020-05-23 Thread Tim via Digitalmars-d-learn
On Saturday, 23 May 2020 at 22:15:49 UTC, Ali Çehreli wrote: Is it not already called? I tried the following and it seems to work: import std.stdio; GameObject[1] world; enum layer = 0; /// Base class of most objects in the game class GameObject{ this(){ world[layer] = this;

Asserting that a base constructor is always called

2020-05-23 Thread Tim via Digitalmars-d-learn
I have a base class GameObject: /// Base class of most objects in the game class GameObject{ this(){ world[layer] = this; } abstract void update(){} void draw(){} } I want to make sure that whenever a class inherits from this, the base constructor is always called.

Re: Storing a reference to the calling object

2020-05-23 Thread Tim via Digitalmars-d-learn
On Saturday, 23 May 2020 at 09:48:57 UTC, Mike Parker wrote: Since you're using classes, one way is to use a common base class or an interface. But assuming "parent" is the owner of the Sprite instance, you might eliminate the dependency on the parent and have it update the Sprite's position

Storing a reference to the calling object

2020-05-23 Thread Tim via Digitalmars-d-learn
Hi all, I'm a little new to D and I'm wondering how I can store a reference to the calling object. I want to create a reference to an object's parent so that each time I go to update the sprite, it is able to grab its position from the parent. So if I have: class Sprite{ /// Postional

Initialization sequence of runtime environment

2014-06-13 Thread Tim via Digitalmars-d-learn
I recently posted another thread (regarding crt1.o: could not read symbols: Bad value - I'm creating a new thread because it's another problem) and I figured out that the following error: stack_bottom = 7fc98804ae18 thread_stack 0x4 /usr/sbin/mysqld(my_print_stacktrace+0x35)[0x8cea15]

Re: crt1.o: could not read symbols: Bad value

2014-06-12 Thread Tim via Digitalmars-d-learn
On Wednesday, 11 June 2014 at 17:21:54 UTC, Tim wrote: On Wednesday, 11 June 2014 at 17:11:51 UTC, Tim wrote: On Wednesday, 11 June 2014 at 10:09:50 UTC, FreeSlave wrote: I conclude that because I have similar errors when trying to build 64-bit library on 32-bit system. /usr/bin/ld:

Re: Decimal type documentation

2014-06-11 Thread Tim via Digitalmars-d-learn
On Tuesday, 10 June 2014 at 15:52:29 UTC, Poyeyo wrote: Hello, has anyone used this https://github.com/andersonpd/decimal implementation? I'm learning D and want to know where to start for the decimal (or bigfloat) stuff. The goal is to be able to read and write some data from a SQL DB

Re: crt1.o: could not read symbols: Bad value

2014-06-11 Thread Tim via Digitalmars-d-learn
On Wednesday, 11 June 2014 at 10:09:50 UTC, FreeSlave wrote: I conclude that because I have similar errors when trying to build 64-bit library on 32-bit system. /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libphobos2.a(format_712_5b3.o): relocation R_X86_64_32 against `.rodata' can not be used

Re: crt1.o: could not read symbols: Bad value

2014-06-11 Thread Tim via Digitalmars-d-learn
On Wednesday, 11 June 2014 at 17:11:51 UTC, Tim wrote: On Wednesday, 11 June 2014 at 10:09:50 UTC, FreeSlave wrote: I conclude that because I have similar errors when trying to build 64-bit library on 32-bit system. /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libphobos2.a(format_712_5b3.o):

crt1.o: could not read symbols: Bad value

2014-06-10 Thread Tim via Digitalmars-d-learn
Hi guys, I've the following few lines: module test; export: extern(D): int test() { return 0; } ... and compile it using the following line: dmd -m64 -fPIC -L-shared test.d -oflibtest.so But when I try to compile it, I always get the following error: /usr/bin/ld:

Re: crt1.o: could not read symbols: Bad value

2014-06-10 Thread Tim via Digitalmars-d-learn
On Tuesday, 10 June 2014 at 20:29:56 UTC, FreeSlave wrote: dmd has -shared option. Try it instead of -L-shared. I'm getting a similar error: /usr/bin/ld: /usr/local/bin/../lib64/libphobos2.a(object__a_58c.o): relocation R_X86_64_32 against `_D10TypeInfo_m6__initZ' can not be used when

How to handle try-catch blocks, nothrow and logfiles

2014-05-24 Thread Tim via Digitalmars-d-learn
I'm working on an application where I want log all exceptions but I'm not sure what's the best way to realize that. Sure I can do the following: void myMethod() nothrow { try { // Do something } catch (Exception e) { // Write log file } } But there are some

Re: How to handle try-catch blocks, nothrow and logfiles

2014-05-24 Thread Tim via Digitalmars-d-learn
On Saturday, 24 May 2014 at 17:55:07 UTC, Ali Çehreli wrote: On 05/24/2014 10:09 AM, Tim wrote: I'm working on an application where I want log all exceptions but I'm not sure what's the best way to realize that. A common solution is to log it in the exception class'es constructor. We even

Re: Modify char in string

2014-05-19 Thread Tim via Digitalmars-d-learn
On Sunday, 18 May 2014 at 19:09:52 UTC, Chris Cain wrote: On Sunday, 18 May 2014 at 18:55:59 UTC, Tim wrote: Hi everyone, is there any chance to modify a char in a string like: As you've seen, you cannot modify immutables (string is an immutable(char)[]). If you actually do want the string

Modify char in string

2014-05-18 Thread Tim via Digitalmars-d-learn
Hi everyone, is there any chance to modify a char in a string like: void main() { string sMyText = Replace the last char_; sMyText[$ - 1] = '.'; } But when I execute the code above I'm always getting cannot modify immutable expression at sMyText[__dollar -1LU]. I though D supported

Re: Socket server + thread: cpu usage

2014-05-01 Thread Tim via Digitalmars-d-learn
On Tuesday, 29 April 2014 at 17:19:41 UTC, Adam D. Ruppe wrote: On Tuesday, 29 April 2014 at 17:16:33 UTC, Tim wrote: Is there anything I'm doing wrong? You should be using a blocking socket. With them, the operating system will put your thread on hold until a new connection comes in.

Re: Socket server + thread: cpu usage

2014-05-01 Thread Tim via Digitalmars-d-learn
On Thursday, 1 May 2014 at 08:08:37 UTC, Tim wrote: On Tuesday, 29 April 2014 at 17:19:41 UTC, Adam D. Ruppe wrote: On Tuesday, 29 April 2014 at 17:16:33 UTC, Tim wrote: Is there anything I'm doing wrong? You should be using a blocking socket. With them, the operating system will put your

Socket server + thread: cpu usage

2014-04-29 Thread Tim via Digitalmars-d-learn
Hi guys, I've the following snipped: TcpSocket oSocket = new TcpSocket(AddressFamily.INET); oSocket.bind(new InternetAddress(127.0.0.1, 12345)); oSocket.blocking(false); oSocket.listen(0); while(true) { try { Socket oRequestSocket = oSocket.accept();

Re: Socket server + thread: cpu usage

2014-04-29 Thread Tim via Digitalmars-d-learn
On Tuesday, 29 April 2014 at 17:19:41 UTC, Adam D. Ruppe wrote: On Tuesday, 29 April 2014 at 17:16:33 UTC, Tim wrote: Is there anything I'm doing wrong? You should be using a blocking socket. With them, the operating system will put your thread on hold until a new connection comes in.

Re: Socket server + thread: cpu usage

2014-04-29 Thread Tim via Digitalmars-d-learn
On Tuesday, 29 April 2014 at 17:35:08 UTC, Tim wrote: On Tuesday, 29 April 2014 at 17:19:41 UTC, Adam D. Ruppe wrote: On Tuesday, 29 April 2014 at 17:16:33 UTC, Tim wrote: Is there anything I'm doing wrong? You should be using a blocking socket. With them, the operating system will put your