Re: template? mixin? template mixins? for modifying a struct setup

2022-05-19 Thread user1234 via Digitalmars-d-learn

On Thursday, 19 May 2022 at 10:15:32 UTC, Chris Katko wrote:

given
```D
struct COLOR
{
float r, g, b, a; // a is alpha (opposite of transparency)
}

auto red   = COLOR(1,0,0,1);
auto green = COLOR(0,1,0,1);
auto blue  = COLOR(0,0,1,1);
auto white = COLOR(1,1,1,1);
//etc
```

is there a way to do:
```D
auto myColor = GREY!(0.5);
// where GREY!(0.5) becomes COLOR(0.5, 0.5, 0.5, 1.0);
```


average is a bad way to grayscale FYI ;)


template? mixin? template mixins? for modifying a struct setup

2022-05-19 Thread Chris Katko via Digitalmars-d-learn

given
```D
struct COLOR
{
float r, g, b, a; // a is alpha (opposite of transparency)
}

auto red   = COLOR(1,0,0,1);
auto green = COLOR(0,1,0,1);
auto blue  = COLOR(0,0,1,1);
auto white = COLOR(1,1,1,1);
//etc
```

is there a way to do:
```D
auto myColor = GREY!(0.5);
// where GREY!(0.5) becomes COLOR(0.5, 0.5, 0.5, 1.0);
```


Re: template? mixin? template mixins? for modifying a struct setup

2022-05-19 Thread bauss via Digitalmars-d-learn

On Thursday, 19 May 2022 at 10:18:38 UTC, user1234 wrote:

On Thursday, 19 May 2022 at 10:15:32 UTC, Chris Katko wrote:

given
```D
struct COLOR
{
float r, g, b, a; // a is alpha (opposite of transparency)
}

auto red   = COLOR(1,0,0,1);
auto green = COLOR(0,1,0,1);
auto blue  = COLOR(0,0,1,1);
auto white = COLOR(1,1,1,1);
//etc
```

is there a way to do:
```D
auto myColor = GREY!(0.5);
// where GREY!(0.5) becomes COLOR(0.5, 0.5, 0.5, 1.0);
```


average is a bad way to grayscale FYI ;)


This is correct, you actually have to do something like this:

```d
uint g = (uint)((0.3f * r) + (0.59f * g) + (0.11f * b));
```

Where g is the new value for the current pixel's rgb value.

However, OP doesn't seem to be grayscaling images, but rather 
just wanting to specify gray colors.


In which case something like this could work:

```d
COLOR GREY(float amount)() { return COLOR(amount, amount, amount, 
1.0); }


...

auto myColor = GREY!(0.5);

myColor is COLOR(0.5, 0.5, 0.5, 1.0)
```



Re: template? mixin? template mixins? for modifying a struct setup

2022-05-19 Thread ag0aep6g via Digitalmars-d-learn

On 19.05.22 12:15, Chris Katko wrote:

given
```D
struct COLOR
{
float r, g, b, a; // a is alpha (opposite of transparency)
}

auto red   = COLOR(1,0,0,1);
auto green = COLOR(0,1,0,1);
auto blue  = COLOR(0,0,1,1);
auto white = COLOR(1,1,1,1);
//etc
```

is there a way to do:
```D
auto myColor = GREY!(0.5);
// where GREY!(0.5) becomes COLOR(0.5, 0.5, 0.5, 1.0);
```


What's wrong with a simple plain function?

COLOR grey(float rgb)
{
return COLOR(rgb, rgb, rgb, 1);
}
auto myColor = grey(0.5);


Re: Unexplainable behaviour with direct struct assignment.

2022-05-19 Thread HuskyNator via Digitalmars-d-learn

On Thursday, 19 May 2022 at 04:33:01 UTC, Tejas wrote:

Does this happen with LDC as well?


I tried it using `LDC 1.29.0` and it prints correctly under both 
`--b=release` and `--b=debug` builds.


Re: Unexplainable behaviour with direct struct assignment.

2022-05-19 Thread frame via Digitalmars-d-learn

On Wednesday, 18 May 2022 at 21:49:14 UTC, HuskyNator wrote:

After updating to `DMD 2.100.0` & `DUB 1.29.0`, I still get 
this behavior.
Only when I use `dub run --b=debug` however (default for me). 
`dub run --b=release` does return what one would expect.


I'm still on 2098.1, Windows 10 and get this at 64bit only

```
9.18366e-40
50
nan
```

but no matter if debug build or not.


Error: undefined symbol: _WinMain@16 When try compile no console

2022-05-19 Thread Marcone via Digitalmars-d-learn

Using -L/SUBSYSTEM:windows user32.lib

Error:

lld-link: error: undefined symbol: _WinMain@16
referenced by 
msvcrt120.lib(msvcrt_stub2.obj):(_WinMainCRTStartup)

Error: linker exited with status 1


Re: Error: undefined symbol: _WinMain@16 When try compile no console

2022-05-19 Thread Adam D Ruppe via Digitalmars-d-learn

On Thursday, 19 May 2022 at 19:29:25 UTC, Marcone wrote:

Using -L/SUBSYSTEM:windows user32.lib


you using a main() function right?

Please note when compiling on Win64, you need to explicitly list 
-Lgdi32.lib -Luser32.lib on the build command. If you want the 
Windows subsystem too, use -L/subsystem:windows 
-L/entry:mainCRTStartup.


If using ldc instead of dmd, use -L/entry:wmainCRTStartup instead 
of mainCRTStartup; note the "w".



see some deets i wrote here

http://arsd-official.dpldocs.info/arsd.simpledisplay.html#installation-instructions


Re: Error: undefined symbol: _WinMain@16 When try compile no console

2022-05-19 Thread Marcone via Digitalmars-d-learn

On Thursday, 19 May 2022 at 19:35:20 UTC, Adam D Ruppe wrote:

On Thursday, 19 May 2022 at 19:29:25 UTC, Marcone wrote:

Using -L/SUBSYSTEM:windows user32.lib


you using a main() function right?

Please note when compiling on Win64, you need to explicitly 
list -Lgdi32.lib -Luser32.lib on the build command. If you want 
the Windows subsystem too, use -L/subsystem:windows 
-L/entry:mainCRTStartup.


If using ldc instead of dmd, use -L/entry:wmainCRTStartup 
instead of mainCRTStartup; note the "w".



see some deets i wrote here

http://arsd-official.dpldocs.info/arsd.simpledisplay.html#installation-instructions


I am using a main() function.
I am compiling on Windows x86 32 bits.
I am using DMD 2.100.0
This error is only in version 2.100.0 of DMD.


Re: Error: undefined symbol: _WinMain@16 When try compile no console

2022-05-19 Thread Adam D Ruppe via Digitalmars-d-learn

On Thursday, 19 May 2022 at 20:20:49 UTC, Marcone wrote:

I am using a main() function.
I am compiling on Windows x86 32 bits.
I am using DMD 2.100.0
This error is only in version 2.100.0 of DMD.


Are you using the `-L/entry:mainCRTStartup` or the 
`L/entry:wmainCRTStartup` ?


Re: Error: undefined symbol: _WinMain@16 When try compile no console

2022-05-19 Thread Marcone via Digitalmars-d-learn

On Thursday, 19 May 2022 at 20:33:34 UTC, Adam D Ruppe wrote:

On Thursday, 19 May 2022 at 20:20:49 UTC, Marcone wrote:

I am using a main() function.
I am compiling on Windows x86 32 bits.
I am using DMD 2.100.0
This error is only in version 2.100.0 of DMD.


Are you using the `-L/entry:mainCRTStartup` or the 
`L/entry:wmainCRTStartup` ?


-L/entry:mainCRTStartup


Re: Error: undefined symbol: _WinMain@16 When try compile no console

2022-05-19 Thread Adam Ruppe via Digitalmars-d-learn

On Thursday, 19 May 2022 at 21:41:50 UTC, Marcone wrote:
Are you using the `-L/entry:mainCRTStartup` or the 
`L/entry:wmainCRTStartup` ?


-L/entry:mainCRTStartup


try the w one too. both doing the same result?


Re: Error: undefined symbol: _WinMain@16 When try compile no console

2022-05-19 Thread Marcone via Digitalmars-d-learn

On Thursday, 19 May 2022 at 22:13:06 UTC, Adam Ruppe wrote:

On Thursday, 19 May 2022 at 21:41:50 UTC, Marcone wrote:
Are you using the `-L/entry:mainCRTStartup` or the 
`L/entry:wmainCRTStartup` ?


-L/entry:mainCRTStartup


try the w one too. both doing the same result?


Both is doing the same result.


vibe.d requestHTTP in static this causes infinite loop?

2022-05-19 Thread Vijay Nayar via Digitalmars-d-learn
I've encountered an unusual behavior that I have no good 
explanation for. Consider the following code example:


```d
import vibe.core.log : logInfo;
import vibe.http.client : requestHTTP, HTTPClientRequest, 
HTTPClientResponse;

import vibe.http.common : HTTPMethod;
import vibe.stream.operations : readAllUTF8;

void doThing() {
  requestHTTP("http://example.com/";,
  (scope HTTPClientRequest req) {
logInfo("Setting request method.");
req.method = HTTPMethod.GET;
  },
  (scope HTTPClientResponse res) {
logInfo("Log point 1");
string data = res.bodyReader.readAllUTF8();
logInfo("Log point 2: %s", data);
  });
}

static this() {
  logInfo("--- static this() ---");
  doThing();
}

void main(string[] args) {
  logInfo("--- main() ---");
  doThing();
}
```

The output of this program is actually an infinite loop with 
output of the form:

```
[Eventcore DNS Lookup() INF] --- static this() ---
[Eventcore DNS Lookup() INF] --- static this() ---
```

If I remove the call from `static this()`, then the web call 
works as normal. Any idea why calling vibe.d's `requestHTTP` 
function inside of a module's static construction would cause an 
infinite loop?


Re: template? mixin? template mixins? for modifying a struct setup

2022-05-19 Thread Chris Katko via Digitalmars-d-learn

On Thursday, 19 May 2022 at 10:35:30 UTC, ag0aep6g wrote:

On 19.05.22 12:15, Chris Katko wrote:

given
```D
struct COLOR
{
float r, g, b, a; // a is alpha (opposite of transparency)
}

auto red   = COLOR(1,0,0,1);
auto green = COLOR(0,1,0,1);
auto blue  = COLOR(0,0,1,1);
auto white = COLOR(1,1,1,1);
//etc
```

is there a way to do:
```D
auto myColor = GREY!(0.5);
// where GREY!(0.5) becomes COLOR(0.5, 0.5, 0.5, 1.0);
```


What's wrong with a simple plain function?

COLOR grey(float rgb)
{
return COLOR(rgb, rgb, rgb, 1);
}
auto myColor = grey(0.5);


Yeah that occurred to me as I was falling asleep. Though, do I 
have to a specify


```D
static auto myColor = grey(0.5);
```
to ensure it's done at compile time? It's not the end of the 
world, but ideally, these are static / hardcoded values that can 
be used thousands of times a second.


Re: template? mixin? template mixins? for modifying a struct setup

2022-05-19 Thread Steven Schveighoffer via Digitalmars-d-learn

On 5/19/22 8:12 PM, Chris Katko wrote:

On Thursday, 19 May 2022 at 10:35:30 UTC, ag0aep6g wrote:

On 19.05.22 12:15, Chris Katko wrote:

given
```D
struct COLOR
{
float r, g, b, a; // a is alpha (opposite of transparency)
}

auto red   = COLOR(1,0,0,1);
auto green = COLOR(0,1,0,1);
auto blue  = COLOR(0,0,1,1);
auto white = COLOR(1,1,1,1);
//etc
```

is there a way to do:
```D
auto myColor = GREY!(0.5);
// where GREY!(0.5) becomes COLOR(0.5, 0.5, 0.5, 1.0);
```


What's wrong with a simple plain function?

COLOR grey(float rgb)
{
    return COLOR(rgb, rgb, rgb, 1);
}
auto myColor = grey(0.5);


Yeah that occurred to me as I was falling asleep. Though, do I have to a 
specify


```D
static auto myColor = grey(0.5);
```
to ensure it's done at compile time? It's not the end of the world, but 
ideally, these are static / hardcoded values that can be used thousands 
of times a second.


Given a CTFE function it's very easy to wrap for ensuring compile-time 
usage:


```d
enum ctGrey(float f) = grey(f);

auto myColor = ctGrey!(0.5);
```

-Steve


Re: template? mixin? template mixins? for modifying a struct setup

2022-05-19 Thread Steven Schveighoffer via Digitalmars-d-learn

On 5/19/22 8:29 PM, Steven Schveighoffer wrote:

Given a CTFE function it's very easy to wrap for ensuring compile-time 
usage:


```d
enum ctGrey(float f) = grey(f);

auto myColor = ctGrey!(0.5);
```


That being said, if it's calculatable at compile time, chances are the 
compiler is already going to do it, even for a standard constructor 
call, especially if there's no custom constructor.


-Steve


Re: vibe.d requestHTTP in static this causes infinite loop?

2022-05-19 Thread Ali Çehreli via Digitalmars-d-learn

On 5/19/22 16:44, Vijay Nayar wrote:

> If I remove the call from `static this()`, then the web call works as
> normal. Any idea why calling vibe.d's `requestHTTP` function inside of a
> module's static construction would cause an infinite loop?

I am not experienced with vibe.d.

'static this' is executed per thread. If requestHTTP starts a new 
thread, then I can see how you would be in an infinite loop. I wonder 
whether it should be 'shared static this' (which is executed once per 
program, not per thread).


Ali



Re: template? mixin? template mixins? for modifying a struct setup

2022-05-19 Thread Mike Parker via Digitalmars-d-learn

On Friday, 20 May 2022 at 00:12:44 UTC, Chris Katko wrote:

Yeah that occurred to me as I was falling asleep. Though, do I 
have to a specify


```D
static auto myColor = grey(0.5);
```
to ensure it's done at compile time? It's not the end of the 
world, but ideally, these are static / hardcoded values that 
can be used thousands of times a second.


If the declarations are at module scope, `static` has no effect, 
and CTFE will be used for initialization.


UI Library

2022-05-19 Thread harakim via Digitalmars-d-learn
I need to write a piece of software to track and categorize some 
purchases. It's the kind of thing I could probably write in a 
couple of hours in C#/Java + html/css/javascript. However, 
something keeps drawing me to D and as this is a simple 
application, it would be a good one to get back in after almost a 
year hiatus.


For this, I need a UI library to use. I need text inputs, buttons 
and that sort of thing. My My order of preference is:

1. Native component library that works on linux and windows
2. Something like SDL
3. Native component library that works on linux or windows
4. vibe.d + web

I mostly value that it works over lots of functionality and 
stability over the way the UI looks. Is there an obvious native 
application component library to use? If not, is bindbc the best 
way to go for the sdl-like option? I think I can figure out 
option Vibe.d if there are no good non-web solutions.


PS I'm surprised the forum search didn't turn up topics about 
desktop applications or UI libraries because I know I've seen 
them.


Re: UI Library

2022-05-19 Thread Craig Dillabaugh via Digitalmars-d-learn

On Friday, 20 May 2022 at 02:37:48 UTC, harakim wrote:
I need to write a piece of software to track and categorize 
some purchases. It's the kind of thing I could probably write 
in a couple of hours in C#/Java + html/css/javascript. However, 
something keeps drawing me to D and as this is a simple 
application, it would be a good one to get back in after almost 
a year hiatus.


[...]


Maybe you can use minigui from arsd

https://github.com/adamdruppe/arsd


Re: UI Library

2022-05-19 Thread harakim via Digitalmars-d-learn

On Friday, 20 May 2022 at 02:53:39 UTC, Craig Dillabaugh wrote:

On Friday, 20 May 2022 at 02:37:48 UTC, harakim wrote:
I need to write a piece of software to track and categorize 
some purchases. It's the kind of thing I could probably write 
in a couple of hours in C#/Java + html/css/javascript. 
However, something keeps drawing me to D and as this is a 
simple application, it would be a good one to get back in 
after almost a year hiatus.


[...]


Maybe you can use minigui from arsd

https://github.com/adamdruppe/arsd


Thank you. I will definitely give that a try.


Re: vibe.d requestHTTP in static this causes infinite loop?

2022-05-19 Thread bauss via Digitalmars-d-learn

On Friday, 20 May 2022 at 01:41:59 UTC, Ali Çehreli wrote:

On 5/19/22 16:44, Vijay Nayar wrote:

> If I remove the call from `static this()`, then the web call
works as
> normal. Any idea why calling vibe.d's `requestHTTP` function
inside of a
> module's static construction would cause an infinite loop?

I am not experienced with vibe.d.

'static this' is executed per thread. If requestHTTP starts a 
new thread, then I can see how you would be in an infinite 
loop. I wonder whether it should be 'shared static this' (which 
is executed once per program, not per thread).


Ali


Static constructor shouldn't be there at all in this case, since 
it's not constructing anything.


He shouldn't really use anything but main in this case.