Re: How to use @safe when a C library integration needed

2023-04-15 Thread Leonardo via Digitalmars-d-learn
On Friday, 14 April 2023 at 16:19:22 UTC, Paul Backus wrote: On Friday, 14 April 2023 at 14:10:41 UTC, Leonardo wrote: [...] No, there isn't. C is an unsafe language, so if you want to call C from `@safe` code, you have to do the work to make sure that each individual call is `@safe`.

Re: How to use @safe when a C library integration needed

2023-04-14 Thread Leonardo via Digitalmars-d-learn
On Monday, 23 January 2023 at 16:46:48 UTC, Dom DiSc wrote: On Monday, 23 January 2023 at 16:36:21 UTC, Leonardo wrote: Hello. How to use @safe when a C library integration needed? Everything need a system function... ```d @safe fn() { // lot of safe stuff () @trusted { // in

How to use @safe when a C library integration needed

2023-01-23 Thread Leonardo via Digitalmars-d-learn
Hello. How to use @safe when a C library integration needed? Everything need a system function...

Re: unique_ptr | Unique for autoclose handle

2022-12-14 Thread Leonardo via Digitalmars-d-learn
On Wednesday, 14 December 2022 at 11:30:07 UTC, Vitaliy Fadeev wrote: Hi! I open a device under Windows: ``` HANDLE h = CreateFileW( ... ); ``` in procedure: ``` HANDLE open_keyboard_device2( LPCWSTR path, int* error_number ) { ... HANDLE dev_handle = CreateFileW(

Re: How to use version in dub?

2022-12-14 Thread Leonardo via Digitalmars-d-learn
On Tuesday, 13 December 2022 at 20:35:28 UTC, ryuukk_ wrote: On Tuesday, 13 December 2022 at 20:01:40 UTC, torhu wrote: On Tuesday, 13 December 2022 at 19:50:15 UTC, torhu wrote: On Tuesday, 13 December 2022 at 19:28:44 UTC, Leonardo A wrote: Hello. How to use version in dub?

Re: How to use ImportC?

2022-03-18 Thread Leonardo via Digitalmars-d-learn
On Friday, 4 March 2022 at 17:17:17 UTC, MoonlightSentinel wrote: On Friday, 4 March 2022 at 01:30:00 UTC, Leonardo wrote: Thanks but not worked here. ``` [leonardo@leonardo-pc dimportc]$ dmd --version DMD64 D Compiler v2.098.1 ``` Please retry with the

Re: How to use ImportC?

2022-03-03 Thread Leonardo via Digitalmars-d-learn
Thanks but not worked here. ``` [leonardo@leonardo-pc dimportc]$ dmd --version DMD64 D Compiler v2.098.1 Copyright (C) 1999-2021 by The D Language Foundation, All Rights Reserved written by Walter Bright [leonardo@leonardo-pc dimportc]$ ls foo.c program.d [leonardo@leonardo-pc dimportc]$ cat

How to use ImportC?

2022-03-03 Thread Leonardo via Digitalmars-d-learn
I saw the new feature called ImportC, it's cool to be able to use C code/libraries, but I'm not much experience in C and didn't understand this incomplete documentation: https://dlang.org/spec/importc.html How to use ImportC?

Re: How to dinamically create Tuples?

2021-01-28 Thread Leonardo via Digitalmars-d-learn
On Wednesday, 27 January 2021 at 17:28:00 UTC, H. S. Teoh wrote: On Wed, Jan 27, 2021 at 05:17:18PM +, Paul Backus via Digitalmars-d-learn wrote: On Wednesday, 27 January 2021 at 17:11:52 UTC, Leonardo wrote: > Hi, I want to know if are some way to dinamically create > Tuples, with

How to dinamically create Tuples?

2021-01-27 Thread Leonardo via Digitalmars-d-learn
Hi, I want to know if are some way to dinamically create Tuples, with variable size and types defined at runtime. Thanks.

Re: Is it possible to store different subclasses in one array?

2020-04-13 Thread Leonardo via Digitalmars-d-learn
On Monday, 13 April 2020 at 05:54:52 UTC, evilrat wrote: On Monday, 13 April 2020 at 04:21:48 UTC, Leonardo wrote: foreach (ref gi; GameItems) { if (gi == Weapon) gi.Attack() } How would it be? Replying myself... weapon = cast(Weapon) gi; if (weapon !is null)

Re: Is it possible to store different subclasses in one array?

2020-04-12 Thread Leonardo via Digitalmars-d-learn
On Monday, 13 April 2020 at 04:15:04 UTC, Leonardo wrote: On Monday, 13 April 2020 at 01:47:11 UTC, Adam D. Ruppe wrote: On Monday, 13 April 2020 at 01:42:51 UTC, Leonardo wrote: Is it possible to store different subclasses in one array? In C#, we have this example, but how I do that in D?

Re: Is it possible to store different subclasses in one array?

2020-04-12 Thread Leonardo via Digitalmars-d-learn
On Monday, 13 April 2020 at 01:47:11 UTC, Adam D. Ruppe wrote: On Monday, 13 April 2020 at 01:42:51 UTC, Leonardo wrote: Is it possible to store different subclasses in one array? In C#, we have this example, but how I do that in D? Did you try BaseItem[] GameItems; GameItems ~= new

Is it possible to store different subclasses in one array?

2020-04-12 Thread Leonardo via Digitalmars-d-learn
Is it possible to store different subclasses in one array? In C#, we have this example, but how I do that in D? public class BaseItem{ public string name = ""; } public class Weapon : BaseItem{ public int damage = 10; } public class Potion : BaseItem{ public int

Re: Game and GC

2018-04-05 Thread Leonardo via Digitalmars-d-learn
On Friday, 23 February 2018 at 03:25:33 UTC, Norm wrote: On Friday, 23 February 2018 at 01:54:07 UTC, Leonardo wrote: Hi, I'm new to language and games. Many people say that GC is bad and can slow down your project in some moments. What can happen if I create a game using D without worrying

Re: Game and GC

2018-02-25 Thread Leonardo via Digitalmars-d-learn
On Saturday, 24 February 2018 at 07:12:21 UTC, Guillaume Piolat wrote: From my experience a combination of the following is necessary: - not having the audio thread registered - using pools aggressively for game entities I'll read the resources you gave. Thanks for the all answers. Great

Re: Game and GC

2018-02-22 Thread Leonardo via Digitalmars-d-learn
On Friday, 23 February 2018 at 02:16:38 UTC, Jonathan M Davis wrote: The GC won't slow down your code in general (in fact, it will probably speed it up in comparison to reference counting), but whenever the GC does a collection, that means that it stops all threads that it manages. So, you

Re: Game and GC

2018-02-22 Thread Leonardo via Digitalmars-d-learn
On Friday, 23 February 2018 at 02:02:12 UTC, StickYourLeftFootIn wrote: On Friday, 23 February 2018 at 01:54:07 UTC, Leonardo wrote: Hi, I'm new to language and games. Many people say that GC is bad and can slow down your project in some moments. What can happen if I create a game using D

Game and GC

2018-02-22 Thread Leonardo via Digitalmars-d-learn
Hi, I'm new to language and games. Many people say that GC is bad and can slow down your project in some moments. What can happen if I create a game using D without worrying with memory management? (using full GC)

Re: Equivalent to nullptr

2017-05-16 Thread Leonardo via Digitalmars-d-learn
On Thursday, 4 May 2017 at 04:34:40 UTC, Stanislav Blinov wrote: In the meantime, you can get around the issue by redeclaring the function with another name and loading it manually just after calling DerelictSDL2.load(): import derelict.sdl2.sdl; __gshared SDL_bool function

Re: Equivalent to nullptr

2017-05-03 Thread Leonardo via Digitalmars-d-learn
On Thursday, 4 May 2017 at 02:45:30 UTC, Adam D. Ruppe wrote: On Thursday, 4 May 2017 at 02:12:13 UTC, Leonardo wrote: nullptr word. How I use this? Does it work if you just use `null` ? No. First I got: source/app.d(45,69): Error: expression (*SDL_EnclosePoints)(& mousePos, 1, , null) of

Equivalent to nullptr

2017-05-03 Thread Leonardo via Digitalmars-d-learn
I was trying to use Derelict-SDL2 library, and the tutorial do this code below, as C++ code has nullptr word. How I use this? - struct Ball { SDL_Rect bbox = {0, 0, 100, 100}; SDL_Point vel = {1, 1}; } - case