Re: Can you access the same classes from C++ and D and vise versa, or do the classes have to not form dependency cycle?

2022-09-14 Thread Tejas via Digitalmars-d-learn
On Tuesday, 13 September 2022 at 03:13:59 UTC, Daniel Donnell, Jr 
wrote:

On Sunday, 11 September 2022 at 02:14:51 UTC, zjh wrote:
On Saturday, 10 September 2022 at 22:07:32 UTC, Ali Çehreli 
wrote:

On 9/10/22 13:04, Daniel Donnell wrote:
> https://dlang.org/spec/cpp_interface.html

At DConf, Manu indicated that that page is outdated and that 
D's C++ support is actually a lot better.



Update it quickly, This is a big selling point.


So what is the answer here?  I'm not sure what they were 
getting at...


You can

https://stackoverflow.com/a/53710273


Re: can not take const struct member address at CTFE , is this a bug?

2022-09-14 Thread Steven Schveighoffer via Digitalmars-d-learn

On 9/14/22 12:53 AM, test123 wrote:

On Wednesday, 14 September 2022 at 00:40:38 UTC, Ruby The Roobster wrote:
The addresses of items stored in memory are by definition not 
constant.  This isn't a bug.


If so why this can work ?

```d
struct c { uint a, b;}
__gshared const c d = { 3, 4};
__gshared const e = & d;
```

the `e` can get address of `d`, then it should be to get address of `d.a`


Yes, this looks like a bug. Please report if not reported already.

-Steve


Re: plot api

2022-09-14 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 14 September 2022 at 19:34:56 UTC, Alain De Vos 
wrote:

Let's say i want to plot the function f(x)=sin(x)/x.
Which API would you advice, in order for me to not re-invent 
the wheel.


Have you tried ggplotd?
https://code.dlang.org/packages/ggplotd


Building Example Project with `raylib-d`

2022-09-14 Thread jwatson-CO-edu via Digitalmars-d-learn

Hello,
I used the following steps to build the example `raylib-d` 
program. (https://github.com/schveiguy/raylib-d#example)


### Install Raylib (Ubuntu/Debian)
1. `sudo apt install libasound2-dev mesa-common-dev libx11-dev 
libxrandr-dev libxi-dev xorg-dev libgl1-mesa-dev libglu1-mesa-dev`

1. `cd /tmp`
1. `git clone https://github.com/raysan5/raylib.git raylib`
1. `cd raylib`
1. `mkdir build && cd build`
1. `cmake -DBUILD_SHARED_LIBS=ON ..`
1. `make -j2`
1. `sudo make install`
1. `sudo reboot now`

### Dlang Raylib API
1. Install Dlang
1. Navigate to project root directory
1. `mkdir source`
1. `touch source/app.d`
1. Code: https://github.com/schveiguy/raylib-d#example
1. `dub add raylib-d`
1. `dub build`

### Errors encountered
```
Performing "debug" build using /usr/bin/dmd for x86_64.
00_test ~master: building configuration "application"...
Linking...
/usr/bin/ld: 
.dub/build/application-debug-linux.posix-x86_64-dmd_v2.100.0-533EF886932B3BC59F9F09D93C0642F5/00_test.o: in function `_D6raylib7binding21validateRaylibBindingFNbNiZv':

/home/james/.dub/packages/raylib-d-4.2.0/raylib-d/source/raylib/binding.d:26: 
undefined reference to `raylibVersion'
/usr/bin/ld: 
/home/james/.dub/packages/raylib-d-4.2.0/raylib-d/source/raylib/binding.d:26: undefined reference to `raylibVersion'

collect2: error: ld returned 1 exit status
Error: linker exited with status 1
/usr/bin/dmd failed with exit code 1.
```

### Questions
There appears to be a linker problem with regards to missing 
symbols, but normally I would expect `make install` to place the 
shared libs in their proper places.

1. Have I missed an install step?
1. What are my next troubleshooting steps?


plot api

2022-09-14 Thread Alain De Vos via Digitalmars-d-learn

Let's say i want to plot the function f(x)=sin(x)/x.
Which API would you advice, in order for me to not re-invent the 
wheel.


Re: C function taking two function pointers that share calculation

2022-09-14 Thread JG via Digitalmars-d-learn

On Wednesday, 14 September 2022 at 17:23:47 UTC, jmh530 wrote:
There is a C library I sometimes use that has a function that 
takes two function pointers. However, there are some 
calculations that are shared between the two functions that 
would get pointed to. I am hoping to only need to do these 
calculations once.


[...]


Maybe others know better but I would have thought the only way is 
to use globals to do this. Often c libraries that I have used get 
round this by taking a function and a pointer and then the 
library calls your function on the pointer simulating a d 
delegate.


Re: Poste some interesting vibe.d webpages

2022-09-14 Thread Alain De Vos via Digitalmars-d-learn
Although the framework is good. There is no community. Or general 
acceptance. Which is a pitty.

Currently I ask myself how to do "sessions" with vibe.d.


C function taking two function pointers that share calculation

2022-09-14 Thread jmh530 via Digitalmars-d-learn
There is a C library I sometimes use that has a function that 
takes two function pointers. However, there are some calculations 
that are shared between the two functions that would get pointed 
to. I am hoping to only need to do these calculations once.


The code below sketches out the general idea of what I've tried 
so far. The function `f` handles both of the calculations that 
would be needed, returning a struct. Functions `gx` and `gy` can 
return the field of the struct that is relevant. Both of them 
could then get fed into the C function as function pointers.


My concern is that `f` would then get called twice, whereas that 
wouldn't be the case in a simpler implementation (`gx_simple`, 
`gy_simple`). ldc will optimize the issue away in this simple 
example, but I worry that might not generally be the case.


How do I ensure that the commonCalculation is only done once?

```d
struct Foo
{
int x;
int y;
}

Foo f(int x, int a)
{
int commonCalculation = a * x;
return Foo(commonCalculation * x, 2 * commonCalculation);
}

int gx(int x, int a) { return f(x, a).x;}
int gy(int x, int a) { return f(x, a).y;}

//int gx_simple(int x, int a) { return a * x * x;}
//int gy_simple(int x, int a) { return 2 * a * x;}

void main() {
import core.stdc.stdio: printf;
printf("the value of x is %i\n", gx(3, 2));
printf("the value of y is %i\n", gy(3, 2));
}
```


Re: C function taking two function pointers that share calculation

2022-09-14 Thread jmh530 via Digitalmars-d-learn

On Wednesday, 14 September 2022 at 18:02:07 UTC, JG wrote:

[snip]

Maybe others know better but I would have thought the only way 
is to use globals to do this. Often c libraries that I have 
used get round this by taking a function and a pointer and then 
the library calls your function on the pointer simulating a d 
delegate.


The C function does make use of a pointer to some data (that I 
neglected to mention), but your comment gives me an idea. Thanks.


Re: Building Example Project with `raylib-d`

2022-09-14 Thread Steven Schveighoffer via Digitalmars-d-learn

On 9/14/22 4:17 PM, jwatson-CO-edu wrote:

Hello,
I used the following steps to build the example `raylib-d` program. 
(https://github.com/schveiguy/raylib-d#example)


### Install Raylib (Ubuntu/Debian)
1. `sudo apt install libasound2-dev mesa-common-dev libx11-dev 
libxrandr-dev libxi-dev xorg-dev libgl1-mesa-dev libglu1-mesa-dev`

1. `cd /tmp`
1. `git clone https://github.com/raysan5/raylib.git raylib`
1. `cd raylib`
1. `mkdir build && cd build`
1. `cmake -DBUILD_SHARED_LIBS=ON ..`
1. `make -j2`
1. `sudo make install`
1. `sudo reboot now`

### Dlang Raylib API
1. Install Dlang
1. Navigate to project root directory
1. `mkdir source`
1. `touch source/app.d`
1. Code: https://github.com/schveiguy/raylib-d#example
1. `dub add raylib-d`
1. `dub build`

### Errors encountered
```
Performing "debug" build using /usr/bin/dmd for x86_64.
00_test ~master: building configuration "application"...
Linking...
/usr/bin/ld: 
.dub/build/application-debug-linux.posix-x86_64-dmd_v2.100.0-533EF886932B3BC59F9F09D93C0642F5/00_test.o: 
in function `_D6raylib7binding21validateRaylibBindingFNbNiZv':
/home/james/.dub/packages/raylib-d-4.2.0/raylib-d/source/raylib/binding.d:26: 
undefined reference to `raylibVersion'
/usr/bin/ld: 
/home/james/.dub/packages/raylib-d-4.2.0/raylib-d/source/raylib/binding.d:26: 
undefined reference to `raylibVersion'

collect2: error: ld returned 1 exit status
Error: linker exited with status 1
/usr/bin/dmd failed with exit code 1.
```

### Questions
There appears to be a linker problem with regards to missing symbols, 
but normally I would expect `make install` to place the shared libs in 
their proper places.


You built the unreleased version of raylib, where they changed the name 
of that symbol. (see 
https://github.com/raysan5/raylib/commit/082920eb800d7d7612d500a4bbc46b21ff232424)


Try `git checkout 4.2.0` on the raylib library before building, or use 
the released binary.


raylib is notorious for making breaking changes. On the next release, I 
will have to update that symbol name.


-Steve


Re: Building Example Project with `raylib-d`

2022-09-14 Thread jwatson-CO-edu via Digitalmars-d-learn
On Wednesday, 14 September 2022 at 23:42:57 UTC, Steven 
Schveighoffer wrote:

On 9/14/22 4:17 PM, jwatson-CO-edu wrote:

Hello,
I used the following steps to build the example `raylib-d` 
program. (https://github.com/schveiguy/raylib-d#example)


### Install Raylib (Ubuntu/Debian)
1. `sudo apt install libasound2-dev mesa-common-dev libx11-dev 
libxrandr-dev libxi-dev xorg-dev libgl1-mesa-dev 
libglu1-mesa-dev`

1. `cd /tmp`
1. `git clone https://github.com/raysan5/raylib.git raylib`
1. `cd raylib`
1. `mkdir build && cd build`
1. `cmake -DBUILD_SHARED_LIBS=ON ..`
1. `make -j2`
1. `sudo make install`
1. `sudo reboot now`

### Dlang Raylib API
1. Install Dlang
1. Navigate to project root directory
1. `mkdir source`
1. `touch source/app.d`
1. Code: https://github.com/schveiguy/raylib-d#example
1. `dub add raylib-d`
1. `dub build`

### Errors encountered
```
Performing "debug" build using /usr/bin/dmd for x86_64.
00_test ~master: building configuration "application"...
Linking...
/usr/bin/ld: 
.dub/build/application-debug-linux.posix-x86_64-dmd_v2.100.0-533EF886932B3BC59F9F09D93C0642F5/00_test.o: in function `_D6raylib7binding21validateRaylibBindingFNbNiZv':

/home/james/.dub/packages/raylib-d-4.2.0/raylib-d/source/raylib/binding.d:26: 
undefined reference to `raylibVersion'
/usr/bin/ld: 
/home/james/.dub/packages/raylib-d-4.2.0/raylib-d/source/raylib/binding.d:26: undefined reference to `raylibVersion'

collect2: error: ld returned 1 exit status
Error: linker exited with status 1
/usr/bin/dmd failed with exit code 1.
```

### Questions
There appears to be a linker problem with regards to missing 
symbols, but normally I would expect `make install` to place 
the shared libs in their proper places.


You built the unreleased version of raylib, where they changed 
the name of that symbol. (see 
https://github.com/raysan5/raylib/commit/082920eb800d7d7612d500a4bbc46b21ff232424)


Try `git checkout 4.2.0` on the raylib library before building, 
or use the released binary.


raylib is notorious for making breaking changes. On the next 
release, I will have to update that symbol name.


-Steve


That worked immediately, thank you! Honored to have the direct 
attention of and detailed advice from the package author.


I have the corrected install instructions below, in case someone 
finds this post while resolving the same issue:


### Install Raylib (Ubuntu/Debian)
1. `sudo apt install libasound2-dev mesa-common-dev libx11-dev 
libxrandr-dev libxi-dev xorg-dev libgl1-mesa-dev libglu1-mesa-dev`

1. `cd /tmp`
1. `git clone https://github.com/raysan5/raylib.git raylib`
1. `cd raylib`
1. **`git checkout 4.2.0`** # 2022-09-14: Or the version 
currently targeted by `raylib-d`

1. `mkdir build && cd build`
1. `cmake -DBUILD_SHARED_LIBS=ON ..`
1. `make -j2`
1. `sudo make install`
1. `sudo reboot now`

### Add Dlang Raylib API, Build, and Run
1. Install Dlang
1. Navigate to project root directory
1. `mkdir source`
1. `touch source/app.d`
1. Code: https://github.com/schveiguy/raylib-d#example
1. `dub add raylib-d`
1. `dub build`
1. `./PROJECTNAME`


Re: can not take const struct member address at CTFE , is this a bug?

2022-09-14 Thread test123 via Digitalmars-d-learn
On Wednesday, 14 September 2022 at 14:41:38 UTC, Steven 
Schveighoffer wrote:

On 9/14/22 12:53 AM, test123 wrote:
On Wednesday, 14 September 2022 at 00:40:38 UTC, Ruby The 
Roobster wrote:
The addresses of items stored in memory are by definition not 
constant.  This isn't a bug.


If so why this can work ?

```d
struct c { uint a, b;}
__gshared const c d = { 3, 4};
__gshared const e = & d;
```

the `e` can get address of `d`, then it should be to get 
address of `d.a`


Yes, this looks like a bug. Please report if not reported 
already.


-Steve


Thanks for explain.

Some how I can not create account for d Bugs,  I hope we have use 
github bugs.



Please help me create a bug report if who has free time and bugs 
account.