Re: mir.algebraic: Visitor cannot be called

2020-12-09 Thread Andre Pany via Digitalmars-d-learn
On Thursday, 10 December 2020 at 05:49:12 UTC, 9il wrote: On Wednesday, 9 December 2020 at 14:34:18 UTC, Andre Pany wrote: [...] For .member access mir.algebraic checks at compile time that all underlying types (except typeof(null)) can be called with provided arguments. It is kind of API pr

Re: mir.algebraic: Visitor cannot be called

2020-12-09 Thread 9il via Digitalmars-d-learn
On Wednesday, 9 December 2020 at 14:34:18 UTC, Andre Pany wrote: Hi, I want to port some Python coding and try have as much similiar coding as possible. I thought I can have a mir variant which stores either class A or B and I can call at runtime a method like this: ``` /+ dub.sdl:

Re: where is the memory corruption?

2020-12-09 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 9 December 2020 at 21:21:58 UTC, ag0aep6g wrote: D's wchar is not C's wchar_t. D's wchar is 16 bits wide. The width of C's wchar_t is implementation-defined. In your case it's probably 32 bits. In D, C's wchar_t is available as `core.stdc.stddef.wchar_t`. http://dpldocs.info/e

Re: where is the memory corruption?

2020-12-09 Thread ag0aep6g via Digitalmars-d-learn
On 09.12.20 21:35, Jack wrote: I'm on linux/opensuse, trying to pass a wchar_* from C to D but I'm getting only the first letter of that string. Could someone help figure out why? this is the piece of D code: extern(C) export void sayHello(const (wchar) *s) [...] and below the piece of C cod

Re: where is the memory corruption?

2020-12-09 Thread Dukc via Digitalmars-d-learn
On Wednesday, 9 December 2020 at 20:35:21 UTC, Jack wrote: the output is "h" rather "hello". What am I missing? In the sayHello function, you are converting a pointer to utf16 character into utf8 string, not utf16 string to utf8 string. Convert the C wstring to a D `wstring` first (std.strin

where is the memory corruption?

2020-12-09 Thread Jack via Digitalmars-d-learn
I'm on linux/opensuse, trying to pass a wchar_* from C to D but I'm getting only the first letter of that string. Could someone help figure out why? this is the piece of D code: extern(C) export void sayHello(const (wchar) *s) { import std.stdio : writeln; import std.conv : to;

Re: How to make Create Window Work?

2020-12-09 Thread Ruby The Roobster via Digitalmars-d-learn
On Wednesday, 9 December 2020 at 17:57:49 UTC, Adam D. Ruppe wrote: C will cast 0 to null implicitly, D will not. If there's ever a case where you need to pass a number as a handle (like some HBRUSHe among others), you then explicitly cast it like `cast(HANDLE) -1`. (HANDLE is an alias to voi

Re: How to make Create Window Work?

2020-12-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 9 December 2020 at 17:45:18 UTC, Ruby The Roobster wrote: 0, // window menu here, that's the only int you do and I'm pretty sure that's supposed a be a HMENU which is a HANDLE, which is a void* rather than an int. C will cast 0 to null

Re: How to make Create Window Work?

2020-12-09 Thread Ruby The Roobster via Digitalmars-d-learn
Also, here is the error in full: E:\Users\User\Desktop\tet.d|100| cannot pass argument `0` of type `int` to parameter `void* i`|

Re: How to make Create Window Work?

2020-12-09 Thread Ruby The Roobster via Digitalmars-d-learn
On Wednesday, 9 December 2020 at 17:42:50 UTC, Adam D. Ruppe wrote: On Wednesday, 9 December 2020 at 17:37:16 UTC, Ruby The Roobster wrote: It's not the 'NULL' that's the error. I know. It doesn't compile because of the '0' . That is what I need to fix, since I want to make a WM_COMMAND for

Re: How to make Create Window Work?

2020-12-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 9 December 2020 at 17:37:16 UTC, Ruby The Roobster wrote: It's not the 'NULL' that's the error. I know. It doesn't compile because of the '0' . That is what I need to fix, since I want to make a WM_COMMAND for that button. Use lowercase `null` instead.

Re: How to make Create Window Work?

2020-12-09 Thread Ruby The Roobster via Digitalmars-d-learn
On Wednesday, 9 December 2020 at 17:32:57 UTC, Adam D. Ruppe wrote: On Wednesday, 9 December 2020 at 17:25:10 UTC, Ruby The Roobster wrote: CreateWindow("BUTTON".toUTF16z, // window class name fyi for a string literal like this you can just do "BUTTON"w.ptr // note the w Th

Re: How to make Create Window Work?

2020-12-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 9 December 2020 at 17:25:10 UTC, Ruby The Roobster wrote: CreateWindow("BUTTON".toUTF16z, // window class name fyi for a string literal like this you can just do "BUTTON"w.ptr // note the w This gives an error saying: Cannot pas argument of type 'int' to argum

How to make Create Window Work?

2020-12-09 Thread Ruby The Roobster via Digitalmars-d-learn
Here is the code im using: extern(Windows) LRESULT WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) nothrow { scope (failure) assert(0); HDC hdc; PAINTSTRUCT ps; RECT rect; switch (message) { case WM_CREATE: CreateWindow("BUTTON".toUT

Re: To use or not immutable?

2020-12-09 Thread Dukc via Digitalmars-d-learn
On Wednesday, 9 December 2020 at 16:47:43 UTC, Jack wrote: Do you use it in your code base? are there some design flaws, like there's in C++'s const, which I'm not aware of? There are downsides, Jonathan Davis has written about them: http://www.jmdavisprog.com/articles/why-const-sucks.html B

To use or not immutable?

2020-12-09 Thread Jack via Digitalmars-d-learn
I'm coding with visual studio code and now it shows a yellow mark on variables that is never modified and that could be marked as const or immutable. I think that makes sense, so I think I'll be using it. Do you use it in your code base? are there some design flaws, like there's in C++'s const,

mir.algebraic: Visitor cannot be called

2020-12-09 Thread Andre Pany via Digitalmars-d-learn
Hi, I want to port some Python coding and try have as much similiar coding as possible. I thought I can have a mir variant which stores either class A or B and I can call at runtime a method like this: ``` /+ dub.sdl: name "app" dependency "mir-core" version="1.1.51" +/ imp