Re: Vibe.d v0.9.0, v0.10.0: ` dub init hello -t vibe.d` fails to build on MacOS

2024-07-07 Thread Ki Rill via Digitalmars-d-learn
On Sunday, 7 July 2024 at 23:33:59 UTC, Steven Schveighoffer 
wrote:
openssl version should be automatically determined by running a 
pre-build step.


If this doesn't work for you, please file a bug here: 
https://github.com/D-Programming-Deimos/openssl


-Steve


Filed a bug here:
https://github.com/D-Programming-Deimos/openssl/issues/112


Re: Vibe.d v0.9.0, v0.10.0: ` dub init hello -t vibe.d` fails to build on MacOS

2024-07-07 Thread Ki Rill via Digitalmars-d-learn

On Sunday, 7 July 2024 at 11:33:47 UTC, Sergey wrote:

On Sunday, 7 July 2024 at 10:55:21 UTC, Ki Rill wrote:

Machine:
```
MacBook Pro (Retina, 15-inch, Late 2013), macOS Big Sur 
version 11.7.10

```

How should I solve this? It mentions undefined symbols from 
openssl, but I have it installed. Vibe.d should link it 
automatically, right?


You can try to add to dependencies "vibe-stream:tls": "~>1.1.0"

and
```
 "subConfigurations": {
"vibe-stream:tls": "notls"
  }
```


It worked, thank you! But what does it do; disables TLS? Thread 
Local Storage?


Re: Operator "+=" overloading for class?

2023-12-20 Thread Ki Rill via Digitalmars-d-learn
On Wednesday, 20 December 2023 at 02:56:24 UTC, Steven 
Schveighoffer wrote:
Instead you are trying to reassign the `this` reference, which 
is a local (and also forbidden). Think about it a second, your 
`this + rhs` is going to allocate a *new* object. Then if the 
assignment to the local `this` parameter succeeded, what 
happens outside the member function? The true reference that is 
calling this will not be updated!


The only way to do this I can see is to reimplement for op=, or 
maybe perform the operation and swap the guts out.


-Steve


Thank you for such a detailed explanation! That does make sense.


Re: Operator "+=" overloading for class?

2023-12-18 Thread Ki Rill via Digitalmars-d-learn

On Monday, 18 December 2023 at 04:49:53 UTC, novice2 wrote:

On Monday, 18 December 2023 at 03:39:16 UTC, Ki Rill wrote:
On Sunday, 17 December 2023 at 07:05:12 UTC, Adam D. Ruppe 
wrote:

On Sunday, 17 December 2023 at 04:13:20 UTC, Ki Rill wrote:

[...]


check what `op` is. pretty sure it is "+" not "+=" so your 
element isnt' saved anywhere. also a bit iffy there isn't a 
member here to work on


Yes, op is '+'. What do you mean by it isn't saved anywhere?


your code just return result value,
but it should not return but save result to "this"
see example at 
https://dlang.org/spec/operatoroverloading.html#index_op_assignment


I get an error, but don't understand why.
```d
auto opOpAssign(string op)(Value rhs)
{
this = this + rhs;
return this;
}

// Error: `this` is not an lvalue and cannot be modified
```


Re: Operator "+=" overloading for class?

2023-12-17 Thread Ki Rill via Digitalmars-d-learn

On Sunday, 17 December 2023 at 07:05:12 UTC, Adam D. Ruppe wrote:

On Sunday, 17 December 2023 at 04:13:20 UTC, Ki Rill wrote:

[...]


check what `op` is. pretty sure it is "+" not "+=" so your 
element isnt' saved anywhere. also a bit iffy there isn't a 
member here to work on


Yes, op is '+'. What do you mean by it isn't saved anywhere? I 
tried reassigning to `this` and returning it, but it fails.


I want to achieve this, but with '+=':
```d
auto g = value(0);
g = g + value(3);

// here it should just create a new instance 'g + value(3)' and 
save it into 'g'

g += value(3);
```

Do you have an advice on how to achieve it?


Re: Operator "+=" overloading for class?

2023-12-16 Thread Ki Rill via Digitalmars-d-learn

On Sunday, 17 December 2023 at 04:15:02 UTC, Ki Rill wrote:

On Sunday, 17 December 2023 at 04:13:20 UTC, Ki Rill wrote:
I am trying to overload `opOpAssign` for my class. The code 
[...]




I forgot to mention, it is relevant to 
[`Value`](https://github.com/rillki/tiny-grad/blob/main/source/rk/tgrad/core/value.d) class only.


This unittest fails:
```d
// test opOpAssign
auto g = value(0);
g += value(3);
assert(g.data == 3);
```


Re: Operator "+=" overloading for class?

2023-12-16 Thread Ki Rill via Digitalmars-d-learn

On Sunday, 17 December 2023 at 04:13:20 UTC, Ki Rill wrote:
I am trying to overload `opOpAssign` for my class. The code 
[...]




I forgot to mention, it is relevant to 
[`Value`](https://github.com/rillki/tiny-grad/blob/main/source/rk/tgrad/core/value.d) class only.


Operator "+=" overloading for class?

2023-12-16 Thread Ki Rill via Digitalmars-d-learn
I am trying to overload `opOpAssign` for my class. The code 
compiles, but it does not seem to be working.


```d
// binary operations have already been implemented for Value
// i need +=, -=, *=, /=
auto opOpAssign(string op)(Value rhs)
{
mixin("return this" ~ op ~ "rhs;");
}

auto opOpAssign(string op)(in ElementType rhs)
{
mixin("return this" ~ op ~ "rhs;");
}
```

What am I missing here? Full project code can be found 
[here](https://github.com/rillki/tiny-grad).


Re: DlangUI: how to change AppFrames?

2023-10-26 Thread Ki Rill via Digitalmars-d-learn

On Tuesday, 24 October 2023 at 11:23:05 UTC, GrimMaple wrote:
I think there was some kind of issue when changing widgets like 
that. Please try doing this instead:

```d
window.executeInUiThread(() => window.mainWidget = 
myPreviousFrame);

```

Also, please post whole code so maybe I can fix this later


It does not work. It does accept new widgets though, but crashes 
if I try to change to the previous one.


I posted the whole code to GitHub 
[issue](https://github.com/buggins/dlangui/issues/677).


Re: DlangUI: how to change AppFrames?

2023-10-24 Thread Ki Rill via Digitalmars-d-learn

On Tuesday, 24 October 2023 at 05:03:51 UTC, Imperatorn wrote:

On Tuesday, 24 October 2023 at 04:38:58 UTC, Ki Rill wrote:

I know how to change the current AppFrame:
```D
window.mainWidget = myFrame;
```

But how do I exit this frame?

I press the button, change to new frame, do the work, and now 
I want to return to the previous frame. How would I do this?


Saving the previous frame not an option?


It crashes if I reset it to the previous one.
```d
button.click = delegate(Widget src) {
// window.mainWidget = homeLayout.child(0);
window.mainWidget = myPreviousFrame;
return true;
};

// crash
```


Re: C to D: please help translate this weird macro

2023-09-23 Thread Ki Rill via Digitalmars-d-learn

On Wednesday, 20 September 2023 at 13:53:08 UTC, Ki Rill wrote:

Here is the macro:

```C
#define NK_CONTAINER_OF(ptr,type,member)\
(type*)((void*)((char*)(1 ? (ptr): &((type*)0)->member) - 
NK_OFFSETOF(type, member)))

```

I'm trying to translate the Nuklear GUI library to D 
[here](https://github.com/rillki/nuklear-d/tree/nuklear-d-translation).


I did translate the library. Wow! That was a lot. It successfully 
builds, but does not work for long and crashes if I try to do 
something: it's either an assertion that fails or out of bounds 
array access is thrown by D. The only thing that works is 
pressing a button.


Now I need to somehow find and fix these things. Nuclear uses 
flexible array members in structs and I am a bit puzzled how to 
handle this without a major code refactor.


Re: C to D: please help translate this weird macro

2023-09-22 Thread Ki Rill via Digitalmars-d-learn

On Thursday, 21 September 2023 at 16:50:51 UTC, Imperatorn wrote:

On Wednesday, 20 September 2023 at 13:53:08 UTC, Ki Rill wrote:

Here is the macro:

```C
#define NK_CONTAINER_OF(ptr,type,member)\
(type*)((void*)((char*)(1 ? (ptr): &((type*)0)->member) - 
NK_OFFSETOF(type, member)))

```

I'm trying to translate the Nuklear GUI library to D 
[here](https://github.com/rillki/nuklear-d/tree/nuklear-d-translation).


When you're done, will you put it on dub?


Yes, I will.


Re: C to D: please help translate this weird macro

2023-09-22 Thread Ki Rill via Digitalmars-d-learn
On Thursday, 21 September 2023 at 16:28:25 UTC, Nick Treleaven 
wrote:


The 1st argument of `getMember` can just be T, like the 
original macro.

The 2nd argument needs to be a compile-time string.
Also the `char*` cast needs to apply to `ptr` before 
subtracting the offset AFAICS.


So reordering to keep type inference of `ptr`:
```d
auto nk_container_of(T, string member, P)(P ptr)
{
return cast(T*)(cast(void*)(cast(char*)ptr -
__traits(getMember, T, member).offsetof)));
}
```
(Untested)


I will test it:)


Re: C to D: please help translate this weird macro

2023-09-20 Thread Ki Rill via Digitalmars-d-learn

On Thursday, 21 September 2023 at 02:23:32 UTC, Ki Rill wrote:

wrote:

[...]


Translated it to this eventually:
```D
auto nk_container_of(P, T)(P ptr, T type, const(char)* member)
{
return cast(T*)(cast(void*)(cast(char*)
(ptr - __traits(getMember, type, member).offsetof)));
}
```


Re: C to D: please help translate this weird macro

2023-09-20 Thread Ki Rill via Digitalmars-d-learn
On Wednesday, 20 September 2023 at 17:14:41 UTC, Dejan Lekic 
wrote:

[...]

NK_CONTAINER_OF should probably be translated to:

`cast(T*)((cast(void*)ptr - __traits(getMember, T, 
member).offsetof))`


PS. I did not invent this. My original idea was far worse than 
this. - It was suggested on IRC by a much cleverer D programmer 
than myself - Herringway@IRC


Thanks! I translated it to this originally after looking at the 
links you've provided:

```D
auto nk_container_of(P, T)(P ptr, T type, size_t member_offsetof)
{
return cast(T*)(cast(void*)(cast(char*)(1 ? (ptr) : ptr - 
member_offsetof)));

}
```

`cast(T*)((cast(void*)ptr - __traits(getMember, T, 
member).offsetof))`


Now, how should I wrap it like a macro? Template mixin? I'm not 
that familiar with D meta programming... I shall skim through the 
`D templates tutorial` for hints.




Re: C to D: please help translate this weird macro

2023-09-20 Thread Ki Rill via Digitalmars-d-learn

On Wednesday, 20 September 2023 at 13:53:08 UTC, Ki Rill wrote:

Here is the macro:

```C
#define NK_CONTAINER_OF(ptr,type,member)\
(type*)((void*)((char*)(1 ? (ptr): &((type*)0)->member) - 
NK_OFFSETOF(type, member)))

```

I'm trying to translate the Nuklear GUI library to D 
[here](https://github.com/rillki/nuklear-d/tree/nuklear-d-translation).


Here is how `NK_OFFSETOF` is defined:
```c
#define NK_OFFSETOF(st,m) ((nk_ptr)&(((st*)0)->m))
```


C to D: please help translate this weird macro

2023-09-20 Thread Ki Rill via Digitalmars-d-learn

Here is the macro:

```C
#define NK_CONTAINER_OF(ptr,type,member)\
(type*)((void*)((char*)(1 ? (ptr): &((type*)0)->member) - 
NK_OFFSETOF(type, member)))

```

I'm trying to translate the Nuklear GUI library to D 
[here](https://github.com/rillki/nuklear-d/tree/nuklear-d-translation).


Re: Which function returns a pair after division ? (integer,frac)

2023-09-18 Thread Ki Rill via Digitalmars-d-learn
On Tuesday, 19 September 2023 at 03:44:18 UTC, Vitaliy Fadeev 
wrote:

What D function or D operator does this?

```asm
IDIV EAX, r/m32
```

```
IDIV 5, 2
 EAX = 2
 EDX = 1
```

and returns (2,1) at once?


You can either use function `out` parameters with return value or 
`tuples`:

```D
import std.typecons;

// with tuples
auto getVal(int a, int b) {
// ...
return tuple(integer, frac);
}

// out params
int getVal2(int a, int b, out int frac) {
// ...

frac = _fraq;
return integer;
}

// USAGE
{
// with tuples
auto v = getVal(5, 2);
assert(v[0] == 2);
assert(v[1] == 1);

// with out params
int frac;
int integer = getVal2(5, 2, frac);
assert(integer == 2);
assert(frac == 1);
}

```


Re: Mir-algorithm tutorial?

2023-08-18 Thread Ki Rill via Digitalmars-d-learn

On Friday, 18 August 2023 at 09:32:31 UTC, Ferhat Kurtulmuş wrote:
I believe the most recent docs for mir-algorithm is here 
http://mir-algorithm.libmir.org/


Thanks. Yes, that's the only thing.

However, it's not a good starting point for someone who just 
wants to get to know the library and play around...


Re: Mir-algorithm tutorial?

2023-08-18 Thread Ki Rill via Digitalmars-d-learn

On Friday, 18 August 2023 at 07:57:05 UTC, Ki Rill wrote:

On Friday, 18 August 2023 at 07:54:04 UTC, Ki Rill wrote:

Is there an up-to-date tutorial?

It's just painful that I cannot find anything helpful on this 
topic. The official mir-algorithm GitHub repo links to 
articles with old code that won't build if I copy-paste it. 
I'm left hunting down the changes and guessing how things 
should really work.


[API documentation](http://docs.algorithm.dlang.io) link about 
mir-algorithm from [dlang 
tour](https://tour.dlang.org/tour/mir/dub/mir-algorithm) does 
not work.


I opened the 
[issue](https://github.com/dlang-tour/core/issues/788).


Re: Mir-algorithm tutorial?

2023-08-18 Thread Ki Rill via Digitalmars-d-learn

On Friday, 18 August 2023 at 07:54:04 UTC, Ki Rill wrote:

Is there an up-to-date tutorial?

It's just painful that I cannot find anything helpful on this 
topic. The official mir-algorithm GitHub repo links to articles 
with old code that won't build if I copy-paste it. I'm left 
hunting down the changes and guessing how things should really 
work.


[API documentation](http://docs.algorithm.dlang.io) link about 
mir-algorithm from [dlang 
tour](https://tour.dlang.org/tour/mir/dub/mir-algorithm) does not 
work.


Mir-algorithm tutorial?

2023-08-18 Thread Ki Rill via Digitalmars-d-learn

Is there an up-to-date tutorial?

It's just painful that I cannot find anything helpful on this 
topic. The official mir-algorithm GitHub repo links to articles 
with old code that won't build if I copy-paste it. I'm left 
hunting down the changes and guessing how things should really 
work.


Re: On assigning const to immutable

2023-07-13 Thread Ki Rill via Digitalmars-d-learn

On Thursday, 13 July 2023 at 11:55:17 UTC, Ki Rill wrote:
Why does the first example `class A` work, but the second one 
with `class B` does not?

```D
class A {
immutable int a;
this(in int a) {
this.a = a;
}
}

class B {
immutable int[] b;
this(in int[] b) {
this.b = b;
}
}

void main()
{
auto a = new A(1);
auto b = new B([1, 2]);
}
```

It implicitly converts `const` to `immutable`, but fails to do 
the same with an array. Is it intentional? Why?


Oh, is it because the first one is passed by value, but the 
second one is a reference?


On assigning const to immutable

2023-07-13 Thread Ki Rill via Digitalmars-d-learn
Why does the first example `class A` work, but the second one 
with `class B` does not?

```D
class A {
immutable int a;
this(in int a) {
this.a = a;
}
}

class B {
immutable int[] b;
this(in int[] b) {
this.b = b;
}
}

void main()
{
auto a = new A(1);
auto b = new B([1, 2]);
}
```

It implicitly converts `const` to `immutable`, but fails to do 
the same with an array. Is it intentional? Why?


Re: Designated initializers to function argument

2023-07-11 Thread Ki Rill via Digitalmars-d-learn

On Tuesday, 11 July 2023 at 15:16:54 UTC, Ki Rill wrote:

```D

// or this
apply(Appearance(color: BLACK, strokeWidth: 4)); // other 
fields are default initialized: strokeOpacity, fillOpacity, 
etc...


```


Ok, this works with DMD v2.103, but does not work with an older 
version (I had ldc2 installed based on DMD v2.98).


Designated initializers to function argument

2023-07-11 Thread Ki Rill via Digitalmars-d-learn

In C I can do the following:
```C
void apply(struct Appearance a) {...}

// usage
apply((struct Appearance) {
.color = BLACK,
.strokeWidth = 4
});
```

Can I do the same in D without creating a struct variable 
separately?

```D
void apply(Appearance a) {...}

// currently accepts
Appearance a = { color: BLACK, strokeWidth: 4 };
apply(a);

// would like this
apply({ color: BLACK, strokeWidth: 4 });

// or this
apply(Appearance(color: BLACK, strokeWidth: 4)); // other fields 
are default initialized: strokeOpacity, fillOpacity, etc...


```


Re: How to setup dub project for contributing to a dub package?

2023-06-23 Thread Ki Rill via Digitalmars-d-learn
On Friday, 23 June 2023 at 15:52:44 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
First things first, dcv is added to the dub-registry, so use 
this.


https://code.dlang.org/packages/dcv

```json
"dependencies": {
"dcv": "~>0.3.0"
}
```

For ffmpeg the binding tells you what to add for search paths 
in the lflags directive.


https://github.com/ljubobratovicrelja/ffmpeg-d#adding-to-dub

All I can suggest is make sure you have the right dev packages 
for ffmpeg installed and findable by the linker.


It works fine if I add it as a `dub` package, but I want to add 
the repository so I can modify it, then test it on a new project, 
and make a PR that improves the package.


How do people usually set up their projects for such tasks?


How to setup dub project for contributing to a dub package?

2023-06-23 Thread Ki Rill via Digitalmars-d-learn
Recently, I tried to set up `dcv` with `dub` to improve a few 
things in the library, but I faced some strange issues.


When doing `dub add dcv`, it works fine. But when I try to add a 
local dcv project folder, or a repository, it fails to link the 
necessary package libraries. Seems like it's only `ffmpeg` 
libraries that are not linked.


What am I missing here?

```
// dub.json

...

"dependencies": {
"dcv": {
"repository": "git+https://github.com/rillki/dcv.git";,
"version": "~master"
}
},

...
```

Output:
```
Undefined symbols for architecture x86_64:
  "_av_free_packet", referenced from:
  
__D3dcv7videoio5input11InputStream13readFrameImplMFNbNiKCQCc4core5image5ImageZb in libdcv.a(input_2c65_47c.o)
  
__D3dcv7videoio6output12OutputStream__T10writeSliceTS3mir7ndslice5slice__T9mir_sliceTPhVmi2VEQBoQBnQBi14mir_slice_kindi2ZQBvZQDiMFNbNiQDeEQFf4core5image11ImageFormatZb in libdcv.a(output_2c76_14e7.o)
  
__D3dcv7videoio6output12OutputStream__T10writeSliceTS3mir7ndslice5slice__T9mir_sliceTPhVmi3VEQBoQBnQBi14mir_slice_kindi2ZQBvZQDiMFNbNiQDeEQFf4core5image11ImageFormatZb in libdcv.a(output_2c74_14e8.o)

  "_av_register_all", referenced from:
  __D3dcv7videoio6common9AVStarter6__ctorMFNbNiZCQBsQBrQBmQBi 
in libdcv.a(common_2c56_37c.o)

  "_avcodec_decode_video2", referenced from:

  ETC

ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to 
see invocation)

Error: linker exited with status 1
Error dmd failed with exit code 1.
```


Re: How do I generate `setX` methods for all private mutable variables in a class?

2023-06-06 Thread Ki Rill via Digitalmars-d-learn

On Monday, 5 June 2023 at 18:54:30 UTC, cc wrote:

[...]


Is there a way to check for mutability as well? I have both 
immutable and mutable fields. I would like to generate setters 
for mutable fields only.





Re: How do I generate `setX` methods for all private mutable variables in a class?

2023-06-05 Thread Ki Rill via Digitalmars-d-learn

On Monday, 5 June 2023 at 18:54:30 UTC, cc wrote:

On Monday, 5 June 2023 at 13:57:20 UTC, Ki Rill wrote:
How do I generate `setX` methods for all private mutable 
variables in my class? Do I need to use `__traits`?


```d
mixin template GenerateSetters() {
	static foreach (idx, field; typeof(this).tupleof) static if 
(__traits(getVisibility,field) == "private") {

mixin(q{
void %SETTER(typeof(this.tupleof[idx]) _) {
%NAME = _;
}
}
.replace("%NAME", field.stringof)
			.replace("%SETTER", "set"~toUpper(field.stringof[0..1]) ~ 
field.stringof[1..$])

);
}
}
class Rectangle {
private Color fillColor;
private Color strokeColor;
private uint strokeWidth;

this(int x, int y) {}

mixin GenerateSetters;
}

void main() {
auto rect = new Rectangle(0, 0);
rect.setStrokeWidth(4);
assert(rect.strokeWidth == 4);
}
```


Thank you! That is exactly what I needed. Although another 
solution provided by Basile B. using attributes opens a door for 
other posibilities...


I don't usually use metaprogramming or code generation much, this 
is an eye-opening experience.


How do I generate `setX` methods for all private mutable variables in a class?

2023-06-05 Thread Ki Rill via Digitalmars-d-learn
How do I generate `setX` methods for all private mutable 
variables in my class? Do I need to use `__traits`?


I need this for my [tiny-svg](https://github.com/rillki/tiny-svg) 
project to generate `setX` methods for all Shapes.


Example:
```D
class Rectangle {
private immutable ...;
private Color fillColor;
private Color strokeColor;
private uint strokeWidth;

this(int x, int y) {...}

mixin(???);

// I need this:
Rectangle setFillColor(Color color) {...}
Rectangle setStrokeColor(Color color) {...}
Rectangle setStrokeWidth(uint color) {...}
}
```

Usage:
```D
new Rectangle(10, 10)
.setFillColor(Colors.white)
.setStrokeColor(Colors.black)
.setStrokeWidth(3);
```


Re: How to setup D with SFML? (using bindbc-sfml)

2023-04-14 Thread Ki Rill via Digitalmars-d-learn

On Friday, 14 April 2023 at 02:33:18 UTC, Salih Dincer wrote:

On Friday, 14 April 2023 at 00:28:53 UTC, Ki Rill wrote:

```
LINK : fatal error LNK1104: cannot open file 'libucrt.lib'
Error: linker exited with status 1104
```

Why does it require this library and where can I find it?


Since this library is a component of the Microsoft C Runtime 
(CRT) library, you may need to install this library.


To install the CRT library, follow these steps:

* Download and install the latest version of Microsoft Visual 
Studio.
* In the Visual Studio installer, install the "C++ Universal 
CRT" component under "Workloads > Desktop development with C++".

* Restart the build and check if the error is resolved.

**Source:** 
https://stackoverflow.com/questions/44763817/link-fatal-error-lnk1104-cannot-open-file-ucrt-lib


SDB@79


Yay! That worked! Now I have a working example. Though it's 
strange that it does not work with shared libs.


Re: How to setup D with SFML? (using bindbc-sfml)

2023-04-13 Thread Ki Rill via Digitalmars-d-learn

On Wednesday, 12 April 2023 at 10:05:14 UTC, Salih Dincer wrote:

On Tuesday, 11 April 2023 at 10:24:09 UTC, Ki Rill wrote:
If you wanted static I would add and run libraries easy, like 
this:

```Json
"libs": [
"csfml-audio",
"csfml-graphics"
],
"versions": [
"SFML_Audio",
"SFML_Graphics",
"BindSFML_Static",
]
}
```
In summary, DUB takes care of everything for us. It should be 
same in W$...


SDB@79


I tried static. It did not work. Now it gives me this error:
```
LINK : fatal error LNK1104: cannot open file 'libucrt.lib'
Error: linker exited with status 1104
```

Why does it require this library and where can I find it?


Re: How to setup D with SFML? (using bindbc-sfml)

2023-04-11 Thread Ki Rill via Digitalmars-d-learn
On Tuesday, 11 April 2023 at 11:55:50 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
I have to ask this since nothing else has worked and the dll's 
on the site don't depend on a MSVC dll:


What are you compiling your program as? 32bit/64bit x86? ARM?

Which DLL's are you downloading? 32bit, 64bit?


I uses the default settings. DUB should compile my project as 
64bit on Windows 10. The bindings I downloaded are also 64bit. 
The links mentioned in my previous post is what I use.


Re: How to setup D with SFML? (using bindbc-sfml)

2023-04-11 Thread Ki Rill via Digitalmars-d-learn

On Sunday, 9 April 2023 at 14:20:30 UTC, Mike Parker wrote:
I've tried your project out two ways, one that succeeds and one 
that fails. I'm guessing you've put your 'libs' directory is 
'bin/libs'. Am I right? If so, then the following should help 
you.



Well, `bin/` and `libs/` are in the same directory.

When dub runs the exectuable, it sets the current working 
directory to the project's root directory by default. 
`setCustomLoaderPath` passes whatever you give it directly to 
the system API unmodified. You've passed a relative path. By 
default, the system API associates relative paths with the 
current working directory.


So given a project root directory of `$ROOT`, and your 
executable in `$ROOT/bin`, the system is looking for the 
libraries in `$ROOT/libs` and *not* in `$ROOT/bin/libs`. If the 
libs are in the former, everything loads. If they're in the 
latter, then it's going to fail.


If you cd into `bin` and run the executable manually, then libs 
in `$ROOT/bin/libs` will load, as your current working 
directory is `bin`.


The quick fix for this is to add `"workingDirectory" : "bin"` 
to your dub.json. Then your relative paths will be relative to 
`$ROOT/bin/`.




I tried `bin/libs/` as well as you describe here. It did not work.

---

Actually, it is quite strange that it fails to load the 
[CSFML](https://www.sfml-dev.org/download/csfml/) library dlls in 
`libs/` (I download CSFML2.5) since that is what I do with 
[GLFW/OpenGL](https://github.com/rillki/d-glfw-opengl-project-template) example as well for Windows 10.


**Even this fails: `loadSFMLGraphics("libs/csfml-graphics.dll")`**

I have the following structure:
```
- bin/
- libs/
- source/
- dub.json
- dub.selections.json
```

My `dub.json`:
```Json
{
"authors": [
"rillki"
],
"copyright": "Copyright © 2023, rillki",
"dependencies": {
"bindbc-sfml": "~>1.0.2"
},
"description": "D/SFML project template",
"license": "BSL",
"name": "d-sfml-project-template",
"targetPath": "bin",
"versions": [
"SFML_Audio",
"SFML_Graphics",
"SFML_Network",
"SFML_System",
"SFML_Window",
"SFML_250"
]
}
```

My `source/app.d`:
```d
module app;

import std.stdio: writeln;
import bindbc.sfml;

void main() {
version(Windows) {
import bindbc.loader;
setCustomLoaderSearchPath("libs");
}

// attempt at loading sfml
if(!loadSFML()) {
writeln("Failed to load SFML library!");
return;
}

// window dimensions
enum width = 720;
enum height = 480;
enum title = "D/SFML project";

// create window
auto window = sfWindow_create(sfVideoMode(width, height), 
title.toStringz, sfWindowStyle.sfDefaultStyle, null);

scope(exit) { sfWindow_destroy(window); }

while(sfWindow_isOpen(window)) {
// process events
sfEvent event;
while(sfWindow_pollEvent(window, &event)) {
if(event.type == sfEventType.sfEvtClosed) {
sfWindow_close(window);
}
}

// ...
}
}

```

I will try to make it work... Meanwhile, if someones spots what I 
am doing wrong, please reply to this post.


Re: How to setup D with SFML? (using bindbc-sfml)

2023-04-09 Thread Ki Rill via Digitalmars-d-learn

On Saturday, 8 April 2023 at 23:40:32 UTC, Mike Parker wrote:

On Saturday, 8 April 2023 at 11:31:40 UTC, Ki Rill wrote:
How do I set up a D and SFML project using the `bindbc-sfml` 
package?


I tried following the instructions, it builds successfully, 
but fails to load the SFML library at runtime.


In particular, `loadSFML, loadSFMLGraphics, loadSFMLXXX` 
fails. Here is 
[link](https://github.com/rillki/d-sfml-project-template) to 
the repo. I plan to create another how-to video, but I cannot 
find what's causing it to fail.


Do you have any ideas?


Not without error messages. The first thing you should do is 
use the error API in bindbc.loader to print them out. That 
should tell you what the problem is.


I forgot about that). Here are the errors that occur on Windows:
```
csfml-system.dll, The specified module could not be found.
csfml-audio.dll, The specified module could not be found.
csfml-audio-2.dll, The specified module could not be found.
csfml-audio-2.0.dll, The specified module could not be found.
```

Why can't it find these libraries? I tell where to look for them:
```D
version(Windows) {
import bindbc.loader;
setCustomLoaderSearchPath("libs"); // tried using absolute 
path as well

}
```

That is strange...


How to setup D with SFML? (using bindbc-sfml)

2023-04-08 Thread Ki Rill via Digitalmars-d-learn
How do I set up a D and SFML project using the `bindbc-sfml` 
package?


I tried following the instructions, it builds successfully, but 
fails to load the SFML library at runtime.


In particular, `loadSFML, loadSFMLGraphics, loadSFMLXXX` fails. 
Here is [link](https://github.com/rillki/d-sfml-project-template) 
to the repo. I plan to create another how-to video, but I cannot 
find what's causing it to fail.


Do you have any ideas?


Re: Failed to archive JPEG (ArchiveMember): Invalid UTF-8 sequence (at index 1)

2023-01-13 Thread Ki Rill via Digitalmars-d-learn

On Saturday, 14 January 2023 at 01:13:33 UTC, Adam D Ruppe wrote:

On Saturday, 14 January 2023 at 01:08:25 UTC, Ki Rill wrote:

a JPEG image.


member.expandedData(file.readText().dup().representation());


A jpeg image is not a text file. Read it with `std.file.read()` 
instead of `readText`. Then you can get rid of those useless 
dup.representation calls too.


Thank you for such a quick reply! It solved my issue!


Failed to archive JPEG (ArchiveMember): Invalid UTF-8 sequence (at index 1)

2023-01-13 Thread Ki Rill via Digitalmars-d-learn
Please, help me solve the annoying error above. I've been 
refactoring and rewriting code for my archive utility called 
[zippo](https://github.com/rillki/zippo) and I face this error 
when it tries to archive a JPEG image.


I tracked it down to the following function that helps me add a 
new member to `ZipArchive`.


```D
void zipAddArchiveMember(ref ZipArchive zip, in string file) {
import std.conv: to;
import std.file: readText;
import std.string: representation;

ArchiveMember member = new ArchiveMember();
member.name = file;
writefln("%s", file);
member.expandedData(file.readText().dup().representation());
member.compressionMethod = CompressionMethod.deflate;
zip.addMember(member);
}
```

Am I missing something?



Re: DUB: How to link an external library on Windows 10?

2021-08-27 Thread Ki Rill via Digitalmars-d-learn
On Friday, 27 August 2021 at 15:24:14 UTC, Steven Schveighoffer 
wrote:
I suspect your MSVC installation is bad, or there are some 
other switches causing problems.


-Steve


Hmm... well, I will use the default setup and think about it 
later.


I mostly use Linux, Windows realm is an uncharted territory for 
me.


Re: DUB: How to link an external library on Windows 10?

2021-08-27 Thread Ki Rill via Digitalmars-d-learn

On Friday, 27 August 2021 at 14:52:15 UTC, Mike Parker wrote:

On Friday, 27 August 2021 at 14:46:56 UTC, Ki Rill wrote:
On Friday, 27 August 2021 at 13:54:18 UTC, Steven 
Schveighoffer wrote:

[...]


How do I tell DUB where to look for `raylibdll.lib` and 
`raylib.dll`? Via `lflags` section? What if I put them in a 
different folder instead of the project's directory?


Yes. The path goes in the lflags directive using whatever the 
linker-specific flag is. I assume for lld it's `-Lpath`. For MS 
link it's `/LIBPATH:path`.


I've added lfags:
```
"lflags": 
["/LIBPATH:C:\\Users\\Username\\Desktop\\test\\source\\"]

```

But now it cannot find the following:
```
msvcrt120.lib
OLDNAMES.lib
shell32.lib
```

I think `lfags` overrides the default search path and I need to 
add it manually as well. But what is that path on Windows?


Re: DUB: How to link an external library on Windows 10?

2021-08-27 Thread Ki Rill via Digitalmars-d-learn
On Friday, 27 August 2021 at 13:54:18 UTC, Steven Schveighoffer 
wrote:

[...]


How do I tell DUB where to look for `raylibdll.lib` and 
`raylib.dll`? Via `lflags` section? What if I put them in a 
different folder instead of the project's directory?


Re: DUB: How to link an external library on Windows 10?

2021-08-27 Thread Ki Rill via Digitalmars-d-learn

On Friday, 27 August 2021 at 13:54:25 UTC, Mike Parker wrote:
But assuming you are on a 64-bit system, the DMD will use 
Visual Studio's linker if you have it installed. If you don't, 
it will use the lld linker it ships with. Either way, you need 
to raylib to be compiled with he same version of the MS Build 
tools so that you don't have conflicts the the vs runtime.


Indeed, DMD used the lld linker.


Re: DUB: How to link an external library on Windows 10?

2021-08-27 Thread Ki Rill via Digitalmars-d-learn
On Friday, 27 August 2021 at 13:54:18 UTC, Steven Schveighoffer 
wrote:
In the end, I got it to build and run, but I'd highly recommend 
just linking against the `raylibdll.lib` and using the dll.


-Steve


Steve, thank you! I got it working with `raylibdll.lib`!

SOLUTION:
1. `dub init`

2. `dub add raylib-d`

3. download `raylib` pre-compiled 
[binaries](https://github.com/raysan5/raylib/releases) for 
Microsoft Visual Studio (msvs)


4. put `raylib.dll` and `raylibdll.lib` into your project's 
folder (into the same directory, where you have `dub.json`)


5. add `"libs":["raylibdll"]` section into dub.json

Compile and run. It should work.


Re: DUB: How to link an external library on Windows 10?

2021-08-27 Thread Ki Rill via Digitalmars-d-learn

On Friday, 27 August 2021 at 13:33:25 UTC, Mike Parker wrote:

On Friday, 27 August 2021 at 13:21:04 UTC, Ki Rill wrote:
I have a Raylib project on Windows using DUB. I've added 
raylib-d via `dub add`. But what I can't figure out is how to 
tell DUB to link against raylib library.


I have the following project structure:
```
-> source
---> app.d
-> libraylib.a
-> raylib.dll
-> etc...
```

I'd like to use either .a or .dll. Do you have any ideas?


raylib.a isn't going to get you anywhere. You'll run into 
issues mixing MinGW-compiled libraries.


If raylib doesn't ship precompiled VS binaries, then, assuming 
you have Visual Studio (or the MS Build tools) installed, you 
should compile Raylib with that same version. Then you'll have 
a new raylib.dll and a raylib.lib. Add raylib.lib to your dub 
config via the "libs" directive.


I have downloaded the pre-compiled binaries from the official 
[Raylib ](https://github.com/raysan5/raylib/releases/tag/3.7.0) 
repo.


I'm not using Visual Studio. Only dub and a text editor.


DUB: How to link an external library on Windows 10?

2021-08-27 Thread Ki Rill via Digitalmars-d-learn
I have a Raylib project on Windows using DUB. I've added raylib-d 
via `dub add`. But what I can't figure out is how to tell DUB to 
link against raylib library.


I have the following project structure:
```
-> source
---> app.d
-> libraylib.a
-> raylib.dll
-> etc...
```

I'd like to use either .a or .dll. Do you have any ideas?