Re: Delegates and classes for custom code.

2018-04-18 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 18 April 2018 at 01:12:33 UTC, Chris Katko wrote: My only questions are: [snip] How's about this one: import std.stdio : writefln; struct data_to_access_t { int tacos; } class Abc(T, alias Fn) { T data; this(T data) { this.data = data; } void

Re: Delegates and classes for custom code.

2018-04-17 Thread arturg via Digitalmars-d-learn
On Wednesday, 18 April 2018 at 01:58:40 UTC, arturg wrote: is it this what you want? class A { int a; void delegate() onDraw; this(void delegate() dg) { onDraw = dg; } void drawText(string s) { s.writeln; }

Re: Delegates and classes for custom code.

2018-04-17 Thread arturg via Digitalmars-d-learn
On Wednesday, 18 April 2018 at 01:12:33 UTC, Chris Katko wrote: That was all pseudo-code typed by hand. I got my code to work today. I don't know if it's the prettiest it can be, but it works: // TESTING ACCESS TO the OWNING function //--- class

Re: Delegates and classes for custom code.

2018-04-17 Thread Chris Katko via Digitalmars-d-learn
That was all pseudo-code typed by hand. I got my code to work today. I don't know if it's the prettiest it can be, but it works: // TESTING ACCESS TO the OWNING function //--- class test_window { float x; float y;

Re: Delegates and classes for custom code.

2018-04-17 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 17 April 2018 at 03:55:55 UTC, Chris Katko wrote: What I want: class viewport_t { int x,y,w,h; } class dialog_t { int x,y; this( int x, int y, delegate void (viewport_t) on_draw ) { this.x = x; this.y = y; this.execute = execute; } void

Re: Delegates and classes for custom code.

2018-04-17 Thread bauss via Digitalmars-d-learn
On Tuesday, 17 April 2018 at 03:55:55 UTC, Chris Katko wrote: What I want: class viewport_t { int x,y,w,h; } class dialog_t { int x,y; this( int x, int y, delegate void (viewport_t) on_draw ) { this.x = x; this.y = y; this.execute = execute; } void

Re: Delegates and classes for custom code.

2018-04-16 Thread Nathan S. via Digitalmars-d-learn
On Tuesday, 17 April 2018 at 04:09:57 UTC, Chris Katko wrote: I'm having trouble conceptualizing this issue at the moment. But it seems if I pass to the delegate my object, then I can ONLY use one class type. Can you post the code you're trying to run?

Re: Delegates and classes for custom code.

2018-04-16 Thread Chris Katko via Digitalmars-d-learn
I'm having trouble conceptualizing this issue at the moment. But it seems if I pass to the delegate my object, then I can ONLY use one class type. Say, the delegate takes a "this" from... some class that wants to have a dialog. A window. Now the delegate NEEDS a this from a window, and only

Re: Delegates and classes for custom code.

2018-04-16 Thread Chris Katko via Digitalmars-d-learn
Some typos in there. execute == on_draw. Basically, I'm just sending a delegate/lambda "custom function" at initialization time. But I'd like that delegate to somehow access the holding classes functions. Or figure out how to do that. Maybe the class somehow sends the delegate a this

Delegates and classes for custom code.

2018-04-16 Thread Chris Katko via Digitalmars-d-learn
What I want: class viewport_t { int x,y,w,h; } class dialog_t { int x,y; this( int x, int y, delegate void (viewport_t) on_draw ) { this.x = x; this.y = y; this.execute = execute; } void draw_text(string text) { } delegate void (viewport_t)