The SMOK scripting interface is intended to support
automation of testing and grading of SMOK models,
and has been used to integrate SMOK models with the
Cebollita debuggers.
You can script reading models, running them, and examining their components.
There is little support for model editing - you can't create components or connections, for instance.
SMOK scripting is object based.
SMOK objects correspond to a running SMOK program.
SMOKComponent objects correspond to individual components in the currently loaded model.
You obtain SMOK objects by using a static (non-object) constructor call.
SMOKComponents
are organized hierarchically, in parent-child relationships.
You obtain the root SMOKComponent object from the
SMOK object, and access to other
components by navigating the hierachy using calls to SMOKComponent objects.
A separate library, not part of the SMOK scripting interface per se,
is provided to facilitate finding individual components easily.
SMOK scripting has been implemented using
SWIG. While SWIG supports a
number of scripting languages, SMOK currently exports appropriate wrappers only for
nsPerl, an implementation of the Perl language, and (Sun JRE 1.4) Java.
Here is a very simple perl script that uses SMOK to read a model,
run it, and check the final value of one of its components:
use SMOK; # load the perl module giving access to SMOK
use SMOKUtils; # load additional SMOK-related perl scripts
$smok = SMOK::CreateSMOK("example", 1); # create a SMOK object(title= "example",visible)
$smok->OpenModelFile("smalltest.smok"); # read a model file
$smok->Step(1000); # run it until it halts or 1000 cycles
# now find the component whose value we want to check and print a result message
$interestingComponent = SMOKUtils::FindComponentByName( $smok, "SUM" );
print $smok->GetRootComponent()->GetName(), " has halted with SUM = ",
$interestingComponent->GetValue(), "\n";
Here is a roughly equivalent script in Java:
// load the SMOK module
static {
try {
System.loadLibrary( "SMOKJava.dll" );
} catch (Exception e) {
System.err.println("Fatal error: Couldn't load SMOKJava.dll.");
System.err.println("Make sure you have it, and that your PATH environment variable");
System.err.println("includes the directory it is in.");
System.exit(1);
}
}
...
SMOK smokInstance = SMOKJava.CreateSMOK("example", 1); # create a SMOK object(title= "example",visible)
smokInstance.OpenModelFile("smalltest.smok"); # read a model file
smokInstance.Step(1000); # run it until it halts or 1000 cycles
System.out.println( smokInstance.GetName(), " has halted at cycle " +
smokInstance.GetCycle() );