Dispatching from receive to a function
Johannes Pfau
spam at example.com
Mon Sep 27 06:21:16 PDT 2010
On 27.09.2010 15:07, Bob Cowdery wrote:
>
> Failing that I think a dispatcher structure using an associative array
> would be my next choice. However I'm getting stuck on how to define and
> use an array which maps a string key to a delegate. Can someone help me
> out there please. I will then effectively have my 'Atom' as a string in
> the message and dispatch on that.
>
Not sure about the other questions, but here's an example for a
string/delegate associative array:
-------------------------------------------
import std.stdio;
alias bool delegate(int, char) TestDelegate;
TestDelegate[string] dict;
class C
{
bool test(int i, char c) {return true;}
}
void main()
{
C c = new C();
dict["test"] = &c.test;
writeln(dict["test"](0, 'c'));
}
-----------------------------------------------
--
Johannes Pfau
More information about the Digitalmars-d-learn
mailing list