How to use ImportC to import WebGPU header

2024-01-10 Thread JN via Digitalmars-d-learn
I would like to use ImportC to automatically import a C header 
into my D project. I've been using Dstep so far which works ok, 
but requires some manual fixes to get the resulting D file to 
compare and it doesn't let me to just drop the C header file.


I created a fresh dub project to try. I try to import this header 
https://github.com/webgpu-native/webgpu-headers/blob/main/webgpu.h . I put webgpu.h file next to app.d.


My code is:

```
import std.stdio;
import webgpu;

void main()
{
}
```

it builds.

Then I tried to output one of the enums to see if it works:

```
import std.stdio;
import webgpu;

void main()
{
writeln(WGPUBlendFactor_Dst);
}
```

and it says:

Starting Performing "debug" build using 
C:\D\dmd2\windows\bin64\dmd.exe for x86_64.
Building test_importd ~master: building configuration 
[application]
source\app.d(6,10): Error: undefined identifier 
`WGPUBlendFactor_Dst`

Error C:\D\dmd2\windows\bin64\dmd.exe failed with exit code 1.

I tried to do the other commandline but I get this error instead:

C:\Users\haxx\Desktop\dev\test_importd\source>dmd -c webgpu.c 
-Hf=webgpu.di

C:\D\dmd2\windows\bin64\..\..\src\druntime\import\importc.h(134): 
fatal error C1034:

sal.h: no include path set
Error: C preprocess command C:\Program Files (x86)\Microsoft 
Visual

Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe failed for file

webgpu.c, exit status 2





Re: raylib wasm soon^tm

2023-12-30 Thread JN via Digitalmars-d-announce

On Saturday, 30 December 2023 at 07:13:25 UTC, monkyyy wrote:

https://monkyyy.itch.io/test-wasm-missle-command

https://github.com/crazymonkyyy/raylib-2024

(press f9 to change color scheme)

Nearly done with my alpha todo list, schvelguy got it working 
on windows,

so thats 3 platforms, windows(wishywashy rn), linux, wasm

For what its worth I live-streamed some of it 
https://www.youtube.com/watch?v=ogFI2hu98wI;


see examples folder for target syntax and style
see readme contributing on contributing

Its a mess, its pre-alpha, but its nearing the point of useful 
wasm


No Windows support shouldn't be such a big deal. If you have WASM 
working, you can just wrap your WASM game in NW.js or Electron to 
make a standalone app.


WASM - Passing JS objects to D

2023-07-25 Thread JN via Digitalmars-d-learn
What is the recommended way to pass JS objects to D when doing 
WASM?


My current solution is to maintain an ID <-> object mapping in 
JS, something like:


const mapJsToHandle = new WeakMap();
const mapHandleToJs = {};
var id = 0;

const toHandle = (x) => {
if (!mapJsToHandle.has(x))
{
id++;
mapJsToHandle.set(x, id);
mapHandleToJs[id] = new WeakRef(x);
return id;
} else {
return mapJsToHandle.get(x);
}
};

const fromHandle = (x) => {
return mapHandleToJs[x].deref();
};

which I can use like:

const drawJS = (imghandle, x, y) => {
document.ctx.drawImage(fromHandle(imghandle), x, y);
}

var img = new Image();
drawImage(toHandle(img))


D code

extern(C) void drawImage(int imghandle)
{
draw(imghandle, 100, 100);
}

void drawJS(int imghandle, double x, double y);



This works. But I wonder if there's some easier/better way? If I 
understand correctly you can only pass primitive objects and 
arrays across the boundaries.




Re: Make IN Dlang

2022-11-02 Thread JN via Digitalmars-d-learn
On Tuesday, 1 November 2022 at 23:40:22 UTC, Christian Köstlin 
wrote:

 sh("touch %s".format(t.name));


One of the problems of many Make-like tools is that they offer 
lots of freedom, especially when allowing you to launch arbitrary 
shell commands. But this also comes with drawbacks, because this 
touch command will instantly break Windows builds, might also be 
a problem on some non-Linux platforms like macOS. Declarative 
approach from tools like dub might be restrictive, but it also 
lets me as a user know that I can download an arbitrary dub 
project and 99% chance it will just compile out of the box on 
Windows.


Re: Release D 2.100.2

2022-11-01 Thread JN via Digitalmars-d-announce

On Sunday, 11 September 2022 at 08:34:40 UTC, Martin Nowak wrote:

Glad to announce D 2.100.2, ♥ to the 18 contributors.

http://dlang.org/download.html

This point release fixes a few issues over 2.100.2, see the 
changelog for more details.


http://dlang.org/changelog/2.100.2.html

-Martin


Windows is showing SmartScreen warnings when trying to run the 
Windows installer. Also, the installed version reports as 
v2.100.2-dirty.


Re: How do I correctly install packages for use with Visual Studio?

2022-10-17 Thread JN via Digitalmars-d-learn

On Sunday, 16 October 2022 at 11:09:31 UTC, Decabytes wrote:
It's a double whammy because I've never used Visual Studio 
before (Just an Emacs Guy), but I need to debug my D 
programming and according to the 
[documentation](https://wiki.dlang.org/Debuggers) this is my 
only option on Windows.


I am using Visual Studio Code with code-d plugin and using the 
standard C++ debugger. Seems to work well enough. Some D-specific 
constructs like AA look weird at times, but breakpoints work, 
shows me values of variables, callstacks.


Re: A New Game Written in D

2022-05-18 Thread JN via Digitalmars-d-announce

On Tuesday, 17 May 2022 at 16:36:34 UTC, Kenny Shields wrote:

Hello,

I've been building a game engine in D for the past 2 and a half 
years and have finally reached a point where it's usable in 
day-to-day game development. Earlier this year I decided to 
make a simple shooter game to serve as a tech demo for the 
engine's capabilities, and also just to get a general idea of 
how well it works when used in a real application. I did an 
initial release of the game yesterday on itch.io, you can find 
more information on the product page if you are interested: 
https://kenny-shields.itch.io/untitled-shooter-game


Looks great! I used to make a game in a similar style, but never 
really got further than having a guy walking around: 
https://www.youtube.com/watch?v=kgIUXiFuJkc





Re: IntelliJ D Language support

2022-05-13 Thread JN via Digitalmars-d-announce

On Thursday, 12 May 2022 at 03:32:01 UTC, Walter Bright wrote:

Now on front page of hackernews!

https://news.ycombinator.com/news


Last time I used IntelliJ plugin it looked interesting but was 
unusuable because of 
https://github.com/intellij-dlanguage/intellij-dlanguage/issues/455 . I will have to give it a try again and see if it's fixed.


How to make a generic function to take a class or struct by reference?

2022-03-27 Thread JN via Digitalmars-d-learn
I would like to have only one definition of getX if possible, 
because they both are doing the same thing. I can't remove the 
ref one, because without a ref it will pass the struct as a 
temporary and compiler won't like that.


```d
import std.stdio;

struct Foo
{
int x;

void doStuff()
{
*getX(this) = 5;
}
}

class Bar
{
int x;

void doStuff()
{
*getX(this) = 5;
}
}

int* getX(T)(ref T t)
{
return 
}

int* getX(T)(T t)
{
return 
}

void main()
{
Foo foo;
Bar bar = new Bar();

foo.doStuff();
bar.doStuff();

assert(foo.x == 5);
assert(bar.x == 5);
}
```


Re: The DIID series (Do It In D)

2022-01-26 Thread JN via Digitalmars-d-announce
On Wednesday, 26 January 2022 at 08:00:53 UTC, Ola Fosheim 
Grøstad wrote:
On Tuesday, 25 January 2022 at 08:44:34 UTC, Guillaume Piolat 
wrote:

I always read "How good really is X?" as "this is bad"
and "How bad really is X?" as "this is good"


Yes, I think that is pretty universal. Didn't feel anything was 
wrong with the title, but the fact that most examples used 
"arsd" gave me the impression that there was only one good 
library…


I feel like some examples, for example JSON one could use some 
explanation, why not just use std.json.


Re: Improve a simple event handler

2022-01-16 Thread JN via Digitalmars-d-learn

On Saturday, 15 January 2022 at 23:15:16 UTC, JN wrote:


Is there some way I could improve this with some D features? My 
main gripes with it are:




Managed to dramatically simplify it to 10 lines of code with 
variadic templates.


```d
import std.stdio;

struct Event(T...)
{
void function(T)[] listeners;

void addListener(void function(T) handler)
{
listeners ~= handler;
}

void emit(T args)
{
foreach (listener; listeners)
{
listener(args);
}
}
}

void onResize(uint newWidth, uint newHeight)
{
writefln("Resized: %d %d", newWidth, newHeight);
}

void main()
{
Event!(uint, uint) windowResizeEvent;
windowResizeEvent.addListener();

windowResizeEvent.emit(1000, 2000);
}
```

I am very happy with this solution.


Improve a simple event handler

2022-01-15 Thread JN via Digitalmars-d-learn

I am writing a simple event handler object for observer pattern.

https://gist.github.com/run-dlang/d58d084752a1f65148b33c796535a4e2

(note: the final implementation will use an array of listeners, 
but I want to keep it simple for now and have only one handler 
per event).


Is there some way I could improve this with some D features? My 
main gripes with it are:


1) generic typing. I wish event handler methods such as onResize 
and onWindowTitle could take concrete types like WindowResize and 
WindowTitle rather than the generic Event struct.


2) same when emitting the event. It feels a bit verbose.

I don't want to use classes or polymorphism. I was thinking 
perhaps std.variant could be useful here, although I am not 
exactly sure how it would work in practice.


Re: dmt: Python-like indentation in D programming language

2021-11-17 Thread JN via Digitalmars-d-announce
On Tuesday, 16 November 2021 at 21:58:24 UTC, Witold Baryluk 
wrote:

Hi,

`dmt` is an old project of mine from around year 2006. I ported 
it recently from D1 to D2, and added some extra features and 
support for extra keywords, and fixed few bugs here and there.


`dmt` is a converter (offline or auto-invoking compiler after 
conversion) from Python-like indention style to curly braces 
for D programming language.




I love the idea. Never been a fan of braces to define blocks and 
I find them to be much more of a pain to match than whitespace. 
These days however, I just set dfmt to autorun on file save and 
never worry about formatting again.


Re: D Language Foundation Quarterly Meeting, October 2021

2021-11-06 Thread JN via Digitalmars-d-announce

On Friday, 5 November 2021 at 13:19:24 UTC, zjh wrote:

D can aim at `experts`, especially `meta programming users`.
On this point,`rust` can't compete.
`Silky general meta programming`.
Use my `strengths` to attack theirs weaknesses.



This is much less of a strength than you think. For 90% of cases, 
lack of metaprogramming is resolved by putting a Python script in 
build step that autogenerates the necessary code.


Re: Gordon programming language

2021-10-26 Thread JN via Digitalmars-d-announce

On Tuesday, 26 October 2021 at 04:38:40 UTC, Tero Hänninen wrote:

On Monday, 25 October 2021 at 18:38:15 UTC, Walter Bright wrote:


Thanks for the kind words!

P.S. The quote is from Flash Gordon.


Ah, didn't know about that although have heard the name 
somewhere.


I actually named my language after Gordon Freeman from the 
Half-Life games which I liked to play. He gets lots done with 
little resources and is silent. My favorite game character.


I was hoping the language is inspired after Gordon Ramsay. With 
compile errors like:


"Look at these pointers, they're RAW",
"This syntax is disgusting"
"The code is not good enough!"


How to make a function that accepts optional struct but can accept struct literal too

2021-10-15 Thread JN via Digitalmars-d-learn
Is there some nice way of achieving something like this C99 code 
in D?


```c
#include 

typedef struct {
int x, y;
} inputs_t;

void foo(inputs_t* optional_inputs)
{
if (!optional_inputs) {
printf("0 0\n");
} else {
printf("%d %d \n", optional_inputs->x, 
optional_inputs->y);

}
}

int main(void) {
foo(NULL); // prints 0 0
foo(&(inputs_t){.x = 5, .y = 6}); // prints 5 6
}
```

below code won't work. Yes, I know I can just use a local 
variable in this case and pass a pointer, but I'd like to get it 
to work with literal structs too.


```d
import std.stdio;

struct inputs_t {
int x, y;
};

void foo(inputs_t* optional_inputs)
{
if (!optional_inputs) {
writeln("0 0");
} else {
writeln(optional_inputs.x, optional_inputs.y);
}
}

void main() {
foo(null); // prints 0 0
foo(&(inputs_t(5, 6))); // error: inputs_t(5,6) is not an 
lvalue and cannot be modified

}
```



Why sometimes stacktraces are printed and sometimes not?

2021-09-29 Thread JN via Digitalmars-d-learn
What makes the difference on whether a crash stacktrace gets 
printed or not?


Sometimes I get a nice clean stacktrace with line numbers, 
sometimes all I get is "segmentation fault error -1265436346" 
(pseudo example) and I need to run under debugger to get the 
crash location.


Re: Looking to get typeof parseXML return value

2021-09-07 Thread JN via Digitalmars-d-learn

On Tuesday, 7 September 2021 at 04:13:08 UTC, Chris Piker wrote:
Like almost all new users to D I'm tripping over how to save 
and pass around variables since nothing has an understandable 
type anymore and you can't use "auto" for *class member* 
storage types.


I struggle with this often. Templated types that pretty much 
require you to use auto look nice on the paper and in samples, 
but once you try to integrate them into a larger project, it can 
get messy.


Re: game-mixer v1.0.0

2021-08-22 Thread JN via Digitalmars-d-announce
On Saturday, 21 August 2021 at 13:45:56 UTC, Guillaume Piolat 
wrote:

One year after the translation of libsoundsio to D by Dennis:
https://forum.dlang.org/post/xckyiizkjwdwvuvtm...@forum.dlang.org

I'm happy to introduce the `game-mixer` package in v1.0.0:
https://code.dlang.org/packages/game-mixer



Looks interesting. I don't mind C library bindings, but I prefer 
D libraries because they are easier to integrate and don't 
require chasing older dlls around.


Any UML generators for D code?

2021-08-12 Thread JN via Digitalmars-d-learn
I'd like to see the relationships between my D classes in a 
graphical form. Is there any tool that supports that?


Detect if a struct is a 3-float vector

2021-06-23 Thread JN via Digitalmars-d-learn

I'm looking for a way to test a struct for these conditions:

1. has members named x, y and z
2. these members are floating point type

This works, but feels kinda verbose, is there some shorter way? 
Can I somehow avoid the hasMember/getMember calls?


```d
import std.traits;

struct Vector3f
{
float x, y, z;
}

struct Vector2f
{
float x, y;
}

struct Vector3i
{
int x, y, z;
}

bool isVector3fType(T)()
{
static if (__traits(hasMember, T, "x") && __traits(hasMember, 
T, "y") && __traits(hasMember, T, "z"))

{
static if (isFloatingPoint!(typeof(__traits(getMember, T, 
"x")))
&& isFloatingPoint!(typeof(__traits(getMember, T, 
"y")))&& isFloatingPoint!(typeof(__traits(getMember, T, "z" {

return true;
}
}
return false;
}

void main()
{
static assert(isVector3fType!Vector3f);
static assert(!isVector3fType!Vector2f);
static assert(!isVector3fType!Vector3i);
}
```


Arrays of variants, C++ vs D

2021-06-17 Thread JN via Digitalmars-d-learn

This C++ code compiles:
```cpp
#include 
#include 
#include 

int main()
{
using Foo = std::variant;
std::map foos =  {{0, "abc"}, {1, 5}};
}

This code doesn't:

```d
import std.variant;

void main()
{
alias Foo = Algebraic!(int, string);
Foo[int] foos = [
0: "abc",
1: 5
];
}
```
but this does:

```d
import std.variant;

void main()
{
alias Foo = Algebraic!(int, string);
Foo[int] foos = [
0: Foo("abc"),
1: Foo(5)
];
}
```

Why does D need the explicit declarations whereas C++ can infer 
it?


Re: Cast class reference to pointer of another class?

2021-06-10 Thread JN via Digitalmars-d-learn

On Saturday, 29 May 2021 at 22:26:48 UTC, ag0aep6g wrote:
You're writing @system code, so dangerous casts are allowed. 
It's no surprise that the code compiles. If you want to be 
safeguarded against such things, use @safe.


The result is a class object being reinterpreted as a struct 
object. Usually, that's just nonsense. But it might be useful 
for some expert who wants to tinker with the object's internals.


I have to disagree. I don't see a good reason for this behavior 
and it's just one more thing to trip people. I think it'd be 
better if such thing was done explicit, something like:


```d
Bar b = new Bar();
Foo* f2 = cast(Foo*)b.ptr;
```


Re: D Language Foundation Monthly Meeting Summary

2021-06-03 Thread JN via Digitalmars-d-announce

On Saturday, 29 May 2021 at 00:30:38 UTC, zjh wrote:

On Saturday, 29 May 2021 at 00:26:54 UTC, zjh wrote:

Good,maybe we can raise our sounding slogan "Better C++" again!


There are too many talents in C++
We must attract them.
Only them can make d great!Because they are library writer. 
They can make d great.


I disagree. Attracting C++ folks doesn't seem to work. You may 
try to lure them with promises of nicer templates and no header 
files, but after a while they will complain about the garbage 
collector and go back to their new C++ draft standard.


If you advertise yourself as Better C++, you are instantly 
setting yourself up for comparison and are turning away everyone 
who dislikes C++ in the first place.


Rust doesn't advertise itself as "Safe C++", Go doesn't advertise 
itself as "Native Java", Zig doesn't advertise itself as "Better 
C".


Re: Cast class reference to pointer of another class?

2021-05-29 Thread JN via Digitalmars-d-learn

fixed formatting:

```d
struct Foo
{
}

class Bar
{
}

void main()
{
Bar b = new Bar();
Foo* f = cast(Foo*)b;
}
```




Cast class reference to pointer of another class?

2021-05-29 Thread JN via Digitalmars-d-learn

```struct Foo
{
}

class Bar
{
}

void main()
{
Bar b = new Bar();
Foo* f = cast(Foo*)b;
}```

this code compiles. Why? What is even the result in "f" in this 
case?


Re: Why is this allowed? Inheritance variable shadowing

2021-05-26 Thread JN via Digitalmars-d-learn

On Tuesday, 13 August 2019 at 04:40:53 UTC, Chris Katko wrote:

You can drop this straight into run.dlang.io:

import std.stdio;

class base{ float x=1;}
class child : base {float x=2;} //shadows base variable!

void main()
{

base []array;
child c = new child;
array ~= c;

writeln(c.x); //=2
writeln(array[0].x); //=1  //uses BASE's interface, yes,
//but why does the CHILD instance one exist at all?
}



Just got bitten by this. When copy pasting code of a bigger 
class, it's easy to miss the redefinition of variable.


Is there any viable usecase for this behavior? I am not buying 
the "C++ does it and it's legal there" argument. There's a reason 
most serious C++ projects use static analysis tools anyway. D 
should be better and protect against dangerous code by default. I 
think a warning in this case would be warranted.




Re: Compiler version "dirty"

2021-05-20 Thread JN via Digitalmars-d-learn

On Tuesday, 9 March 2021 at 01:36:18 UTC, Paul Backus wrote:

On Monday, 8 March 2021 at 22:29:58 UTC, Q. Schroll wrote:

When I enter `dmd --version`, it says:
  DMD64 D Compiler v2.095.1-dirty
What should the "dirty" mean? To me, it seems looks something 
went wrong somewhere.


It means someone made a mistake when preparing the release. 
Probably harmless.


v2.096.1 also reports as -dirty


Struct initialization extra comma - should it compile

2021-04-25 Thread JN via Digitalmars-d-learn

struct Foo
{
int x, y, z;
}

void main()
{
 Foo bar = Foo(1,);
}

This compiles without syntax errors, is this expected?


Re: Foo Foo = new Foo();

2021-02-21 Thread JN via Digitalmars-d-learn
On Sunday, 21 February 2021 at 18:09:29 UTC, FeepingCreature 
wrote:

On Sunday, 21 February 2021 at 18:07:49 UTC, JN wrote:

class Foo
{
}

void main()
{
Foo Foo = new Foo();
}

this kind of code compiles. Is this expected to compile?


Yes, why wouldn't it? main is a different scope than global; 
you can override identifiers from global in main. And "Foo" 
only exists after the declaration, so it doesn't conflict.


I was worried I hit some corner case where it compiles even 
though it shouldn't. Can lead to some confusing code. I guess D 
is smart enough to figure out which is a type and which is a 
variable. C++ gets confused in similar situation.


Re: How add png image to zip file using std.zip?

2021-02-21 Thread JN via Digitalmars-d-learn

On Sunday, 21 February 2021 at 17:17:56 UTC, Marcone wrote:

ZipArchive zip = new ZipArchive();
std.file.write("foo.zip", zip.build());

ArchiveMember f = new ArchiveMember();
f.name = "Wallpaper_001.png";

zip.addMember(f);
std.file.write("foo.zip", zip.build());

File is added with file size 0.
How can I use expandedData for add images files? Or what I use 
for it?


expandedData should hold the contents of the uncompressed file, 
as byte array. So something like:


f.name = "Wallpaper_001.png";
f.expandedData = cast(ubyte[])std.file.read("Wallpaper_001.png");

should work. f.name = "Wallpaper_001.png" only says "create a 
file named Wallpaper_001.png inside the zip". It doesn't say "put 
the Wallpaper_001.png file into the zip".


Foo Foo = new Foo();

2021-02-21 Thread JN via Digitalmars-d-learn

class Foo
{
}

void main()
{
Foo Foo = new Foo();
}

this kind of code compiles. Is this expected to compile?


Any tools to track heap/stack corruptions?

2021-02-03 Thread JN via Digitalmars-d-learn
I am dealing with some nasty issue in my code. Basically random 
unrelated lines of code are crashing with access violations, and 
if I switch from dmd to ldc the crash goes away, or crash comes 
back, or it crashes in a different spot. Seems like I am 
corrupting some memory somewhere (I interact a lot with C 
libraries). Do you know of any tools I could use to try to narrow 
it down?


I've used Application Verifier but so far it didn't point me to 
anything specific.


Re: Refactoring tools

2021-02-03 Thread JN via Digitalmars-d-learn

On Wednesday, 3 February 2021 at 07:20:06 UTC, Imperatorn wrote:

2. If not, why? (Is D still too small?)


D uses templates and a lot of code is generated at compile time. 
It's the same reason C++ doesn't have any advanced refactoring 
tools like e.g. Java does. In Java, it's simple to rename a class 
in all files that use it, and the tools know that X class is 
actually the class from module A and not the X class from module 
B. In D, for all you know you could have someone using 
mixin("My"~"Class"), good luck automatically renaming that.


Re: How to resize an image ? 樂

2020-12-27 Thread JN via Digitalmars-d-learn

On Friday, 25 December 2020 at 20:59:03 UTC, vnr wrote:

Hello 

For a small "script" that generates printable files, I would 
need to change the size of an image (which is loaded into 
memory as an array of bytes) to shrink it to scale if it 
exceeds the A4 page size.


To load the images into memory and generate a PDF, I use the 
"printed" package. It is not very provided but is sufficient 
for my use, I just need the resize option... Is there a 
relatively simple way to do this?


Thank you.


I use the trusty stb_image C libraries (bindings here 
https://code.dlang.org/packages/stb ), specifically the 
stbir_resize_* functions.


Why are default template parameters not permitted on class templates?

2020-11-29 Thread JN via Digitalmars-d-learn

class ValueHolder(T = int)
{
T t;
}

void main()
{
ValueHolder!int v1;
ValueHolder v2; // error
}

onlineapp.d(9): Error: template class onlineapp.ValueHolder(T = 
int) is used as a type without instantiation; to instantiate it 
use ValueHolder!(arguments)


Re: Resolve dub dependency

2020-09-21 Thread JN via Digitalmars-d-learn

On Monday, 21 September 2020 at 19:38:12 UTC, Paul Backus wrote:

On Monday, 21 September 2020 at 19:16:17 UTC, JN wrote:
I am trying to use bindbc-sdl and bindbc-wgpu at the same 
time. The error is:


Unresolvable dependencies to package bindbc-loader:
  bindbc-sdl 0.19.1 depends on bindbc-loader ~>0.3.0
  bindbc-sdl 0.19.1 depends on bindbc-loader ~>0.3.0
  bindbc-wgpu 0.1.0-alpha8 depends on bindbc-loader ~>0.2.1

What is the cleanest way to resolve this? I don't understand 
why can't -sdl and -wgpu use different versions of the loader 
library.


You can't use different versions of a library in the same 
library in the same program because library version isn't 
included in name mangling, so you'll get link errors for having 
multiple definitions of the same symbol.


Ahh ok, that makes sense. I patched bindbc-wgpu locally to use 
loader ~>0.3.0 and it's working now.


Resolve dub dependency

2020-09-21 Thread JN via Digitalmars-d-learn
I am trying to use bindbc-sdl and bindbc-wgpu at the same time. 
The error is:


Unresolvable dependencies to package bindbc-loader:
  bindbc-sdl 0.19.1 depends on bindbc-loader ~>0.3.0
  bindbc-sdl 0.19.1 depends on bindbc-loader ~>0.3.0
  bindbc-wgpu 0.1.0-alpha8 depends on bindbc-loader ~>0.2.1

What is the cleanest way to resolve this? I don't understand why 
can't -sdl and -wgpu use different versions of the loader library.


Re: D mentionned in the ARTIBA webzine for an article on Silq

2020-09-02 Thread JN via Digitalmars-d-announce

On Wednesday, 2 September 2020 at 00:35:07 UTC, user1234 wrote:

«Trivia:

- Silq is written in the D programming language.

- To install Silq via vscode, see: 
https://silq.ethz.ch/install.


- A timeline of major developments in quantum computing:
»

https://www.artiba.org/blog/meet-silq-the-first-intuitive-high-level-language-for-quantum-computers


One thing I always feel this forum is missing is a section for 
work in progress projects, even if they never end up anywhere. 
Right now people are shy about their projects, so the only way 
you learn about them is by finding mentions of them such as 
these, when they're released on DUB repository or when someone 
makes an announcement post on Announce. The problem with Announce 
is that people only use it for official releases - and that's 
good - but we're missing out on all the work in progress buzz.


I always reference the old dsource forums - 
http://dsource.org/forums/ - click at that, it's a graveyard now, 
but imagine going there back then - so exciting! So many fun 
projects. It's fun to scroll around and see what people are doing 
and maybe even join them in their effort. Most of these projects 
never got out of wip stages and got abandoned later on, but they 
were certainly interesting. Even now, many years later I like to 
browse them to look for inspiration and see what people were 
after.


I'd really love a "Projects" section here on these forums, with 
perhaps sections for "WIP" and "Releases", so that people can 
post all the cool stuff they are working on for others to see.


Autodecode?

2020-08-16 Thread JN via Digitalmars-d-learn
Related to this thread: 
https://forum.dlang.org/post/xtjzhkvszdiwvrmry...@forum.dlang.org


I don't want to hijack it with my newbie questions. What is 
autodecode and why is it such a big deal? From what I've seen 
it's related to handling Unicode characters? And D has the wrong 
defaults?


Re: What would be the advantage of using D to port some games?

2020-07-21 Thread JN via Digitalmars-d-learn

On Wednesday, 24 June 2020 at 18:53:34 UTC, matheus wrote:
Hi, I currently use D for small CLI/Batch apps, before that I 
used to program in C.


Despite of using D I usually program like C but with the 
advantage of: GC, AA, CTFE and a few classes here and there.


As we can see there are a lot of old classic games source 
available like: DOOM, Duke Nukem 3D, Red Alert and most them 
written originally in C/C++.


What I'd like to know from the experts is: What would be the 
advantage of using D to port such games?


Thanks in advance,

Matheus.


The advantage is that you have a fun programming project and a 
challenge. And you don't have to worry about being stuck on the 
code or art side, because all those are ready for you, you just 
have to rewrite it in a different language.


Also, when finished, it makes for a fun blog post about 
challenges of porting C/C++ code to D and which parts were 
simplified using D features.


I was thinking of porting something like Doom to D also (DooD?), 
but never got around to it. I guess one could start with a 
betterC port too.


Re: Send empty assoc array to function

2020-07-10 Thread JN via Digitalmars-d-learn

On Friday, 10 July 2020 at 03:59:37 UTC, Mike Parker wrote:
Meh. You could say the same about foo(int[]), or 
foo(SomeClass). AAs are reference types. Reference type 
instances can be null.


Oh, that actually makes sense. I always thought assoc arrays are 
value types.


Anyway, even if they are reference type, I still would consider 
[] and null different types of values. [] conveys to me that the 
object exists, but is empty. null conveys to me that the object 
exists and cannot be used.


int[int] a = null;
a[5] = 6;

This kind of code just looks weird... yes, I know the " = null " 
part is excessive, but still.


Re: Send empty assoc array to function

2020-07-09 Thread JN via Digitalmars-d-learn
On Thursday, 9 July 2020 at 20:24:11 UTC, Steven Schveighoffer 
wrote:

On 7/9/20 4:04 PM, JN wrote:

On Thursday, 9 July 2020 at 19:53:42 UTC, JN wrote:

void foo(int[int] bar)
{
    // ...
}



Is it possible to send an empty array literal?

foo( [ 0 : 2 ] ) works
foo( [] ) doesn't

int[int] empty;
foo(empty);
works but it's two lines


Hmm, foo(null) seems to work, but is it correct way to do it?



Yes, that is correct.

-Steve


Interesting. Often in D discussion, an argument pops up that the 
language should be protecting against hidden breakages from API 
changes. This would be an example of that happening.


void foo(int[int] bar), someone calls it with a null, suddenly 
the signature changes to void foo(int* bar) and you will be 
sending a null pointer and possibly breaking the app.


Re: Send empty assoc array to function

2020-07-09 Thread JN via Digitalmars-d-learn

On Thursday, 9 July 2020 at 19:53:42 UTC, JN wrote:

void foo(int[int] bar)
{
// ...
}



Is it possible to send an empty array literal?

foo( [ 0 : 2 ] ) works
foo( [] ) doesn't

int[int] empty;
foo(empty);
works but it's two lines


Hmm, foo(null) seems to work, but is it correct way to do it?



Send empty assoc array to function

2020-07-09 Thread JN via Digitalmars-d-learn

void foo(int[int] bar)
{
// ...
}



Is it possible to send an empty array literal?

foo( [ 0 : 2 ] ) works
foo( [] ) doesn't

int[int] empty;
foo(empty);
works but it's two lines


Re: Visual D 1.0.0 released

2020-07-07 Thread JN via Digitalmars-d-announce

On Saturday, 4 July 2020 at 13:00:16 UTC, Rainer Schuetze wrote:
See 
https://rainers.github.io/visuald/visuald/VersionHistory.html 
for the complete list of changes.


Cheers,
Rainer


Anyone who uses VisualD and Code-D can compare the two? (Yes, I 
know the difference between Visual Studio and Visual Studio Code).


Re: Why is this allowed

2020-07-01 Thread JN via Digitalmars-d-learn

On Wednesday, 1 July 2020 at 15:57:24 UTC, Nathan S. wrote:

On Tuesday, 30 June 2020 at 16:22:57 UTC, JN wrote:
Spent some time debugging because I didn't notice it at first, 
essentially something like this:


int[3] foo = [1, 2, 3];
foo = 5;
writeln(foo);   // 5, 5, 5

Why does such code compile? I don't think this should be 
permitted, because it's easy to make a mistake (when you 
wanted foo[index] but forgot the []). If someone wants to 
assign a value to every element they could do foo[] = 5; 
instead which is explicit.


What's your opinion on using that syntax in the initial 
declaration, like `float[16] foo = 0`?


I don't like it. I'd prefer:

float[16] foo = [ 0 ];

or

float[16] foo = { 0 };

or

float[16] foo(0);


Re: Print only part of a stack trace

2020-07-01 Thread JN via Digitalmars-d-learn

On Wednesday, 1 July 2020 at 18:30:15 UTC, Dennis wrote:
I have a function that checks a global error constant of a C 
library (OpenGL) like this:

```
void assertNoOpenGLErrors() {
if (glGetError() != GL_NO_ERROR) {
assert(0); // stack trace points to here instead of 
caller

}
}


Bit off-topic, but if you can use them, debug contexts offer much 
better OpenGL error-checking experience. 
https://www.khronos.org/opengl/wiki/Debug_Output . Instead of 
checking glGetError() after each call, you can setup a C callback 
that will trigger whenever an error occurs. It also offers some 
vendor-specific performance warnings.


Re: Why is this allowed

2020-06-30 Thread JN via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 16:37:12 UTC, Steven Schveighoffer 
wrote:
That's a feature. I don't think it's going away. The problem of 
accidental assignment is probably not very common.


-Steve


What is the benefit of this feature? I feel like D has quite a 
few of such "features". I like my code to be explicit, even at a 
cost of some extra typing, rather than get bitten by some 
unexpected implicit behavior.


Why is this allowed

2020-06-30 Thread JN via Digitalmars-d-learn
Spent some time debugging because I didn't notice it at first, 
essentially something like this:


int[3] foo = [1, 2, 3];
foo = 5;
writeln(foo);   // 5, 5, 5

Why does such code compile? I don't think this should be 
permitted, because it's easy to make a mistake (when you wanted 
foo[index] but forgot the []). If someone wants to assign a value 
to every element they could do foo[] = 5; instead which is 
explicit.


Re: iopipe v0.2.0 - safe update

2020-06-28 Thread JN via Digitalmars-d-announce
On Sunday, 28 June 2020 at 18:57:22 UTC, Steven Schveighoffer 
wrote:
Just wanted to post that I finished my update of iopipe to be 
@safe. I still have some work to do with std.io so things are 
more usable (next on my list is to make standard handles 
accessible).


In this update, I've made it so nearly all of iopipe can be 
used in @safe code. The one exception is the RingBuffer, which 
can leave dangling pointers, hence the unsafety.


Inside iopipe is a RefCounted type that is @safe. It uses the 
GC for memory management, so while destruction is synchronous, 
the memory itself is left to the GC to clean up.


-Steve

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


What's iopipe and what does it do? How does it compare with 
std.process?


Re: From the D Blog: A Pattern for Head-mutable Structures

2020-06-26 Thread JN via Digitalmars-d-announce
On Friday, 26 June 2020 at 05:37:13 UTC, Arun Chandrasekaran 
wrote:
This is a very interesting post. But this strategy with HN is 
clearly not working. 5 upvotes after 17 hours and 0 comments. 
Please paste the direct link in future even if the ranking goes 
down after a few hours. Some publicity is better than nothing 
at all.


To be honest... I use D and don't really understand what the blog 
post is about (I don't really care much for const and such). I 
just glance through it and nothing catches my eye. I imagine any 
non-D user would completely ignore this blog post. It's a nice 
blog post for D users who are into this topic, but it's not 
something that would grab general attention. Also the premise of 
"D's const is hard to use, here's a way to deal with it" is not 
very optimistic. People here might think "wow, that's a nifty 
trick", but most outsiders would just think "wow that const thing 
is pain in the ass".


Here's some examples of blog posts that got popular on reddit 
last week. They're short enough and can be understood without 
deep understanding of the language:


https://jvns.ca/blog/2020/06/19/a-little-bit-of-plain-javascript-can-do-a-lot/
https://kristoff.it/blog/zig-colorblind-async-await/



Use classes as keys in associative array

2020-06-06 Thread JN via Digitalmars-d-learn
Is it possible to use different class instances as keys for 
associative array, but compare them by the contents? I tried to 
override opEquals but it doesn't seem to work. Basically I'd like 
this code to work. I know structs would work but I can't use 
structs for this):


import std.stdio;

class Name
{
string s;

this(string s)
{
this.s = s;
}
}

void main()
{
Name n1 = new Name("John");
Name n2 = new Name("John");

int[Name] ages;
ages[n1] = 50;

assert(ages[n2] == 50);
}


Re: Determining @trusted-status

2020-05-29 Thread JN via Digitalmars-d-learn

On Friday, 29 May 2020 at 00:09:56 UTC, Clarice wrote:
It seems that @safe will be de jure, whether by the current 
state of DIP1028 or otherwise. However, I'm unsure how to 
responsibly determine whether a FFI may be @trusted: the type 
signature and the body. Should I run, for example, a C library 
through valgrind to observe any memory leaks/corruption? Is it 
enough to trust the authors of a library (e.g. SDL and OpenAL) 
where applying @trusted is acceptable?
There's probably no one right answer, but I'd be very thankful 
for some clarity, regardless.


I think most C FFI should be @system, even if it's for popular 
libraries like SDL. Whenever you have API that takes a pointer 
and a size of array, you are risking buffer overflows and similar 
issues. It's very easy to mess up and send array length instead 
of array length * element.sizeof. A @trusted API would only 
accept a slice, which is much safer than raw pointers.


Alternatively you could just use @trusted blocks. Unsafe blocks 
are a common practice in languages like C# or Rust when it comes 
to calling unsafe code. @safe isn't about 100% bulletproof 
safety. @safe is (should be) about not having memory related 
errors outside of @trusted code, minimizing the surface area for 
errors.


Re: DIP1028 - Rationale for accepting as is

2020-05-26 Thread JN via Digitalmars-d-announce

On Tuesday, 26 May 2020 at 02:04:02 UTC, Johannes Loher wrote:
According to your argument of „convenience“, the developer will 
probably just mark the function incorrectly as @trusted which 
makes the code compile. The memory corruption will happen. 
However, even if the developer did not think much about 
potential safety issues when adding @trusted to the function, 
he now still remembers that he did that (it was a conscious 
decision, even if it was a careless and lazy one). He has a 
clear point to start looking for the reason of the memory 
corruption.


Or he'll do the right thing, and keep the function @system but 
call it from a @trusted block. Then when he's stuck debugging, he 
can show it to his experienced buddy and his experienced buddy 
will instantly look in the @trusted block because it's suspicious.


Re: DIP1028 - Rationale for accepting as is

2020-05-23 Thread JN via Digitalmars-d-announce
On Saturday, 23 May 2020 at 12:13:45 UTC, Steven Schveighoffer 
wrote:


What is not fine is having the compiler do it for you so nary a 
@trusted marking is in sight. I don't really understand the 
draw of that.


-Steve


I think not only about how @safe mechanically verifiable is an 
advantage, but also @trusted blocks are very greppable so it's 
easy to find "danger zones" in any project.


I briefly skimmed through the discussion and I don't really see 
the issue with @trusted blocks other than the slightly awkward 
syntax. Yes, it's additional effort, but it should be an 
additional effort, so that people try to avoid unsafe code.


In languages like Rust and C# people are used to using unsafe 
blocks whenever interacting with C code, or people build safe 
wrappers over unsafe APIs, which is exactly what would be 
expected in D after these changes.


Re: On the D Blog: Lomuto's Comeback

2020-05-17 Thread JN via Digitalmars-d-announce

On Thursday, 14 May 2020 at 14:11:57 UTC, SashaGreat wrote:


If possible could you please next time share link with "old" 
instead of "www"? Like:


https://old.reddit.com/r/programming/comments/gjm6yp/lomutos_comeback_quicksort_partitioning/



There is a Chrome extension that automatically redirects to the 
old version of Reddit




Re: How to include my own library in my d program with dub ?

2020-05-14 Thread JN via Digitalmars-d-learn

On Thursday, 14 May 2020 at 12:53:43 UTC, Vinod K Chandran wrote:

Hi all,
I just build a skeleton of a Gui library(win32 based) for my 
own purpose. How do i use this in my d programs with dub ? Now, 
all files are located in a folder called "GuiLib".
Side note : Why i started making a gui library instead of 
learning language ?
Answer : By this way, i can learn the language and i will have 
my own gui library. Otherwise, i would have struggle with 
learning a third party library.


I don't know if it's up-to-date, but this should work:

https://github.com/dlang/dub/wiki/Cookbook#working-with-submodules-or-packages-that-are-not-in-the-registry

I am assuming your GUI library uses dub already for building?


Re: bindbc-sdl Updates

2020-04-18 Thread JN via Digitalmars-d-announce

On Saturday, 18 April 2020 at 15:31:02 UTC, aberba wrote:

On Friday, 17 April 2020 at 03:48:09 UTC, Mike Parker wrote:

On Thursday, 16 April 2020 at 18:55:21 UTC, Luis wrote:

[...]


I disagree. There are numerous examples of SDL on the 
internet. There are sites full of SDL tutorials. bindbc-sdl is 
a binding. It doesn't change the API. I'm not going to write 
example programs for every library I create bindings for when 
plenty of examples exist.


There's this level of convenience that is triggered when you 
see a sample demo. It seems some library authors don't get it.


For libraries, absolutely.

For C bindings - no. Just remember the special things like 
library loading, and for the rest just copy a random C/C++ 
example.


Re: Is there an exception for access violation on LDC/win64?

2020-04-13 Thread JN via Digitalmars-d-learn

On Monday, 13 April 2020 at 10:18:17 UTC, realhet wrote:

Hi,

import std.stdio, std.exception;

[...]


Running under the debugger should show you the location of the 
crash.


Re: Discord bot written in D

2020-04-07 Thread JN via Digitalmars-d-learn

On Monday, 6 April 2020 at 21:23:22 UTC, Quantium wrote:
Are there any libraries to creade a simple discord bot using D? 
And if you know these libraries, could you day me their pros 
and cons?


There are four Discord API related libraries on code.dlang.org. 
Have you checked those?


Re: Vibe.d navigation

2020-03-31 Thread JN via Digitalmars-d-learn

On Tuesday, 31 March 2020 at 18:57:51 UTC, GreatSam4sure wrote:
I am playing with the vibe.d for some days now. One thing I am 
struggling with is move from one page to another using web 
interface. The naming of the functions and proper navigation 
from one page to another is not clear to me.


How to move from one page to another. I will appreciate any 
help.


https://vibed.org/api/vibe.web.web/redirect


Cool name for Dub packages?

2020-03-07 Thread JN via Digitalmars-d-learn

Do we have any cool name for Dub packages?

Rust has 'crates'
Crystal has 'shards'
Python has 'wheels'
Ruby has 'gems'


Re: in not working for arrays is silly, change my view

2020-03-02 Thread JN via Digitalmars-d-learn

On Saturday, 29 February 2020 at 21:56:51 UTC, Ali Çehreli wrote:
Because you mentioned canFind, I think you want the semantics 
to be "is there an element with this value." If so, it would be 
confusing to use the same operator for two different things: 
For associative arrays, it means "is there an element 
accessible with this key."


Does it? I always viewed it as "is this value in list of keys"

Unless 'in' works with arrays to mean "is this index valid", 
then I don't see the benefit. If we had it, I think more people 
would ask "why does 'in' work differently for arrays?"
Are there other languages that support this semantic? 
Checking... Ok, Python has it, highly likely because they don't 
have arrays to begin with.




Well, Python lists are for most purposes equivalent to arrays and 
it hasn't really been confusing for people.




in not working for arrays is silly, change my view

2020-02-29 Thread JN via Digitalmars-d-learn

assert(1 in [1, 2, 3]);

Error: incompatible types for (1) in ([1, 2, 3]): int and int[

Yes, I know about .canFind(), but this is something that trips 
people over and over.


I think it would be better if "in" worked for both assoc arrays 
and normal arrays, or didn't work at all, for added consistency.


Re: Where are the GSOC 2020 ideas?

2020-02-27 Thread JN via Digitalmars-d-learn

On Thursday, 27 February 2020 at 08:16:32 UTC, mark wrote:
On https://wiki.dlang.org I can find GSOC ideas 2011-2019, but 
not 2020.


I know the 2020 one's haven't been accepted, but I'd like to 
know what they are in case I feel like having a go at one as 
part of learning D.


I don't know where is the official list, but this list may have 
been used for thinking up GSOC 2020 projects:


https://github.com/dlang/projects/issues?q=is%3Aissue+is%3Aopen+label%3Agsoc2020


Re: Beta 2.091.0

2020-02-27 Thread JN via Digitalmars-d-announce
On Wednesday, 26 February 2020 at 12:17:43 UTC, Martin Nowak 
wrote:
Glad to announce the first beta for the 2.091.0 release, ♥ to 
the 55 contributors.


http://dlang.org/download.html#dmd_beta 
http://dlang.org/changelog/2.091.0.html


Due to updating several components in the build pipeline, this 
beta and release are unfortunately delayed. 2.091.0 is now 
planned to be released one week later on March 8th.


As usual please report any bugs at
https://issues.dlang.org

-Martin


"Class deallocator have been deprecated in v2.080.0 (see ), and 
turned into an error in v2.087.0. They have now been completely 
removed from the language, and the parser won't recognize them 
anymore."


missing a link after the see


Re: Lambda capture by value

2020-02-24 Thread JN via Digitalmars-d-learn

On Monday, 24 February 2020 at 20:00:20 UTC, Adam D. Ruppe wrote:

On Monday, 24 February 2020 at 19:50:23 UTC, JN wrote:

foreach (i; iota(5))
{
printers[i] = () { write(i); };


I know it looks silly but if you make that:

 printers[i] = (int i) { return () { write(i); }; }(i);

it will do what you want.

This is something that used to be common in javascript, write a 
little function that passes the capture-by-value args and 
returns the lambda you actually want and call it immediately.


That extra layer causes the compiler to create a new copy of 
the capture variables snapshotted in time.


D'oh! I am actually familiar with the pattern from Javascript, 
used it many times, but somehow got it mixed up with something 
else and couldn't make it work.


Thanks.


Lambda capture by value

2020-02-24 Thread JN via Digitalmars-d-learn

import std.range;
import std.stdio;

alias NumberPrinter = void delegate();

NumberPrinter[int] printers;

void main()
{
foreach (i; iota(5))
{
printers[i] = () { write(i); };
}

foreach (i; iota(5))
{
printers[i]();
}
}

This prints 4 4 4 4 4.

How to make it so that it prints 0 1 2 3 4? Is it possible 
without changing the delegate definition to void delegate(int)?


Re: Earcut polygon triangulation

2020-02-24 Thread JN via Digitalmars-d-announce

On Sunday, 23 February 2020 at 16:20:09 UTC, Ahmet Sait wrote:
Out of curiosity, why would you need to triangulate polygons 
instead of using stencil buffer? I'm assuming you're using 
OpenGL (or something similar) since you talked about your hobby 
game. Any advantage of triangulating shapes? (anti-aliasing 
maybe?)


Triangulation goes beyond rendering. I imagine this library might 
be useful when making a level editor for a DOOM-like 2.5D engine.


Default value for member class

2020-02-10 Thread JN via Digitalmars-d-learn

class IntValue
{
int x = 5;
}

class Foo
{
IntValue val = new IntValue();
}

void main()
{
Foo f1 = new Foo();
Foo f2 = new Foo();

assert(f1.val == f2.val);
}


Is this expected? Or should each Foo have their own IntValue 
object? They're equal right now, changing one changes the other. 
When exactly is the "new IntValue" happening? On program init, or 
when calling new Foo() for the first time?


Re: total newbie + IDE

2020-02-09 Thread JN via Digitalmars-d-learn

On Sunday, 9 February 2020 at 13:22:56 UTC, solnce wrote:
I really enjoy Pascal having Lazarus. Although it is not 
perfected, it provides very good start for beginners - native 
IDE, RAD, easy to setup and adjust, integrated debugger. All 
that beginners need to have for good start at no time cost. It 
is just language doesn't evolve itself.




There isn't anything comparable to RAD for D. There was one being 
developed in the days od D1 for the DFL UI library - 
http://www.dprogramming.com/entice.php , but it's been long dead.


You can use GLADE to design an interface and then load it in a 
GtkD.


And it is after 13 years of in active development and being 
successor (as it claims so) to C++. ADA has it, Eiffel has it, 
FPC, Gambino many niche and small languages have it, why D, 
which has much wider application,  cannot have it? I think that 
is natural further evolution of any programming language.


I think the text editor/IDE landscape changed a little in last 
decade or so. Editors such as Sublime Text or Ultraedit lost 
their popularity, so did small language specific IDEs such as 
Dev-C++ or Code::blocks. Most of users of these IDEs migrated to 
the big projects like VSCode, Visual Studio or IntelliJ. Also, 
the introduction of language servers allows working on IDE 
support, without being bound to a specific IDE.


Editors/IDEs such as VSCode have a massive ecosystem. Why not 
take advantage of it, rather than start from scratch.


Re: GtkD on Windows: notes + question

2020-02-09 Thread JN via Digitalmars-d-learn

On Sunday, 9 February 2020 at 13:28:59 UTC, mark wrote:
I found a much easier way to get GtkD working on windows than 
that described in 
https://gtkdcoding.com/2019/01/11/-introduction-to-gtkDcoding.html


1. I downloaded and installed the Gtk3 runtime (the link is on 
https://gtkdcoding.com/2019/01/11/-introduction-to-gtkDcoding.html)


2. I downloaded and unzipped the GtkD3 zip to C:\bin\GtkD3

3. Since I'd already installed LDC I just had to run:

dub add-path C:\bin\GtkD3

Now I'm able to build and run on windows using dub. And again, 
I get static builds so have deployable .exes.


However, when I double-click a GtkD .exe it pops up a console 
window, then the GUI window, and the console window stays until 
I close the GUI.


Is there a way to avoid the console Window, at least for 
release builds?


https://forum.dlang.org/thread/xkvdpdsfzevanucrg...@forum.dlang.org


Re: total newbie + IDE

2020-02-07 Thread JN via Digitalmars-d-learn

On Friday, 7 February 2020 at 17:02:18 UTC, solnce wrote:

Hi guys,

I am total newbie and trying to learn a little bit of 
programming for personal purposes (web scrapping, small 
databases for personal use etc.). I've been trying to install 
any of IDE available, but had no success.


[...]


Try Visual Studio Code with Code-D extension.


Re: D as a C Replacement

2020-02-04 Thread JN via Digitalmars-d-announce
On Wednesday, 5 February 2020 at 04:31:21 UTC, Walter Bright 
wrote:

https://www.reddit.com/r/programming/comments/eyzrm9/d_as_a_c_replacement_the_art_of_machinery/
https://theartofmachinery.com/2019/04/05/d_as_c_replacement.html


It's a pity associative arrays aren't part of betterC. I was 
considering starting a new project in betterC, because I was 
looking for something like C with some additional nice haves, but 
without assoc arrays for me betterC still occupies that weird 
spot where it's not enough over C and too much below D.


Re: Empty string vs null

2020-02-03 Thread JN via Digitalmars-d-learn

On Tuesday, 4 February 2020 at 07:44:08 UTC, mark wrote:
Just found this post by Mark Parker that explains: 
https://forum.dlang.org/post/gvveit$10i5$1...@digitalmars.com


I recommend using Nullable from 
https://dlang.org/phobos/std_typecons.html#Nullable if you want 
to explicitly allow a non-value. I think it's cleaner and shows 
the intent better.





Assoc array init

2020-02-03 Thread JN via Digitalmars-d-learn

int[int] a = [5: 7];

void main()
{
}


This fails because apparently [5: 7] is a "non-const expression". 
How? Why?


Yes, I know I can just init in a static this() section, but that 
feels like a bad workaround.


Re: Is there a std.zip.ZipArchive isDir or isFile method?

2020-02-03 Thread JN via Digitalmars-d-learn

On Monday, 3 February 2020 at 13:26:38 UTC, mark wrote:

I'm using std.zip.ZipArchive to read zip files, e.g.:

auto zip = new ZipArchive(read(filename));
// ...
foreach (name, member; zip.directory) {
if (name.endsWith('/')) // skip dirs
continue;
mkdirRecurse(dirName(name));
zip.expand(member);
write(name, member.expandedData());
}

As you can see, I am detecting directories with a crude test.

I really wish there was a method for this: and if there is, 
could you give me the link 'cos I can't see one in the docs?


(BTW The code above is slightly simplified: the real code won't 
unzip if there's an absolute path or .. present and also 
ensures that all members are unzipped into a subdir even if the 
zip has top-level names.)


ArchiveMember has "flags" field, perhaps it stores if it's a 
directory?


If not, fileAttributes will have it but it looks it's OS specific.


Re: bindbc-opengl: Now drawing triangle

2020-01-25 Thread JN via Digitalmars-d-learn

On Saturday, 25 January 2020 at 19:52:25 UTC, Luhrel wrote:

Hello,

I made a simple OpenGL file using bindbc-opengl and glfw 
(https://pastebin.com/ehmcHwxj) based on 
https://github.com/SonarSystems/Modern-OpenGL-Tutorials/blob/master/%5BGETTING%20STARTED%5D/%5B1%5D%20Triangle/main.cpp


The cpp project compiles and runs fine (g++ main.cpp -lGL 
-lglfw -o gl_test && ./gl_test), but my d-translated file not: 
the triangle isn't shown.


Do you have any idea ?


I assume it's working now?

For future, learn to use RenderDoc:

https://renderdoc.org/

it allows you to debug your OpenGL application and see what kind 
of data is sent by your app.


lambda alias import

2020-01-17 Thread JN via Digitalmars-d-learn

stuff.d:

alias doStuff = () {};

main.d:

import stuff;

void main()
{
  doStuff();
}


DMD throws compile error:

 Error 42: Symbol Undefined __D5stuff9__lambda3FNaNbNiNfZv

Is this expected behavior? It tripped me while trying to use 
DerelictVulkan :(


Re: How to parse epub content

2020-01-11 Thread JN via Digitalmars-d-learn

On Saturday, 11 January 2020 at 12:38:38 UTC, Adnan wrote:
How would someone approach parsing epub files in D? Is there 
any libraries to parse XHTML?


XHTML is XML. There are libraries to parse XML, from std.xml in 
the standard library to libraries like dxml in the package 
repository.


Re: Release D 2.090.0

2020-01-07 Thread JN via Digitalmars-d-announce

On Tuesday, 7 January 2020 at 10:30:09 UTC, Martin Nowak wrote:

Glad to announce D 2.090.0, ♥ to the 48 contributors.

This release comes with the ability to convert lazy parameters 
to delegates, new intrinsics to force rounding to specific 
floating point precision, unittest builds that no longer 
execute main by default, a new GC.inFinalizer API, and various 
other changes.


http://dlang.org/download.html 
http://dlang.org/changelog/2.090.0.html


-Martin


Loving the JSON getter :)


Re: How load icon from resource using LoadImage?

2020-01-05 Thread JN via Digitalmars-d-learn

On Sunday, 5 January 2020 at 13:33:35 UTC, Marcone wrote:
I am using this code to load icon from local directory, but I 
want to load icon from resource.res file:


wndclass.hIcon  = LoadImage( NULL, "icon.ico", IMAGE_ICON, 0, 
0, LR_LOADFROMFILE| LR_SHARED | LR_LOADTRANSPARENT);


https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-loadimagea

According to the docs, the first argument is NULL only for 
standalone images, otherwise you have to provide a valid 
HINSTANCE.


By the way, have you managed to add the res file into the binary? 
My understanding is that the res file should be added into the 
exe file by the rc command before it can be used.


Re: Unfold string array

2020-01-05 Thread JN via Digitalmars-d-learn

On Sunday, 5 January 2020 at 08:21:54 UTC, Teo wrote:

All advises are welcome
Thank you!


For some reason I can't get run.dlang.io to shorten a link... 
hmm... I'll use ideone.


https://ideone.com/EjbhIs

It's kind of a naive implementation, there probably is room for 
improvement but should work for start.


Re: Finding position of a value in an array

2019-12-30 Thread JN via Digitalmars-d-learn

On Sunday, 29 December 2019 at 08:31:13 UTC, mipri wrote:


int i = a.countUntil!(v => v == 55);
assert(i == 2);


I also had to ask because I couldn't find it. In other languages 
it's named "index()", "indexOf()" or "find()". D is the only 
language I know which uses the "countUntil" scheme. And even so 
it's not obvious from the name if it's the index of the element 
or number of preceding elements.




Re: Default values in derived class

2019-12-28 Thread JN via Digitalmars-d-learn
On Saturday, 28 December 2019 at 22:12:38 UTC, Johan Engelen 
wrote:
What Mike is saying is that `Base` has one `b` member variable, 
but `Derived` has two (!).


```
writeln(d.b); // false
writeln(d.Base.b); // true (the `b` member inherited from Base)
```

-Johan


That makes sense. I think the compiler/linter should be warning 
against such cases though, because it's easy to make mistakes 
this way.


Default values in derived class

2019-12-28 Thread JN via Digitalmars-d-learn

import std.stdio;

class Base
{
bool b = true;
}

class Derived : Base
{
bool b = false;
}

void main()
{
// 1
Base b = new Derived();
writeln(b.b); // true
// 2
Derived d = new Derived();
writeln(d.b); // false
}


Expected behavior or bug? 1) seems like a bug to me.


Re: What kind of Editor, IDE you are using and which one do you like for D language?

2019-12-23 Thread JN via Digitalmars-d-learn

On Sunday, 22 December 2019 at 17:20:51 UTC, BoQsc wrote:
There are lots of editors/IDE's that support D language: 
https://wiki.dlang.org/Editors


What kind of editor/IDE are you using and which one do you like 
the most?


This list could use some cleaning up. Some of the IDEs haven't 
been maintained in a while, and most of them are some obscure 
editors with basic D syntax highlighting. There should be a link 
o n the main webpage to a list of recommended IDEs, and the 
common ones, the ones people are looking for - IntelliJ D Plugin, 
VisualD, VSCode.


Personally I use code-d. Haven't had much luck with the other D 
VSCode extension.


Re: How use Resedit Dialogs + Dlang?

2019-12-15 Thread JN via Digitalmars-d-learn

On Sunday, 15 December 2019 at 04:00:14 UTC, Marcone wrote:

There's a way to create simple GUI for Dlang using Resedit? How?


Do you know how to do it with C++? It should work the same in D, 
just use the WinApi bindings for calls.


Re: Hunt XML released 1.0.0 rc! Support for parsing, encoding, serialize, unserialize, object binding ..

2019-12-05 Thread JN via Digitalmars-d-announce

On Thursday, 5 December 2019 at 16:48:01 UTC, zoujiaqing wrote:

## Sample code for it
```D
import hunt.xml;

@XmlRootElement("user")
class User
{

@XmlAttribute("ID")
int id = 1001;

@XmlElement("USERNAME")
string name;
}


I like the declarative API, can't wait to give it a go. Reminds 
me of JAXB :)


Re: Dmd install to new Windows 10 system can't run app.d

2019-11-21 Thread JN via Digitalmars-d-learn

On Thursday, 21 November 2019 at 09:26:39 UTC, zoujiaqing wrote:

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


I had the same issue a while ago and reported it here 
https://issues.dlang.org/show_bug.cgi?id=20061


Re: dud: A dub replacement

2019-11-18 Thread JN via Digitalmars-d-announce

On Monday, 18 November 2019 at 10:40:28 UTC, Russel Winder wrote:
On Mon, 2019-11-18 at 10:26 +, Sebastiaan Koppe via 
Digitalmars-d-announce wrote:
On Monday, 18 November 2019 at 09:53:56 UTC, Paolo Invernizzi 
wrote:
> A win-win move would be to have dud emit the other formats 
> automatically as part of the compilation procedure, so to 
> have always all of them present and synced on the content.


I already regret starting about this. Instead of rooting for 
the SDL format, I should have just recommended to deprecate 
the json one.


I do not think you should regret starting a discussion on this.

Personally I only ever use SDL with Dub. Even contemplating 
using JSON for human written configuration files is, for me, 
totally the wrong thing to do.


I only use the JSON format. JSON is widespread together with XML. 
SDL I heard first time of in the context of Dub and never seen it 
used elsewhere. TOML also I know only from Cargo. YAML at least I 
know from several different projects.


I guess the tool must be working very well though if the main 
argument is what kind of data format to use :)


Re: I wrote a little socket tutorial

2019-11-15 Thread JN via Digitalmars-d-announce

On Friday, 15 November 2019 at 20:01:01 UTC, Adam D. Ruppe wrote:

On Friday, 15 November 2019 at 19:40:51 UTC, JN wrote:
I used this to get started back in the day: 
http://arsdnet.net/dcode/book/chapter_02/03/


yeah, that's one of the samples from my "D Cookbook" and I 
wrote this new thing primarily to expand upon the text there 
from the book (which was minimal).


Such code snippets are amazing for starting out. Too many 
libraries just throw the API documentation at you and figure out 
how to set up things. Especially in non-OOP languages, with OOP 
the dependencies kinda flow much better (oh, for this I need 
object of this class, so I make this, oh and now I need this 
object).


Re: I wrote a little socket tutorial

2019-11-15 Thread JN via Digitalmars-d-announce

On Friday, 15 November 2019 at 18:41:02 UTC, bauss wrote:
On Tuesday, 12 November 2019 at 18:03:44 UTC, Adam D. Ruppe 
wrote:
A lot of people ask me how to use sockets in Phobos, so I 
wrote it up with a few samples. Not every detail you could 
ever need, but I tried to be reasonably comprehensive for new 
users.


http://dpldocs.info/this-week-in-d/Blog.Posted_2019_11_11.html


Back when I first started D I wish this existed because there 
was virtually nothing regarding sockets back then.


It would have helped me a lot in terms of using it.

Great tutorial, 10/10.


I used this to get started back in the day: 
http://arsdnet.net/dcode/book/chapter_02/03/




Re: Blog series to teach and show off D's metaprogramming by creating a JSON serialiser

2019-11-10 Thread JN via Digitalmars-d-announce

On Sunday, 10 November 2019 at 10:22:17 UTC, SealabJaster wrote:
Next post is out, I feel kind of iffy over how I went over 
classes, but I think for the most part it came out ok. I 
probably won't touch classes specifically in any future post 
though, unless I can think of something interesting to do with 
them.


It's outside of the scope of the tutorial, but the "tough" part 
in serializing classes is realizing that they're a reference type 
rather than value type. Just like with serializing pointers, I 
could have two references pointing to the same class object, and 
a smart deserializer would create only one class object and point 
both references to it.




Re: Blog series to teach and show off D's metaprogramming by creating a JSON serialiser

2019-11-03 Thread JN via Digitalmars-d-announce

On Sunday, 3 November 2019 at 08:37:07 UTC, SealabJaster wrote:

On Sunday, 3 November 2019 at 08:35:42 UTC, SealabJaster wrote:

On Friday, 1 November 2019 at 21:14:56 UTC, SealabJaster wrote:

...


Sorry, seems it cut out the first half of that reply.

New posts are out, and I don't want to spam Announce with new 
threads, so I'm just replying to this one.


#1.1 https://bradley.chatha.dev/Home/Blog?post=JsonSerialiser1_1
#2 https://bradley.chatha.dev/Home/Blog?post=JsonSerialiser2


"This often seems to confuse people at first, especially those 
coming from other languages"


I think what's confusing people is that enum (short for 
ENUMERATION) is suddenly used like a constant/alias.


Re: Saving and loading large data sets easily and efficiently

2019-10-01 Thread JN via Digitalmars-d-learn

On Monday, 30 September 2019 at 20:10:21 UTC, Brett wrote:
So it much more difficult than POD but would still be a little 
more work to right... hoping that there is something already 
out there than can do this. It should be


I'm afraid there's nothing like this available. Out of 
serialization libraries that I know, msgpack-d and cerealed don't 
store references and instead duplicate the pointed-to content. 
Orange does it, but it doesn't support binary output format, only 
XML, so it isn't a good fit for your data.


Re: Help playing sounds using arsd.simpleaudio

2019-09-29 Thread JN via Digitalmars-d-learn

On Saturday, 28 September 2019 at 03:21:38 UTC, Murilo wrote:
Can anyone just please show me how to play a background 
sound(like those in games) using arsd.simpleaudio? I'd like 
something simple with a code snippet please.


I recommend SoLoud - bindings are available here 
http://code.dlang.org/packages/bindbc-soloud . It's more powerful 
than simpleaudio, supports multiple formats, 3D audio, etc.


Interfaces and templates

2019-09-20 Thread JN via Digitalmars-d-learn

import std.stdio;

interface IWriter
{
void write(U)(U x);
}

class Foo : IWriter
{
void write(U)(U x, int y)
{
writeln(x);
}
}



void main()
{
}

Does this code make sense? If so, why doesn't it throw an error 
about unimplemented write (or incorrectly implemented) method?


Re: DMD 2.088.0 and Other New Blog Post

2019-09-06 Thread JN via Digitalmars-d-announce

On Friday, 6 September 2019 at 13:45:19 UTC, Mike Parker wrote:
I've just published a new blog post announcing the 2.088.0 
release of DMD and tacked on a few other news items at the end. 
Most of it will not be news to readers of the forums, but 
please keep an eye on the reddit comments if you've got time to 
spare.


Blog:
https://dlang.org/blog/2019/09/06/dmd-2-088-0-released/

Reddit:
https://www.reddit.com/r/programming/comments/d0gtq7/d_20880_released/


Minor typo in blog post: getAvaliable.

Could use some more descriptive title on reddit, because no one 
who doesn't know D will click it. Perhaps something like "DMD 
2.088.0 released - comes with std::string and std::vector 
bindings".


  1   2   3   4   >