JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Sat Sep 30, 2006 11:07 pm Post subject: September 30th -- Classes! |
|
|
Hmm, well they're in somewhat. I haven't really nailed down all the semantics yet, but they're functional.
Code: | class EventDispatcher
{
mFunctions = null;
method constructor()
{
this.mFunctions = { };
}
method opCall(type)
{
local functions = this.mFunctions[type];
if(functions !is null)
{
for(local i = 0; i < #functions; ++i)
functions[i](type);
}
}
method add(type, f)
{
local functions = this.mFunctions[type];
if(functions is null)
functions = [f];
else
functions ~= f;
this.mFunctions[type] = functions;
}
}
function fooHandler()
{
writefln("foo event");
}
function fooHandler2()
{
writefln("foo event 2");
}
function barHandler()
{
writefln("bar event");
}
local ed = EventDispatcher();
ed:add("foo", fooHandler);
ed:add("foo", fooHandler2);
ed:add("bar", barHandler);
ed("foo");
ed("bar"); |
Just a simple event dispatch manager thing, which produces:
Code: | foo event
foo event 2
bar event |
Pretty cool. I've still got the "as" keyword (for casting class references) to implement though.
I've also started removing functionality from tables, and started changing functionality with regards to metatables. I'm not sure if I'll let userdata keep its metatables; might as well. |
|