DoclerLabs / hexMachina

Releases, issues, documentation, website of hexMachina, framework written in Haxe
http://hexmachina.org
MIT License
44 stars 8 forks source link

DSL runtime parameters #225

Closed FrancisBourre closed 7 years ago

FrancisBourre commented 7 years ago

Static compilers (Xml and Flow) can use runtime parameters to dynamize compiled code during its execution. Parameters are statically typed and double compile-checked, 1st time during DSL declaration, 2nd time during execution call.

Flow example

DSL declaration:

@context(   name = 'applicationContext',
            params = {x: Float, y: Float, p:hex.structures.Point} )
{
    size = new hex.structures.Size( x, y );
    anotherSize = new hex.structures.Size( p.x, p.y );
}

Code execution:

var code = BasicStaticFlowCompiler.compile( applicationAssembler, "flow/runtimeArguments.flow" );
code.execute( { x:10, y: 20, p: new hex.structures.Point( 30, 40 ) } );

Xml example

DSL declaration:

<root name="applicationContext">

    <params>
        <param id="x" type="Float"/>
        <param id="y" type="Float"/>
        <param id="p" type="hex.structures.Point"/>
    </params>

    <bean id="size" type="hex.structures.Size">
        <argument type="Int" ref="x"/>
        <argument type="Int" ref="y"/>
    </bean>

    <bean id="anotherSize" type="hex.structures.Size">
        <argument type="Int" ref="p.x"/>
        <argument type="Int" ref="p.y"/>
    </bean>

</root>

Code execution:

var code = BasicStaticXmlCompiler.compile( applicationAssembler, "xml/runtimeArguments.xml" );
code.execute( { x:10, y: 20, p: new hex.structures.Point( 30, 40 ) } );