Re: need help to get member function const address

2020-03-19 Thread Boris Carvajal via Digitalmars-d-learn
On Thursday, 19 March 2020 at 14:43:53 UTC, Steven Schveighoffer 
wrote:
I think this is an invalid limitation, you should file an issue 
at https://issues.dlang.org


essentially, with your sample A struct:

const f1 =  // OK
const f2 =  // Error, not constant expression

Both these should be valid,  is not a delegate, but a 
function pointer.


-Steve


https://issues.dlang.org/show_bug.cgi?id=20687
https://github.com/dlang/dmd/pull/10946


Re: Best way to learn 2d games with D?

2020-03-19 Thread Kagamin via Digitalmars-d-learn
On Thursday, 19 March 2020 at 13:10:29 UTC, Steven Schveighoffer 
wrote:

Similar for me but not GameMaker but RPG Maker.


I've seen all your work on the language, and this is a pretty 
good endorsement.


Not sure if I'm ready to pay for it though, I want to make sure 
his motivation/drive is not going to fizzle out ;)


IME RPG Maker has bad support for animations and shines in mostly 
static turn based RPG battles. Some games try to do nontrivial 
animations, but they become very slow slideshows with many 
seconds between slides. Not sure which game he would prefer to 
make.


Re: @future attribute / @future keyword?

2020-03-19 Thread Mathias Lang via Digitalmars-d-learn
On Wednesday, 18 March 2020 at 14:23:28 UTC, Steven Schveighoffer 
wrote:


Honestly, I think that concept was never fully implemented (or 
maybe followed properly). Simply because there has not been 
much complaint about symbols being added "too quickly".


99.99% of the time, you add a symbol to a module, and there are 
no ill effects. The problem at the time was a significant one 
for Sociomantic, I believe because of a change that they needed 
for switching from Tango to druntime.


If you grep druntime, there are 2 usages, both from about 2-3 
years ago. Both were either submitted by sociomantic, or asked 
to add the @__future attribute from them.


I'm guessing that either interest was lost in keeping this up, 
or didn't notice when things were added, and it didn't affect 
them. Seems like all the focus was on the exception hierarchy 
(which needs TLC anyway). Maybe someone from that org can 
identify how this has helped them.


The whole concept itself has some rather obscure use cases. 
Perhaps in the future there will be an obvious use case, and we 
will be glad that we have it.


-Steve


Yep that feature is completely under-documented. It ended up 
being important to Sociomantic because we introduced `message` in 
`Exception`, as our `Exception` are reusable and use a buffer to 
minimize allocations, but said `message` broke a bunch of code 
because other `Exception`-derived class had implemented their own 
method that clashed with that very common name. In addition, some 
shadowing might have been involved at the time, which made the 
issue painful to track down.


It is less important to mainstream D than it was to Sociomantic 
mainly due to the differences in our approaches. Sociomantic code 
relied heavily on OOP, while mainstream D does not. New symbols 
in Phobos are rare, and rarely conflict with other modules. 
Adding a new overload in an overload set is guaranteed to not 
conflict since the change from protection to visibility.


I like to see it this way: Any new virtual function (and 
potentially new field) in a derived class relies on the absence 
of such name existing in any of its ancestor. If it does exist, 
or is introduced, the compiler will complain about `override` not 
being used. On the other hand, a new symbol in a module does not 
have this requirement (there is still potential for breaking 
change: e.g. if you introduce an overload that conflict, for 
example adding a `const(char)[]` overload to a function that has 
a `const(char)*` overload and no `string` overload).


To answer the OP: It is still in the language, and there's a test 
for it in druntime 
(https://github.com/dlang/druntime/blob/master/test/exceptions/src/future_message.d). But yeah, no one uses it.


Re: need help to get member function const address

2020-03-19 Thread Steven Schveighoffer via Digitalmars-d-learn

On 3/19/20 9:40 AM, Calvin P wrote:

On Monday, 16 March 2020 at 18:43:47 UTC, Steven Schveighoffer wrote:


enum A0 = 

Note that you can't call it at all, but you can get the function 
pointer, and put it into a delegate later by assigning .funcptr.


void main()
{
    A a;
    void delegate() dg;
    dg.ptr = 
    dg.funcptr = A0;
    dg(); // calls a.d()
}



Thanks for the tips, Steve.

I need to put them into a big const struct to use on runtime,  so they 
can not be modify on runtime by mistake.


I can not put the address into enum,  because  Error: need this to access d

add cast(void*) still get same error:

enum callee_ptr = cast(void*) &(__traits(getMember, A, "d")); // Error: 
need this to access d


but I come up with a workaround:

static void* getCallee() pure @nogc nothrow {
     enum callee_ptr = &(__traits(getMember, App, name));
     return callee_ptr;
}

__gshared const AppHelper  APP_HELPER = {,  ..};


I'm not sure this is what you want. Essentially the address of the 
getCallee function is going to be put into AppHelper, so you are still 
fetching the function address at runtime.


What might be best is simply to use a static ctor to build the struct 
you want (as long as it's not betterC):


const AppHelper APP_HELPER;
share static this()
{
   APP_HELPER = ...;
}

It's kind of strange to me that you can't evaluate  but you can 
evaluate  at compile time.


Even stranger that it works as an enum, but not as a const function 
pointer. I too cannot find a way to make it work.


I think this is an invalid limitation, you should file an issue at 
https://issues.dlang.org


essentially, with your sample A struct:

const f1 =  // OK
const f2 =  // Error, not constant expression

Both these should be valid,  is not a delegate, but a function pointer.

-Steve


Re: need help to get member function const address

2020-03-19 Thread Calvin P via Digitalmars-d-learn

On Thursday, 19 March 2020 at 13:23:41 UTC, Adam D. Ruppe wrote:


Check the error message there... you already have a function 
pointer, no need to use the .funcptr metod.


It is a bit weird though because it actually EXCLUDES the 
hidden argument for `this`. I prefer doing wrapper functions 
usually.



Thanks for the tips,   I can get it into enum but not be able to 
use it as const at compile time. I come up with this workaround:



static void* getCallee() pure @nogc nothrow {
enum callee_ptr = &(__traits(getMember, App, name));
return callee_ptr;
}

__gshared const AppHelper  APP_HELPER = {,  ..};


Re: need help to get member function const address

2020-03-19 Thread Calvin P via Digitalmars-d-learn
On Monday, 16 March 2020 at 18:43:47 UTC, Steven Schveighoffer 
wrote:


enum A0 = 

Note that you can't call it at all, but you can get the 
function pointer, and put it into a delegate later by assigning 
.funcptr.


void main()
{
A a;
void delegate() dg;
dg.ptr = 
dg.funcptr = A0;
dg(); // calls a.d()
}

-Steve


Thanks for the tips, Steve.

I need to put them into a big const struct to use on runtime,  so 
they can not be modify on runtime by mistake.


I can not put the address into enum,  because  Error: need this 
to access d


add cast(void*) still get same error:

enum callee_ptr = cast(void*) &(__traits(getMember, A, "d")); //  
Error: need this to access d


but I come up with a workaround:

static void* getCallee() pure @nogc nothrow {
enum callee_ptr = &(__traits(getMember, App, name));
return callee_ptr;
}

__gshared const AppHelper  APP_HELPER = {,  ..};








Re: need help to get member function const address

2020-03-19 Thread Adam D. Ruppe via Digitalmars-d-learn

On Thursday, 19 March 2020 at 04:30:32 UTC, Calvin P wrote:
my question is, how to get it in compile time like static 
function address:


=
struct A {
 void d(){};
 static void fn(){};
}

enum FN =   // static method address is ok
enum A1 = (&__traits(getMember, A,"d")).funcptr; // Error: no 
property funcptr for type void function()


Check the error message there... you already have a function 
pointer, no need to use the .funcptr metod.


It is a bit weird though because it actually EXCLUDES the hidden 
argument for `this`. I prefer doing wrapper functions usually.


Re: Best way to learn 2d games with D?

2020-03-19 Thread Steven Schveighoffer via Digitalmars-d-learn

On 3/19/20 2:22 AM, dangbinghoo wrote:

On Sunday, 15 March 2020 at 17:58:58 UTC, Steven Schveighoffer wrote:
I want to try and learn how to write 2d games. I'd prefer to do it 
with D.


I've found a ton of tutorials on learning 2d gaming with other 
languages. Is there a place to look that uses D for learning? Should I 
just start with another language and then migrate to D later? Anyone 
recommend any specific tutorial/book?




there's a youtube channel teaching 2D game dev. using dlang:

https://www.youtube.com/channel/UCK3fxU3_7tzBhZZ_6rljAQA/videos


Oh wow, that is awesome! I'll take a look. Thanks.

-Steve


Re: Best way to learn 2d games with D?

2020-03-19 Thread Steven Schveighoffer via Digitalmars-d-learn

On 3/18/20 1:37 AM, bauss wrote:

On Tuesday, 17 March 2020 at 23:09:32 UTC, Dennis wrote:

On Tuesday, 17 March 2020 at 22:47:43 UTC, Sebastiaan Koppe wrote:
Dont trust that marketing, there is actually decent scripting in 
gamemaker, which you'll need if you get creative.


Second that. GameMaker is how I got into programming at age 12, and 
look where I ended up ;)


Similar for me but not GameMaker but RPG Maker.


I've seen all your work on the language, and this is a pretty good 
endorsement.


Not sure if I'm ready to pay for it though, I want to make sure his 
motivation/drive is not going to fizzle out ;)


-steve


Re: need help to get member function const address

2020-03-19 Thread Calvin P via Digitalmars-d-learn

On Thursday, 19 March 2020 at 06:34:40 UTC, Alex wrote:
A non-static member method can use the context of the struct 
where it is defined in. E.g. it could alter a member variable.
This context has to be constructed at run time (and there could 
be many instances of the context) and does not exist in compile 
time. Therefore the difference to the static method.


I am not try to get the context, I just need the function address 
which is const and should able to get at compile time.



On Thursday, 19 March 2020 at 09:13:42 UTC, Boris Carvajal wrote:

On Thursday, 19 March 2020 at 04:30:32 UTC, Calvin P wrote:

You can assemble a delegate with an struct pointer or class 
reference and a function member pointer.


Sorry for duplicate thread.

The last time I submit my question on web, it keep get blocked. I 
thought it was not submitted successfully, so I submit from draft 
again.


Re: need help to get member function const address

2020-03-19 Thread Boris Carvajal via Digitalmars-d-learn

On Thursday, 19 March 2020 at 04:30:32 UTC, Calvin P wrote:

I use this code to get member function address on runtime:

=
struct A {
   this(){};
}
auto ctor = (&__traits(getMember, A.init,"__ctor")).funcptr;
=


my question is, how to get it in compile time like static 
function address


You asked the same question two days ago.
Check the reply.
https://forum.dlang.org/post/r4ohd3$2e94$1...@digitalmars.com

You can assemble a delegate with an struct pointer or class 
reference and a function member pointer.


Re: Best way to learn 2d games with D?

2020-03-19 Thread German Diago via Digitalmars-d-learn

My two cents doing some 2D stuff for a while (a cards game).

1. stick to SDL2 if you want to have something that will work in 
many places. SFML AFAIK is not so compatible.


From there, maybe I would start by mixing SDL2* libraries and 
using D with extern(C) interfaces if needed unless there is a 
well-maintained wrapper.


The rest of the alternatives just brought trouble to me when 
trying to run in many systems.


Re: OR in version conditional compilation

2020-03-19 Thread Kagamin via Digitalmars-d-learn

https://issues.dlang.org/show_bug.cgi?id=19495#c1


Re: need help to get member function const address

2020-03-19 Thread Alex via Digitalmars-d-learn

On Thursday, 19 March 2020 at 04:30:32 UTC, Calvin P wrote:

I use this code to get member function address on runtime:

=
struct A {
   this(){};
}
auto ctor = (&__traits(getMember, A.init,"__ctor")).funcptr;
=


my question is, how to get it in compile time like static 
function address:


=
struct A {
 void d(){};
 static void fn(){};
}

enum FN =   // static method address is ok
enum A0 = &(A.d).funcptr; // Error: need this for d of type 
void()
enum A1 = (&__traits(getMember, A,"d")).funcptr; // Error: no 
property funcptr for type void function()
enum A2 = (&__traits(getMember, A.init,"d")).funcptr; //  
Error: (().d).funcptr cannot be evaluated at compile time

=


A non-static member method can use the context of the struct 
where it is defined in. E.g. it could alter a member variable.
This context has to be constructed at run time (and there could 
be many instances of the context) and does not exist in compile 
time. Therefore the difference to the static method.


Re: Best way to learn 2d games with D?

2020-03-19 Thread dangbinghoo via Digitalmars-d-learn
On Sunday, 15 March 2020 at 17:58:58 UTC, Steven Schveighoffer 
wrote:
I want to try and learn how to write 2d games. I'd prefer to do 
it with D.


I've found a ton of tutorials on learning 2d gaming with other 
languages. Is there a place to look that uses D for learning? 
Should I just start with another language and then migrate to D 
later? Anyone recommend any specific tutorial/book?


-Steve


there's a youtube channel teaching 2D game dev. using dlang:

https://www.youtube.com/channel/UCK3fxU3_7tzBhZZ_6rljAQA/videos