Re: readline / Gnu readline

2020-01-29 Thread Michael via Digitalmars-d-learn

On Thursday, 30 January 2020 at 06:15:54 UTC, Mike Parker wrote:

Is your source file named rl.d? And are you running dmd in the 
source file's directory?


No, I did not. Changed it now and it works with dmd. Great!
Tried the same with rdmd I'm getting a linker error.




Re: readline / Gnu readline

2020-01-29 Thread Mike Parker via Digitalmars-d-learn

On Thursday, 30 January 2020 at 06:12:32 UTC, Michael wrote:

When 'dmd rl -L-lreadline' in the command line. I do get the 
following error:

Error: module rl is in file 'rl.d' which cannot be read.

So probably I'm missing something unfortunately I don't know 
what.


Is your source file named rl.d? And are you running dmd in the 
source file's directory?


Re: readline / Gnu readline

2020-01-29 Thread Michael via Digitalmars-d-learn
On Wednesday, 29 January 2020 at 21:15:08 UTC, Adam D. Ruppe 
wrote:

On Wednesday, 29 January 2020 at 20:01:32 UTC, Michael wrote:

I am new to D.
I would like to use the Gnu readline function in D. Is there a 
module that i can use?


just define it yourself

---

// this line right here is all you need to call the function
extern(C) char* readline(const char*);

import core.stdc.stdio;

void main() {
char* a = readline("prompt> ");
printf("%s\n", a);
}

---

# and also link it in at the command line with -L-lreadline
 dmd rl -L-lreadline






readline is so simple you don't need to do anything fancier. If 
you need history and such too you just define those functions 
as well.


Dear Adam,

I did exactly just what you proposed.

When 'dmd rl -L-lreadline' in the command line. I do get the 
following error:

Error: module rl is in file 'rl.d' which cannot be read.

So probably I'm missing something unfortunately I don't know what.


Re: iopipe: Writing output to std.io File

2020-01-29 Thread Jesse Phillips via Digitalmars-d-learn
On Tuesday, 28 January 2020 at 16:09:55 UTC, Steven Schveighoffer 
wrote:


Everything is pulled with iopipe, even output, so it's just a 
matter of who is pulling and when. Pushing is a matter of 
telling the other end to pull.


-Steve


That statement I think will be very helpful to me.

The push would control the buffer, creating that value concept, 
where the buffer is flush which creates a pull, specified in the 
delegate.


Pusher(buffer) <- put(content)

An output range wrapper would provide a push interface which 
would fill in the buffer of the Pusher. When the buffer fills the 
range wrapper would ask to release which Pusher does by calling 
the delegate.


Hopefully I'm following this correctly.






Re: How change window Backgound Color when press a Button when using "ResEdit Resource Editor" to design?

2020-01-29 Thread Mike Parker via Digitalmars-d-learn

On Thursday, 30 January 2020 at 04:31:46 UTC, Marcone wrote:



I am very noob. Can you send me the code?


You've been asking a lot of questions about the Win32 API. This 
is a D programming forum, not a Win32 API forum. I'm sure people 
are generally happy to help point you in the right direction, but 
you can't rely on anyone to send you code for it. Not many people 
are doing Win32 API programming in D (and I would guess a large 
percentage of the community here have never touched it). You 
really need to be following a Win32 API tutorial to learn this 
stuff.


I don't personally know how good any online Win32 tutorials are, 
but I do know that the book "Programming Windows 5th Edition" is 
an excellent resource for learning Win32 programming:


https://amzn.to/37C6htu

It's available in both hardcover and Kindle editions. If you can 
afford to get it, I highly recommend you do.


Several years ago, Andrej Mitrovic translated many of the 
examples from that book to D. Even if you don't buy the book, 
this will be a good resource to help you:


https://github.com/AndrejMitrovic/DWinProgramming



Re: How change window Backgound Color when press a Button when using "ResEdit Resource Editor" to design?

2020-01-29 Thread Marcone via Digitalmars-d-learn

On Thursday, 30 January 2020 at 04:29:42 UTC, bauss wrote:

On Thursday, 30 January 2020 at 03:49:29 UTC, Marcone wrote:
I created a GUI using "ResEdit Resource Editor" and embeded to 
Dlang using this code above. Now I want to change the window 
Backgound Color when press a Button. How can I make it?





You need to handle WM_ERASEBKGND

And then you can set it using CreateSolidBrush and 
SetClassLongPtr with GCLP_HBRBACKGROUND


I am very noob. Can you send me the code?


Re: How change window Backgound Color when press a Button when using "ResEdit Resource Editor" to design?

2020-01-29 Thread bauss via Digitalmars-d-learn

On Thursday, 30 January 2020 at 03:49:29 UTC, Marcone wrote:
I created a GUI using "ResEdit Resource Editor" and embeded to 
Dlang using this code above. Now I want to change the window 
Backgound Color when press a Button. How can I make it?





You need to handle WM_ERASEBKGND

And then you can set it using CreateSolidBrush and 
SetClassLongPtr with GCLP_HBRBACKGROUND


How change window Backgound Color when press a Button when using "ResEdit Resource Editor" to design?

2020-01-29 Thread Marcone via Digitalmars-d-learn
I created a GUI using "ResEdit Resource Editor" and embeded to 
Dlang using this code above. Now I want to change the window 
Backgound Color when press a Button. How can I make it?



import core.sys.windows.windows;
import core.sys.windows.commctrl;
import std.stdio;
pragma(lib, "gdi32.lib");
pragma(lib, "comctl32.lib");

enum IDD_DIALOG1 = 100;
enum BT_1 = 4;

HINSTANCE hInst;

extern(Windows):

BOOL DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM 
lParam) nothrow

{
switch(uMsg)
{
case WM_INITDIALOG:
{
}
return TRUE;

case WM_CLOSE:
{
EndDialog(hwndDlg, 0);
}
return TRUE;

case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case BT_1:
{
try {
// When press button the background need 
change to red for exemple.

}
catch(Exception) {

}
return true;
}
default: {
break;
}
}
}
return TRUE;
default:{
}
}
return FALSE;
}

int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR 
lpCmdLine, int nShowCmd)

{
hInst=hInstance;
InitCommonControls();
return DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), NULL, 
&DlgMain);

}


Re: readline / Gnu readline

2020-01-29 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 29 January 2020 at 22:10:04 UTC, bachmeier wrote:
That's pretty cool. I didn't know anything about this. Taking 
the example from here:


Yeah, readline is a really nice lib, super simple interface. I 
think it is in large part responsible for the GPL's success too 
since it is so useful, so simple, and so correctly licensed :)


And knowing how extern(C) is so easy is good to know too - using 
any C lib from D  can be done similarly and for a lot of libs it 
is actually this simple.


BTW I also have a comparable function in my terminal.d:

http://dpldocs.info/experimental-docs/arsd.terminal.html#get-line

though of course then you gotta download my code file and add it 
to your build (which is easy but still). mine also works on 
windows!


Re: readline / Gnu readline

2020-01-29 Thread bachmeier via Digitalmars-d-learn
On Wednesday, 29 January 2020 at 21:15:08 UTC, Adam D. Ruppe 
wrote:

On Wednesday, 29 January 2020 at 20:01:32 UTC, Michael wrote:

I am new to D.
I would like to use the Gnu readline function in D. Is there a 
module that i can use?


just define it yourself

---

// this line right here is all you need to call the function
extern(C) char* readline(const char*);

import core.stdc.stdio;

void main() {
char* a = readline("prompt> ");
printf("%s\n", a);
}

---

# and also link it in at the command line with -L-lreadline
 dmd rl -L-lreadline



readline is so simple you don't need to do anything fancier. If 
you need history and such too you just define those functions 
as well.


That's pretty cool. I didn't know anything about this. Taking the 
example from here:

https://eli.thegreenplace.net/2016/basics-of-using-the-readline-library/
You can basically run the same code (I modified it to end on 
empty input. This is complete with history:


extern(C) {
char* readline(const char*);
void add_history(const char *string);
}

import core.stdc.stdio;
import core.stdc.string;
import core.stdc.stdlib;

void main() {
  char* buf;
  while ((buf = readline(">> ")) !is null) {
if (strlen(buf) > 0) {
  add_history(buf);
printf("[%s]\n", buf);
free(buf);
} else {
break;
}
  }
}



Re: readline / Gnu readline

2020-01-29 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 29 January 2020 at 20:01:32 UTC, Michael wrote:

I am new to D.
I would like to use the Gnu readline function in D. Is there a 
module that i can use?


just define it yourself

---

// this line right here is all you need to call the function
extern(C) char* readline(const char*);

import core.stdc.stdio;

void main() {
char* a = readline("prompt> ");
printf("%s\n", a);
}

---

# and also link it in at the command line with -L-lreadline
 dmd rl -L-lreadline



readline is so simple you don't need to do anything fancier. If 
you need history and such too you just define those functions as 
well.


Re: Constant GC allocations when sending large messages to threads?

2020-01-29 Thread Steven Schveighoffer via Digitalmars-d-learn

On 1/29/20 2:48 PM, cc wrote:

Given the sample program at https://pastebin.com/u9sSNtj7
I'm experiencing GC allocations with every call to std.concurrency.send 
when sending larger messages (e.g. multiple ulongs).  These do not occur 
when sending uints in comparison, in the provided example.


For example, when the ManyAllocations version is set, I see results like:
allocations: 100  bytes: 3280

When commented out, I see:
allocations: 1  bytes: 80

Is there a way to mitigate this memory usage?

Using DMD32 D Compiler v2.089.1-dirty on Windows 10 x64
cmdline: rdmd.exe -m64



I'm pretty sure std.concurrency uses Variant to pass message data, which 
boxes when it gets over a certain size. You are probably crossing that 
threshold.


The allocations should level out eventually when the GC starts 
collecting them.


-Steve


How to generate ddoc html?

2020-01-29 Thread Pavel Shkadzko via Digitalmars-d-learn
I've been skimming through https://dlang.org/spec/ddoc.html in 
order to understand how can one use ddoc to generate nice htmls. 
I tend to use markdown to log some daily work or copy down code 
examples. For learning purposes I wanted to try ddoc for this but 
could not find any information on ddoc.html page on how to 
actually generate the html page. I guessed that dmd should have a 
switch to generate docs and was correct: dmd mylogs.dd -D would 
generate mylogs.html.


I decided to generate the actuall ddoc.html by simply copying its 
contents into a separate file and calling dmd -D on it but the 
generated ddoc.thml file contained only the title and nothing 
else. I was then told on IRC that ddoc.dd lacks files with marco 
definitions. But where are these files? I suspect these are the 
many .ddoc files in https://github.com/dlang/dlang.org root dir:


https://github.com/tastyminerals/dlang.org/blob/master/macros.ddoc
https://github.com/dlang/dlang.org/blob/master/doc.ddoc
https://github.com/tastyminerals/dlang.org/blob/master/errorpage.ddoc

etc.

But how do I link them together then? Do I need to have some 
specific dir structure? I might be wrong but I couldn't find this 
information on ddoc.thml. Maybe the documentation page needs some 
improvement? I could add this information if only I knew how to 
do it in the first place :)


Re: readline / Gnu readline

2020-01-29 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Wednesday, 29 January 2020 at 20:01:32 UTC, Michael wrote:

I am new to D.
I would like to use the Gnu readline function in D. Is there a 
module that i can use?


Found this. But code.dlang.org is having some issues right now. 
Try accessing it after some time.


https://code.dlang.org/packages/readline


readline / Gnu readline

2020-01-29 Thread Michael via Digitalmars-d-learn

I am new to D.
I would like to use the Gnu readline function in D. Is there a 
module that i can use?


Constant GC allocations when sending large messages to threads?

2020-01-29 Thread cc via Digitalmars-d-learn

Given the sample program at https://pastebin.com/u9sSNtj7
I'm experiencing GC allocations with every call to 
std.concurrency.send when sending larger messages (e.g. multiple 
ulongs).  These do not occur when sending uints in comparison, in 
the provided example.


For example, when the ManyAllocations version is set, I see 
results like:

allocations: 100  bytes: 3280

When commented out, I see:
allocations: 1  bytes: 80

Is there a way to mitigate this memory usage?

Using DMD32 D Compiler v2.089.1-dirty on Windows 10 x64
cmdline: rdmd.exe -m64



Re: How to convert "string" to const(wchar)* ?

2020-01-29 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, January 29, 2020 12:16:29 AM MST Ferhat Kurtulmuş via 
Digitalmars-d-learn wrote:
> On Wednesday, 29 January 2020 at 06:53:15 UTC, Jonathan M Davis
>
> wrote:
> > On Tuesday, January 28, 2020 10:17:03 PM MST Marcone via
> >
> > Digitalmars-d-learn wrote:
> >> [...]
> >
> > Of course it is. string is immutable(char)[], and the
> > characters are in UTF-8. immutable(wchar)[] would would be
> > UTF-16. Even casting between those two types would result in
> > nonsense, because UTF-8 and UTF-16 are different encodings.
> > Casting between array or pointer types basically causes one
> > type to be interpreted as the other. It doesn't convert the
> > underlying data in any fashion. Also, strings aren't
> > null-terminated in D, so having a pointer to a random string
> > could result in a buffer overflow when you try to iterate
> > through the string via pointer as is typical in C code. D code
> > just uses the length property of the string.
> >
> > [...]
>
> + Just a reminder that string literals are null-terminated.

Yes, but unless you're using them directly, it doesn't really matter. Their
null character is one past their end and thus is not actually part of the
string itself as far as the type system is concerned. So, something as
simple as str ~ "foo" would mean that you weren't dealing with a
null-terminated string. You can do something like

printf("answer: %d\n", 42);

but if you mutate the string at all or create a new string from it, then
you're not dealing with a string with a null-terminator one past its end
anymore. Certainly, converting a string to wstring is not going to result in
the wstring being null-terminated without a null terminator being explicitly
appended to it.

Ultimately, that null-terminator one past the end of string literals is
pretty much just useful for being able to pass string literals directly to C
functions without having to explicitly put a null terminator on their end.

- Jonathan M Davis






Re: books for learning D

2020-01-29 Thread Jan Hönig via Digitalmars-d-learn

On Monday, 13 January 2020 at 16:37:31 UTC, Ron Tarrant wrote:

On Monday, 13 January 2020 at 10:28:48 UTC, mark wrote:

I'm just starting out learning D.

Andrei Alexandrescu's "The D Programming Language" is 10 years 
old, so is it still worth getting? (I don't know how much D 
has changed in 10 years.)


Actually, Andrei's book has been updated a few times over the 
years since first being published. The latest version says this 
on the copyright page:


D version: 2.081.1
Book revision: 2018-10-17

So, it's really only about 14 months old.


I am also curious. Where can i find the revised book.


Re: books for learning D

2020-01-29 Thread rumbu via Digitalmars-d-learn

On Wednesday, 29 January 2020 at 08:40:48 UTC, p.shkadzko wrote:
Has anyone read "d programming language tutorial: A Step By 
Step Appoach: Learn d programming language Fast"?


https://www.goodreads.com/book/show/38328553-d-programming-language-tutorial?from_search=true&qid=G9QIeXioOJ&rank=3


Beware, this is a scam.
This guy has hundreds of "books". These books are promoted on 
various forums for download. Of course, you must enter your CC to 
"prove your identity".


Re: books for learning D

2020-01-29 Thread p.shkadzko via Digitalmars-d-learn
Has anyone read "d programming language tutorial: A Step By Step 
Appoach: Learn d programming language Fast"?


https://www.goodreads.com/book/show/38328553-d-programming-language-tutorial?from_search=true&qid=G9QIeXioOJ&rank=3


Re: Looking for a Simple Doubly Linked List Implementation

2020-01-29 Thread Barry allen via Digitalmars-d-learn

On Tuesday, 28 January 2020 at 20:20:25 UTC, Barry allen wrote:

your linked list seems very complex https://get-shareit.com

https://get-vidmateapk.com
/* Node of a doubly linked list */
struct Node {
int data;
struct Node* next; // Pointer to next node in DLL
struct Node* prev; // Pointer to previous node in DLL
};