Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "VIATRA2/Live Transformations/HelloWorld"

(New page: The following "hello world" trigger shows another important property of the live transformation engine, the handling of the ASMfunctions. These can be considered as global variables, the v...)
 
Line 1: Line 1:
The following "hello world" trigger shows another important property of the live transformation engine, the handling of the ASMfunctions. These can be considered as global variables, the values stored in them are preserved throughout the triggers lifecycle. If we start this trigger, then the action sequence will be executed after each entity creation in the model space.
+
The following "hello world" trigger is actually the simplest trigger one can write. If we start this trigger, then the action sequence will be executed after each entity creation in the model space.
  
 
<source lang="java">
 
<source lang="java">
 
machine HelloTriggerWorld
 
machine HelloTriggerWorld
 
{
 
{
  // Beware, this is a global variable, which _holds_ it's value throughout the triggers lifecycle.
 
  asmfunction testFruit / 1
 
  {
 
    ("fruit") = "apple"; // Startup value of the variable
 
  }
 
 
 
   @Trigger(priority='100', mode='always', sensitivity='rise', startup='passive', execution='iterate')
 
   @Trigger(priority='100', mode='always', sensitivity='rise', startup='passive', execution='iterate')
 
   gtrule testTrigger(inout E) =
 
   gtrule testTrigger(inout E) =
Line 23: Line 17:
 
     {
 
     {
 
       println( "Trigger Action triggered by: " + E );
 
       println( "Trigger Action triggered by: " + E );
      println( "Trigger AsmTest: " + testFruit("fruit") );
 
      update testFruit("fruit") = "orange";
 
 
     }
 
     }
 
   }  
 
   }  
Line 32: Line 24:
 
     seq
 
     seq
 
     {
 
     {
      println ( "VTCL AsmTest: " + testFruit("fruit") );
 
 
       println ( startTrigger("testTrigger") );
 
       println ( startTrigger("testTrigger") );
 
     }
 
     }
 
}
 
}
 
</source>
 
</source>

Revision as of 11:08, 2 July 2008

The following "hello world" trigger is actually the simplest trigger one can write. If we start this trigger, then the action sequence will be executed after each entity creation in the model space.

machine HelloTriggerWorld
{
  @Trigger(priority='100', mode='always', sensitivity='rise', startup='passive', execution='iterate')
  gtrule testTrigger(inout E) =
  {
    // This pattern triggers the action sequence.
    precondition pattern lhs(E)=
    {
      entity(E);
    }
 
    // The action sequence.
    action
    {
      println( "Trigger Action triggered by: " + E );
    }
  } 
 
  //Main rule, the startTrigger() method invokes the engine.
  rule main() =
    seq
    {
      println ( startTrigger("testTrigger") );
    }
}

Back to the top