FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

September 30th -- Classes!

 
Post new topic   Reply to topic     Forum Index -> MiniD
View previous topic :: View next topic  
Author Message
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Sat Sep 30, 2006 11:07 pm    Post subject: September 30th -- Classes! Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> MiniD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group