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

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)) {

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 drawb

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

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()

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

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 c

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_inpu

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. Templ

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 {

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",

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. Us

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

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

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 glob

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("f

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

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

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 m

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-loade

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

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 o

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

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] empt

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 i

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: 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 compil

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 } }

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 cod

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 f

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; clas

Re: Determining @trusted-status

2020-05-28 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 libra

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 librar

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. H

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

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 cons

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 wher

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); };

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

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

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 cos

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/

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. [...] Tr

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-v

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; mkdirRecu

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

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: 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.mi

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 wo

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

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 c

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 mai

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: 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

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

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

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: Sort Associative Array by Key

2019-08-25 Thread JN via Digitalmars-d-learn
On Sunday, 25 August 2019 at 17:01:23 UTC, a11e99z wrote: On Sunday, 25 August 2019 at 16:54:33 UTC, Samir wrote: Is there a way to output the values of an associative array based on the lexicographic order of the keys? For example, if foo = ["VXE":8, "BZP":5, "JLC":2], I'd like to output som

Re: Can I remove an element from a global associative array from within a class destructor?

2019-08-03 Thread JN via Digitalmars-d-learn
On Friday, 2 August 2019 at 23:13:10 UTC, realhet wrote: Today I read the documentation about structs, unions and classes, but I haven't find any restrictions for the ~this() destructors. Is there some extra rules regarding the GC and what I must not do in the destructors? Class destructors

Re: Help me decide D or C

2019-08-01 Thread JN via Digitalmars-d-learn
On Thursday, 1 August 2019 at 09:43:20 UTC, Kagamin wrote: On Wednesday, 31 July 2019 at 22:30:52 UTC, Alexandre wrote: 1) Improve as a programmer 2) Have fun doing programs Thats it basically. I am planning to study all "free" time I have. I am doing basically this since last year. Try Basi

D on ARM laptops?

2019-07-03 Thread JN via Digitalmars-d-learn
Does anyone know if and how well D works on ARM laptops (such as Chromebooks and similar)? For example this one https://www.pine64.org/pinebook/ . Can it compile D? Obviously DMD is out because it doesn't have ARM builds. Not sure about GDC. How about LDC?

Re: What is iota function full name

2019-06-21 Thread JN via Digitalmars-d-learn
On Friday, 21 June 2019 at 09:18:49 UTC, Jonathan M Davis wrote: So, iota is the name of the function, and it doesn't stand for anything. It's just the name of the Greek letter that was used for a similar function in another language that most programmers these days have probably never heard of

Re: Using python in D

2019-06-07 Thread JN via Digitalmars-d-learn
On Friday, 7 June 2019 at 05:04:30 UTC, rnd wrote: On Friday, 7 June 2019 at 04:39:14 UTC, rikki cattermole wrote: On 07/06/2019 3:54 PM, rnd wrote: How should I 'initialize python' ? The example is probably a good place to begin. https://github.com/ariovistus/pyd/blob/master/examples/simpl

Static struct?

2019-04-24 Thread JN via Digitalmars-d-learn
I noticed a construct I haven't seen before in D when reading the description for automem - https://github.com/atilaneves/automem static struct Point { int x; int y; } What does "static" do in this case? How does it different to a normal struct?

Re: Unexpected behaviour in associative array

2019-04-19 Thread JN via Digitalmars-d-learn
On Friday, 19 April 2019 at 12:37:10 UTC, Arredondo wrote: Here's a reasonably-sized code fragment that demonstrates the issue. I hope the comments along the way are descriptive enough Hmm. Have you tried using a different compiler or 32/64 bit? I had a weird "null out of nowhere" bug going on

Re: What Does @ Mean?

2019-04-08 Thread JN via Digitalmars-d-learn
On Monday, 8 April 2019 at 14:19:04 UTC, XavierAP wrote: The only other example of language using @, in an almost but not quite completely different way, is C#. It's also a prefix that allows you to define names that would collide with reserved words, for example string @class = "menu"; Of cour

Re: Where is GDC being developed?

2019-03-21 Thread JN via Digitalmars-d-learn
On Thursday, 21 March 2019 at 08:19:56 UTC, Per Nordlöw wrote: At https://github.com/D-Programming-GDC/GDC/commits/master there's the heading "This repository has been archived by the owner. It is now read-only." Where will the development of GDC continue? I am not exactly sure, but if GD

Re: Setting the GtkD Include Path in dexed?

2019-03-12 Thread JN via Digitalmars-d-learn
On Tuesday, 12 March 2019 at 17:39:06 UTC, Ron Tarrant wrote: Another way of asking this, I suppose, would be: How do I pass command line arguments to dmd from within dexed? How about Project -> Project editor -> Categories -> Other -> dmdOtherOptions ?

Struct destructor

2019-03-02 Thread JN via Digitalmars-d-learn
Compare this D code: import std.stdio; struct Foo { ~this() { writeln("Destroying foo"); } } void main() { Foo[string] foos; foos["bar"] = Foo(); writeln("Preparing to destroy"); foos.remove("bar"); writeln("Ending program"); } and equivalent C++ code:

Re: Using arsd.simpledisplay module

2019-02-25 Thread JN via Digitalmars-d-learn
On Monday, 25 February 2019 at 23:35:24 UTC, Murilo wrote: I need help with the arsd.simpledisplay module. Is there anyone there who knows about it? I have doubts concerning SimpleWindow.eventLoop(). I'm pretty sure Adam D. Ruppe knows about it since he's the author :) What exactly is the q

Re: How to setup dub to use x86 and x64 dll's when appropriate?

2019-02-25 Thread JN via Digitalmars-d-learn
On Tuesday, 26 February 2019 at 04:20:27 UTC, Michelle Long wrote: On Tuesday, 26 February 2019 at 04:17:04 UTC, Michelle Long wrote: e.g., using sdl for different versions and have it automatically switch. What would be nice is if one could stick all the files for x86 in one dir and x64 in t

Re: How to call other variadic function with the same arguments?

2019-02-24 Thread JN via Digitalmars-d-learn
On Sunday, 24 February 2019 at 13:09:15 UTC, Victor Porton wrote: Let f be a variadic function: Result f(...); How to implement variadic function g which calls f with the same arguments as one it receives? Result g(...) { // ... } void f(A...)(A a) { foreach(t; a) writeln(t);

Re: Windows Defender won't let me install DMD

2019-02-19 Thread JN via Digitalmars-d-learn
On Monday, 18 February 2019 at 16:32:26 UTC, belkin wrote: Additional question as a beginner. What do I need to install to get started. Obviously I need a compiler (which one is best ). But I also want an IDE and so far it seems Visual D would be a best choice. Ideas? Visual D works well, as

Re: Why -I flag does not work?

2019-02-09 Thread JN via Digitalmars-d-learn
On Saturday, 9 February 2019 at 08:15:36 UTC, Victor Porton wrote: Why does -I flag in DFLAGS does not work? (Ubuntu Linux) I'm no expert on dub, but it's possible that it's overriding the import path anyway. One of the main points of dub is that you shouldn't have to handle the import paths

Re: Tricky DMD bug, but I have no idea how to report

2019-02-08 Thread JN via Digitalmars-d-learn
On Friday, 8 February 2019 at 23:30:44 UTC, H. S. Teoh wrote: On Fri, Feb 08, 2019 at 10:45:39PM +, JN via Digitalmars-d-learn wrote: [...] Anyway, I reduced the code further manually. It's very hard to reduce it any further. For example, removing the assignments in fromEulerAngles s

Re: Tricky DMD bug, but I have no idea how to report

2019-02-08 Thread JN via Digitalmars-d-learn
On Friday, 8 February 2019 at 22:11:31 UTC, H. S. Teoh wrote: Pity I still can't reproduce the problem locally. Otherwise I would reduce it even more -- e.g., eliminate std.stdio dependency and have the program fail on assert(obj != null), and a bunch of other things to make it easier for compi

Re: Tricky DMD bug, but I have no idea how to report

2019-02-08 Thread JN via Digitalmars-d-learn
On Friday, 8 February 2019 at 21:35:34 UTC, H. S. Teoh wrote: On Fri, Feb 08, 2019 at 09:23:40PM +, JN via Digitalmars-d-learn wrote: [...] I managed to greatly reduce the source code. I have filed a bug with the reduced testcase https://issues.dlang.org/show_bug.cgi?id=19662 . Haha, you

Re: Tricky DMD bug, but I have no idea how to report

2019-02-08 Thread JN via Digitalmars-d-learn
On Friday, 8 February 2019 at 09:30:12 UTC, Vladimir Panteleev wrote: On Friday, 8 February 2019 at 09:28:48 UTC, JN wrote: I will try. However, one last thing - in the example test scripts, it runs first with one compiler setting (or D version) and the second time with the other compiler setti

Re: Tricky DMD bug, but I have no idea how to report

2019-02-08 Thread JN via Digitalmars-d-learn
On Friday, 8 February 2019 at 07:30:41 UTC, Vladimir Panteleev wrote: On Thursday, 7 February 2019 at 22:16:19 UTC, JN wrote: Does it also work for dub projects? It will work if you can put all the relevant D code in one directory, which is harder for Dub, as it likes to pull dependencies fr

Re: Tricky DMD bug, but I have no idea how to report

2019-02-07 Thread JN via Digitalmars-d-learn
On Thursday, 7 February 2019 at 03:50:32 UTC, Vladimir Panteleev wrote: On Monday, 17 December 2018 at 21:59:59 UTC, JN wrote: while working on my game engine project, I encountered a DMD codegen bug. It occurs only when compiling in release mode, debug works. Old thread, but FWIW, such bugs

Re: Tricky DMD bug, but I have no idea how to report

2019-02-06 Thread JN via Digitalmars-d-learn
On Wednesday, 6 February 2019 at 22:22:26 UTC, H. S. Teoh wrote: Of course, I've no clue whether this is the cause of your problems -- it's just one of many possibilities. Pointer bugs are nasty things to debug, regardless of whether or not they've been abstracted away in nicer clothing. I st

Re: Tricky DMD bug, but I have no idea how to report

2019-02-06 Thread JN via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 22:56:19 UTC, H. S. Teoh wrote: Since no explicit slicing was done, there was no compiler error / warning of any sort, and it wasn't obvious from the code what had happened. By the time doSomething() was called, it was already long past the source of the problem

Re: crashing with no stack trace, why?

2019-02-01 Thread JN via Digitalmars-d-learn
On Thursday, 31 January 2019 at 11:09:56 UTC, DanielG wrote: However it was simply crashing with an exit code (-1073740771 / ‭0xC41D‬), and I was having a heck of a time trying to debug on Windows. (Shoutout to the revamped WinDbg Preview, couldn't get anything else to work!) For Windows,

Re: How to disable/hide constructor when using factory method?

2019-01-24 Thread JN via Digitalmars-d-learn
On Thursday, 24 January 2019 at 12:52:47 UTC, Arafel wrote: You are declaring the constructor, but not defining it, i.e. you're telling the compiler that it's in some other compilation unit. The compiler won't complain, but the linker will. If you replace: [...] with: [...] it should

Re: How to disable/hide constructor when using factory method?

2019-01-24 Thread JN via Digitalmars-d-learn
On Wednesday, 23 January 2019 at 19:41:44 UTC, Alex wrote: On Wednesday, 23 January 2019 at 19:26:37 UTC, JN wrote: class Foo { static Foo makeFoo() { Foo f = new Foo(); return f; } } void main() { Foo f = Foo.makeFoo(); } For a code like this. I'd like all user

How to disable/hide constructor when using factory method?

2019-01-23 Thread JN via Digitalmars-d-learn
class Foo { static Foo makeFoo() { Foo f = new Foo(); return f; } } void main() { Foo f = Foo.makeFoo(); } For a code like this. I'd like all users of the class to be forced to create instances using the static method makeFoo. I want to disallow "new Foo()". But

  1   2   >