Re: Windows Console and writing Unicode characters

2021-03-30 Thread Luhrel via Digitalmars-d-learn

On Tuesday, 30 March 2021 at 13:19:02 UTC, Adam D. Ruppe wrote:

On Tuesday, 30 March 2021 at 08:31:02 UTC, Luhrel wrote:

I have been used this trick in C++, so it might also work in D:


If you follow through the link that's what I mention as being a 
bad idea and provide the code given as a more correct 
alternative.


It changes a global (well to the console) setting that persists 
after your program terminates, which can break other programs 
later, it can trigger font changes, and it doesn't actually 
always work anyway.


You're much better off calling the correct functions.


Oh okay, I never had those issues, strangely enough.

It's a good website BTW.


Re: Windows Console and writing Unicode characters

2021-03-30 Thread Luhrel via Digitalmars-d-learn

On Monday, 29 March 2021 at 02:12:57 UTC, Brad wrote:

I am new here so I will post this in Learn.

I have been doing a bit of reading on printing unicode 
characters in the Windows Console.  Specifically W10 command 
prompt.  I ran across a post by Adam Ruppe in a thread created 
a couple years ago which links a short bit of code and a quick 
discussion that Adam presents on his blog.  Here is a link to 
the specific reply I refer to: 
https://forum.dlang.org/post/sjsqqhwvlonohvwyq...@forum.dlang.org


[...]


I have been used this trick in C++, so it might also work in D:
```
import core.stdc.stdlib;
import std.stdio;

void main()
{
version(Windows)
system("chcp 65001 > NUL".ptr);
writeln("çéäö");
}
```


Re: How does one run a linux system command from a D main() fcn ?

2020-08-04 Thread Luhrel via Digitalmars-d-learn

On Tuesday, 4 August 2020 at 19:52:47 UTC, Andy Balba wrote:

i.e.  D  equivalent to C++ command system("MyExe")


https://dlang.org/library/std/process.html


Re: Pattern matching via switch?

2020-03-14 Thread Luhrel via Digitalmars-d-learn

On Saturday, 14 March 2020 at 19:04:28 UTC, 12345swordy wrote:

I.E.

switch (object)
case Type1 t1:
case Type2 t2:
case Type3 t3:


As far as I know, there's no way to do that in a switch.
However, you can do something like this:

---
void main()
{
auto i = new Type1();
foo(i);
}

void foo(T)(T type)
{
static if (is(T == Type1))
{
// ...
}
else static if (is(T == Type2))
{
// ...
}
// ...
}
---

Hope this helps


Re: Dscanner: is it possible to switch off style checks case-by-case?

2020-02-15 Thread Luhrel via Digitalmars-d-learn

On Thursday, 13 February 2020 at 17:15:50 UTC, mark wrote:

I'm starting out with GtkD and have this function:

void main(string[] args) {
Main.init(args);
auto game = new GameWindow();
Main.run();
}

and this method:

void quit(Widget widget) {
Main.quit();
}

When I run dscanner --styleCheck it reports:

./src/app.d(10:10)[warn]: Variable game is never used.
./src/app.d(22:22)[warn]: Parameter widget is never used.

These are correct. However, is it possible to switch them off 
individually?


(In Python you can switch off lint checks using a special text 
in a comment at the end of the line.)


With DLS, you can use @suppress in comment:

void quit(Widget widget) // 
@suppress(dscanner.suspicious.unused_parameter)

{
Main.quit();
}

more info: https://code.dlang.org/packages/dls

Simply install the extension to your editor.


Re: How to call a extern C++ class constructor ?

2020-02-01 Thread Luhrel via Digitalmars-d-learn
On Saturday, 1 February 2020 at 08:32:51 UTC, Ferhat Kurtulmuş 
wrote:

On Saturday, 1 February 2020 at 08:27:07 UTC, Luhrel wrote:
On Saturday, 1 February 2020 at 08:21:29 UTC, Ferhat Kurtulmuş 
wrote:


You cannot. 
https://dlang.org/spec/cpp_interface.html#using_cpp_classes_from_d


You must use a factory method like createInstance.


Oh I see, so there's definitively no way to call a c++ ctor 
without modifying the c++ code ?


İf you are not allowed to modify that c++ code, you can write a 
createInstance function in your custom cpp file.


That was my fear.


Re: How to call a extern C++ class constructor ?

2020-02-01 Thread Luhrel via Digitalmars-d-learn
On Saturday, 1 February 2020 at 08:21:29 UTC, Ferhat Kurtulmuş 
wrote:


You cannot. 
https://dlang.org/spec/cpp_interface.html#using_cpp_classes_from_d


You must use a factory method like createInstance.


Oh I see, so there's definitively no way to call a c++ ctor 
without modifying the c++ code ?


How to call a extern C++ class constructor ?

2020-02-01 Thread Luhrel via Digitalmars-d-learn

Hello there,

I would like to know how can I call a C++ ctor.

Actually, I have this:

C++:
CppClass.cpp

#include "CppClass.h"


AmazingCppClass::AmazingCppClass()
{
number = 124;
}

int AmazingCppClass::getNumber(bool show)
{
if (show)
printf("Number: %s", number);
return number;
}

void AmazingCppClass::add(int num)
{
number += num;
}

CppClass.h:

#include 


class AmazingCppClass
{
private:
int number;

public:
AmazingCppClass();
int getNumber(bool show);
void add(int num);
};


D:
app.d

import std.stdio;

void main()
{
auto dcpp = new AmazingCppClass();
dcpp.getNumber(true); //segfault here
}

extern(C++) class AmazingCppClass
{
this();

int getNumber(bool show);

void add(int num);
}


But somehow I got a segfault on dcpp.getNumber(true).
I found that there's a __cpp_new 
(https://dlang.org/phobos/core_stdcpp_new_.html), but I have no 
idea how to use it and the doc doesn't say a lot about this 
(https://dlang.org/spec/cpp_interface.html#using_cpp_classes_from_d)


Do you guys know ?


Re: bindbc-opengl: Now drawing triangle

2020-01-27 Thread Luhrel via Digitalmars-d-learn

On Saturday, 25 January 2020 at 21:33:09 UTC, JN wrote:


I assume it's working now?


Yup it works.


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.


Wow that's what I need. Thanks for sharing this.




Re: bindbc-opengl: Now drawing triangle

2020-01-25 Thread Luhrel via Digitalmars-d-learn
On Saturday, 25 January 2020 at 20:21:31 UTC, lithium iodate 
wrote:


In line 146

glBufferData(GL_ARRAY_BUFFER, vertices.sizeof, vertices.ptr, 
GL_STATIC_DRAW);


you are calculating the size of `vertices` incorrectly. As 
`vertices` is a dynamic array, .sizeof will only give you the 
size of the array reference (size_t.sizeof * 2, note that 
.sizeof will always give you a compile-time constant in D).

Change it to

glBufferData(GL_ARRAY_BUFFER, vertices.length * GLfloat.sizeof, 
vertices.ptr, GL_STATIC_DRAW);


and the data will be correctly copied into the buffer.


Many thanks !


bindbc-opengl: Now drawing triangle

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

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 ?