Andrew Borley wrote:
[snip]
In other news, I have just added in support for properties to the Python
extension:
- A composite with a property defined in a component and the associated
.componentType file:
   <component name="DivideComponent">
       <implementation.python module="DivideImpl" scope="composite"/>
       <property name="doRounding">true</property>
    </component>

<componentType
...
   <property name="doRounding" type="xsd:boolean"/>
</componentType>

Is automatically instantiated and assigned the property value in the python
implementation module:

def divide(val1, val2):
   result = float(val1) / float(val2)
print "Python - DivideImpl.divide " + str(val1) + " / " + str(val2) + "
= " + str(result)

   # Use the doRounding property
   if doRounding:
       result = round(result)
       print "Python - DivideImpl.divide is rounding the result to " +
str(result)

   return result


Cheers

Andy


Andy, this is nice. What do you think about going just one small step further to make ComponentType definitions optional, and basically define the Python variable automatically when it is configured as a property or a reference on the component definition?

As a scripting developer I am not used to declare my variables ahead of time, they are just created automatically once I assign a value to them. Doing this would be in the same spirit: you get a variable created for you when you configure/assign its value on the component declaration and the scripting developer does not need to write ComponentType files to declare things that he usually doesn't like to declare...

This would just require a small change to ModelLoader.cpp and your PythonImplementation.cpp, for references we would do the following: - ModelLoader would call a new needReferenceType(name) method or a findReferenceType(string name, createNew=true) method on the ComponentType (your PythonImplementation) and in this method you would create the ReferenceType.
- We would follow a similar scheme for properties.

I had started to implement that scheme for Ruby (see RubyImplementation::findReferenceType() in revision r442461 or RubyImplementation.cpp) then backed it out as in Ruby you usually declare your public attributes/properties. But I think that this would apply well to languages like Python and Javascript.

Let me know what you think.

--
Jean-Sebastien


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to