Monday, July 25, 2005

This morning, I implemented in C++ a simple component manager that iterates a directory looking for SIL files, and for each one found, creates an in-memory data structure to represent each component and the classes that the component implements.

The next step will be to iterate the in-memory structures and create JavaScript objects that implement each component and class represented, and register these objects with the JavaScript engine.

In addition, some kind of marshalling code within the layout manager will be needed to dispatch calls made from JavaScript to the components (not to mention, some code to load each DLL at runtime will be required). This is going to take some thought...

Tonight I fleshed out the basics for implementing a simple component manager. What is a component manager? Well, In order for callbacks (like onclick) in JavaScript to be effective, they need to be able to do something more meaningful than dump strings to stderr. To gain more power, they need to interface to external code written in a more powerful language, like C or C++. Components are one way to package code that can be called from JavaScript.

For this project, components and their interfaces are described in a XML file with a sil extension (which stands for Simple Interface Language).

Example:



<component name="simple" id="94981D9E-FC99-11D9-8BDE-F66BAD1E3F3A">
<class name="HelloClass">
<function name="Hello">
<arg name="MyName" type="string"/>
<return type="number"/>
</function>
<property name="age" type="number"/>
</class>
<class name="HelloClass2">
<function name="Hello">
<arg name="MyName" type="string"/>
<return type="number"/>
</function>
<property name="age" type="number"/>
</class>
</component>


Allowed argument and return types are string, number, and bool, corresponding to the basic types supported by JavaScript. Properties are defined with a property tag. The also have a name and type.

Each component is implemented as a single DLL/shared lib that implements the above classes, and methods to create and destroy objects belonging to the classes implemented by the component.