Re: Is there any writeln like functions without GC?

2019-11-02 Thread 9il via Digitalmars-d-learn

On Thursday, 31 October 2019 at 03:56:56 UTC, lili wrote:

Hi:
   why writeln need GC?


See also Mir's @nogc formatting module

https://github.com/libmir/mir-runtime/blob/master/source/mir/format.d


Re: Is there any writeln like functions without GC?

2019-11-02 Thread Seb via Digitalmars-d-learn

On Thursday, 31 October 2019 at 16:03:22 UTC, bachmeier wrote:
On Thursday, 31 October 2019 at 15:11:42 UTC, Ferhat Kurtulmuş 
wrote:


It would be nice if one reimplement writeln of Phobos by 
bypassing gc and use a custom nogc exception as described 
here*? Of course I can imagine that it would be a breaking 
change in the language and requires so much work for it to be 
compatible with other std modules/language features.


*: 
https://www.auburnsounds.com/blog/2016-11-10_Running-D-without-its-runtime.html


I can't imagine any possibility we'll ever see a breaking 
change to writeln. It would have to be an addition to Phobos.


Yep or Phobos 2 which is more realistic at this point.


Re: Is there any writeln like functions without GC?

2019-11-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, October 31, 2019 9:11:42 AM MDT Ferhat Kurtulmuş via 
Digitalmars-d-learn wrote:
> On Thursday, 31 October 2019 at 13:46:07 UTC, Adam D. Ruppe wrote:
> > On Thursday, 31 October 2019 at 03:56:56 UTC, lili wrote:
> >> Hi:
> >>why writeln need GC?
> >
> > It almost never does, it just keeps the option open in case
> >
> > * it needs to throw an exception (like if stdout is closed)
> >
> > * you pass it a custom type with toString that uses GC
> >
> > @nogc is just super strict and doesn't even allow for rare
> > cases.
>
> It would be nice if one reimplement writeln of Phobos by
> bypassing gc and use a custom nogc exception as described here*?
> Of course I can imagine that it would be a breaking change in the
> language and requires so much work for it to be compatible with
> other std modules/language features.
>
> *:
> https://www.auburnsounds.com/blog/2016-11-10_Running-D-without-its-runtime
> .html

You can always just use printf.

- Jonathan M Davis






Re: Unable to pass a D function member to a C callback

2019-11-02 Thread Dennis via Digitalmars-d-learn

On Saturday, 2 November 2019 at 20:42:29 UTC, Luh wrote:

Yup that's it !
Many thanks !


One word of warning: ensure the C library does not have the only 
reference to your Game class instance, or the garbage collector 
might deallocate it since it does not scan threads created by C 
libraries.


See:
https://dlang.org/spec/garbage.html#gc_foreign_obj


Re: Unable to pass a D function member to a C callback

2019-11-02 Thread Luh via Digitalmars-d-learn

On Saturday, 2 November 2019 at 19:55:58 UTC, Dennis wrote:

On Saturday, 2 November 2019 at 19:42:54 UTC, Luh wrote:

So I think I just can't. :(


Is that `void* c` in the callback a context pointer by any 
chance?
That's a common thing in C callbacks precisely for purposes 
like this.
You can cast your class to a void* when you register the 
callback and in the callback function cast it back to a class 
and call process on that.


I don't know what C library you're working with so can't give 
you specifics.


Yup that's it !
Many thanks !


Which is the active fork in DFL gui library ?

2019-11-02 Thread Vinod K Chandran via Digitalmars-d-learn

Hi all,
I just found that DFL gui library very interesting. But after 
some searching, i can see that DFL is inactive and there is few 
other forks for it. So this is my question - Which fork is good 
for a gui development in windows platform.
BTW, i just tested the gtkD and successfully compiled a hello 
app. How do i avoid the console window when compiling gtkD app ?

Thanks in advance.


Re: Unable to pass a D function member to a C callback

2019-11-02 Thread Dennis via Digitalmars-d-learn

On Saturday, 2 November 2019 at 19:42:54 UTC, Luh wrote:

So I think I just can't. :(


Is that `void* c` in the callback a context pointer by any chance?
That's a common thing in C callbacks precisely for purposes like 
this.
You can cast your class to a void* when you register the callback 
and in the callback function cast it back to a class and call 
process on that.


I don't know what C library you're working with so can't give you 
specifics.


Re: Unable to pass a D function member to a C callback

2019-11-02 Thread Luh via Digitalmars-d-learn

On Saturday, 2 November 2019 at 18:31:28 UTC, Stefan Koch wrote:

On Saturday, 2 November 2019 at 17:49:09 UTC, Luh wrote:

Hello,

When trying to pass a D function to the C callback, the 
compiler says:


'Error: cannot implicitly convert expression &this.onProcessCb 
of type extern (C) bool delegate(const(short*) a, ulong b, 
void* c) to extern (C) bool function(const(short*), ulong, 
void*'


because my function is member of a class (compiles when the 
function is out of the class).


Is there any way to say to solve this ?
The wiki isn't very clear about the C callbacks:
https://dlang.org/spec/interfaceToC.html#callbacks

C code:

typedef bool (*onProcessCallback)(const short*, size_t, void*);



D Code:
-
class Game
{
onProcessCallback m_onProcessCb;

this()
{
m_onProcessCb = &onProcessCb; // Error here
}

void onProcess()
{
// ...
}

extern(C) bool onProcessCb(const short* a, size_t b, void* c)
{
onProcess();
return true;
}
}

private extern(C)
{
// Should call onProcess() when executed by the C lib
	alias onProcessCallback = bool function(const short*, size_t, 
void*);

}
-


you are missing a static in your member function's signature.
The callback is not providing a this pointer.


My problem is, that the onProcess function should not be static 
because it uses a variable inside the class.


like:
-
class Game
{
private short[] m_a;

void onProcess(short[] a)
{
m_a ~= a;
// ...
}

extern(C) bool onProcessCb(const short* a, size_t b, void* c)
{
onProcess();
return true;
}
}
-

So I think I just can't. :(


Re: Unable to pass a D function member to a C callback

2019-11-02 Thread Alex via Digitalmars-d-learn

On Saturday, 2 November 2019 at 17:49:09 UTC, Luh wrote:

Hello,

When trying to pass a D function to the C callback, the 
compiler says:


'Error: cannot implicitly convert expression &this.onProcessCb 
of type extern (C) bool delegate(const(short*) a, ulong b, 
void* c) to extern (C) bool function(const(short*), ulong, 
void*'


because my function is member of a class (compiles when the 
function is out of the class).


Is there any way to say to solve this ?
The wiki isn't very clear about the C callbacks:
https://dlang.org/spec/interfaceToC.html#callbacks

C code:

typedef bool (*onProcessCallback)(const short*, size_t, void*);



D Code:
-
class Game
{
onProcessCallback m_onProcessCb;

this()
{
m_onProcessCb = &onProcessCb; // Error here
}

void onProcess()
{
// ...
}

extern(C) bool onProcessCb(const short* a, size_t b, void* c)
{
onProcess();
return true;
}
}

private extern(C)
{
// Should call onProcess() when executed by the C lib
	alias onProcessCallback = bool function(const short*, size_t, 
void*);

}
-


This is because onProcessCb is a member of an object. Therefore, 
it carries also the information about the context, which includes 
e.g. all members of the class.


Due to this onProcessCb is a delegate, which is something 
different from a function, cf.

https://dlang.org/spec/function.html#closures

So, there is a type mismatch.



Re: Unable to pass a D function member to a C callback

2019-11-02 Thread Stefan Koch via Digitalmars-d-learn

On Saturday, 2 November 2019 at 17:49:09 UTC, Luh wrote:

Hello,

When trying to pass a D function to the C callback, the 
compiler says:


'Error: cannot implicitly convert expression &this.onProcessCb 
of type extern (C) bool delegate(const(short*) a, ulong b, 
void* c) to extern (C) bool function(const(short*), ulong, 
void*'


because my function is member of a class (compiles when the 
function is out of the class).


Is there any way to say to solve this ?
The wiki isn't very clear about the C callbacks:
https://dlang.org/spec/interfaceToC.html#callbacks

C code:

typedef bool (*onProcessCallback)(const short*, size_t, void*);



D Code:
-
class Game
{
onProcessCallback m_onProcessCb;

this()
{
m_onProcessCb = &onProcessCb; // Error here
}

void onProcess()
{
// ...
}

extern(C) bool onProcessCb(const short* a, size_t b, void* c)
{
onProcess();
return true;
}
}

private extern(C)
{
// Should call onProcess() when executed by the C lib
	alias onProcessCallback = bool function(const short*, size_t, 
void*);

}
-


you are missing a static in your member function's signature.
The callback is not providing a this pointer.


Unable to pass a D function member to a C callback

2019-11-02 Thread Luh via Digitalmars-d-learn

Hello,

When trying to pass a D function to the C callback, the compiler 
says:


'Error: cannot implicitly convert expression &this.onProcessCb of 
type extern (C) bool delegate(const(short*) a, ulong b, void* c) 
to extern (C) bool function(const(short*), ulong, void*'


because my function is member of a class (compiles when the 
function is out of the class).


Is there any way to say to solve this ?
The wiki isn't very clear about the C callbacks:
https://dlang.org/spec/interfaceToC.html#callbacks

C code:

typedef bool (*onProcessCallback)(const short*, size_t, void*);



D Code:
-
class Game
{
onProcessCallback m_onProcessCb;

this()
{
m_onProcessCb = &onProcessCb; // Error here
}

void onProcess()
{
// ...
}

extern(C) bool onProcessCb(const short* a, size_t b, void* c)
{
onProcess();
return true;
}
}

private extern(C)
{
// Should call onProcess() when executed by the C lib
	alias onProcessCallback = bool function(const short*, size_t, 
void*);

}
-


Re: Execute certain Tests?

2019-11-02 Thread Paul Backus via Digitalmars-d-learn

On Saturday, 2 November 2019 at 17:27:14 UTC, Martin Brezel wrote:

Is there a trick to execute only the test, defined in one file?
Or the Tests of a certain Module?

Or in general: How to avoid to execute all the tests, when 
running "dub test"?

It doesn't has to be dub, though.


dmd -unittest -run -main module.d


Re: Execute certain Tests?

2019-11-02 Thread Max Haughton via Digitalmars-d-learn

On Saturday, 2 November 2019 at 17:27:14 UTC, Martin Brezel wrote:

Is there a trick to execute only the test, defined in one file?
Or the Tests of a certain Module?

Or in general: How to avoid to execute all the tests, when 
running "dub test"?

It doesn't has to be dub, though.


Not by default, if you know the language well then you can use 
UDAs to write a fancy test runner in ten minutes, if not then use 
Attila's unit-threaded (or similar)



Max


Execute certain Tests?

2019-11-02 Thread Martin Brezel via Digitalmars-d-learn

Is there a trick to execute only the test, defined in one file?
Or the Tests of a certain Module?

Or in general: How to avoid to execute all the tests, when 
running "dub test"?

It doesn't has to be dub, though.