Re: C++/D class interop example crashes

2021-03-27 Thread Jan via Digitalmars-d-learn

On Saturday, 27 March 2021 at 18:39:53 UTC, Bastiaan Veelo wrote:
The example links objects statically. You may be experiencing 
additional challenges with crossing DLL boundaries. I have not 
yet used DLLs, but did you initialise the D runtime?


I haven't done anything extra (I'm pretty new to D). Do you mean 
calling this from the D code before using writeln?

https://dlang.org/phobos/core_runtime.html#initialize

I would have thought that happens automatically anyway.


C++/D class interop example crashes

2021-03-27 Thread Jan via Digitalmars-d-learn

I just tried to get this example to work:
https://dlang.org/spec/cpp_interface.html#using_d_classes_from_cpp

It kept crashing for me with a 'privileged instruction' error 
when the function 'bar' was executed. Finally I removed the call 
to writefln and voilĂ  it finally works.


So why does it fail? I assumed the standard library functions 
should all work.
I'm compiling with "dmd -shared -m64 -debug" and link against a 
C++ DLL that was built with VS2019. Should the D DLL not contain 
everything to be self-sufficient to use it's entire runtime 
functionality?

And if not, what other functions might be problematic?

Also, if anyone here has contacts to the people that maintain the 
samples, maybe someone should adjust the sample to not contain 
code that may break this way.


Re: Mimicking a shell

2020-01-06 Thread Jan via Digitalmars-d-learn
I think the suggestion of angel would be most fitting for my 
case. As angel said, the using the C code for D would be a 
relatively small refactor.


if you want to send like a synthetic arrow keystroke, well, 
things get ugly again, it will need to send the right series of 
bytes based on what terminal the program thinks you are.


Using arrow key etc. would be very beneficial for my case. So I 
thank Adam for his solution, but I prefer angel's one.


Thanks guys :)



Re: Mimicking a shell

2020-01-04 Thread Jan via Digitalmars-d-learn

On Sunday, 29 December 2019 at 19:21:53 UTC, Adam D. Ruppe wrote:

On Sunday, 29 December 2019 at 17:03:14 UTC, Jan wrote:

Is there a way to forward all input and output from a shell?


yes, but it is platform specific and can be a decent amount of 
code.


what OS are you on?


I am using Linux (Fedora).

Thanks, @angel. I'll take a look at your suggestion :)


Mimicking a shell

2019-12-29 Thread Jan via Digitalmars-d-learn

Hi,

Is there a way to forward all input and output from a shell? This 
implies that e.g. pressing the left arrow on the keyboard is 
immediately being forwarded to the shell and that the output from 
a shell would be *exactly* the same as output from my D program 
(that would include the prompt and VGA colouring).


Kind regards,
Jan


Re: Pass 'this' as reference

2018-09-19 Thread Jan via Digitalmars-d-learn
On Saturday, 15 September 2018 at 20:13:51 UTC, Jonathan M Davis 
wrote:
On Saturday, September 15, 2018 11:44:05 AM MDT Jan via 
Digitalmars-d-learn wrote:

[...]


No. variables are _always_ lvalues. An lvalue is an object 
which is addressable and which can therefore be assigned a 
value (ignoring issues of constness). The name comes from the 
fact that lvalues are allowed on the left-hand side of an 
assignment operation, whereas rvalues are only allowed on the 
right. e.g.


[...]


Many thanks Jonathan! :)


Re: Pass 'this' as reference

2018-09-15 Thread Jan via Digitalmars-d-learn
On Thursday, 13 September 2018 at 11:08:30 UTC, Jonathan M Davis 
wrote:

[...]


Thanks for clarifying Jonathan :)
But aren't the variables considered rvalues then?


Re: Pass 'this' as reference

2018-09-13 Thread Jan via Digitalmars-d-learn

Many thanks Adam and Steve! Works like a charm! :D
I presumed classes are lvalues. I shouldn't make things more 
complicated than they are ;-)


Pass 'this' as reference

2018-09-12 Thread Jan via Digitalmars-d-learn
I'm using D not for that long and lately I have encountered an 
issue. I have class 'Foo' with a constructor using this signature:

`this (ref Bar original)`

In the 'Bar' class itself I want to create an instance of 'Foo' 
using 'this' as parameter. Something in the way of:

`Foo foo = new Foo(ref this);`

I couldn't find anything interesting on the internet to help me. 
Could anyone help me? Many thanks in advance!