Sunday, June 11, 2006

Message Passing Works!
Ok, so it's not complete yet. But I'm able to register a message handler (think callback function) with an object, and send the object a message what will use the handler. Below is a sample output of the test program.

$ ./test_xxobject
Starting xxobject test...
Sending 'getDescription' message to object...
Message accepted! Object description: xX object prototype.

And now for part of the source code (I need to figure out how to insert C source code properly into HTML)

int main()
{
xxObject *obj1;
const char *desc;

printf("Starting xxobject test...\n");
obj1 = xxObject_New();
printf("Sending 'getDescription' message to object...\n");
desc = (const char*)xxObject_SendMessage(obj1, "getDescription");
if(desc != NULL)
{
printf("Message accepted! Object description: %s\n", desc);
}
else
{
printf("Message rejected! Unsupported by object.\n");
}

return 0;
}

The problem is that so far, I could only insert functions into the object slots (implemented as two lists) because I don't have a way to distiguish which objects in the slots are callable functions and which are not. That's what I get for trying to implement a typeless system. Currently, in a lot of places I shouldn't. That, and I have yet to implement a dictionary object. I need one real bad! What if I add an 'isCallable' flag and a 'payload' void pointer to each of the objects in the slots. Then, I could use the flag to check if the payload is a pointer to a function, and if so, call it. If not, ... return the object? But that would identify an object as belonging to a particular type! I know I need to have some types. I need to think some more.

0 Comments:

Post a Comment

<< Home