ScriptStack 1.0.4
Loading...
Searching...
No Matches
ScriptStack.Runtime.Host Interface Reference

The main interface to create a Host. A Host can implement Routine's to extend its functionality. More...

Inheritance diagram for ScriptStack.Runtime.Host:
ScriptStack.Runtime.Model

Public Member Functions

object Invoke (string routine, List< object > parameters)
 Called when a Routine is invoked.

Detailed Description

The main interface to create a Host. A Host can implement Routine's to extend its functionality.

A Host must implement the Invoke() method. As you can see, it is just an empty declaration to hook in.

Every time a Routine is requested from within a script, this method is invoked.

You have to implement the logic (the function body) inside this method!

The name of the Routine is passed as string as 1st parameter. Parameters are passed as a list of objects as 2nd parameter.

A Host class with a registered "print" Routine would look like the following example.

{
private Manager manager;
private Script script;
private Interpreter interpreter;
public ScriptStack(String[] args)
{
manager = new Manager();
manager.Register(new Routine((Type)null, "print", (Type)null));
script = new Script(manager, args[0]);
interpreter = new Interpreter(script);
interpreter.Handler = this;
while (!interpreter.Finished)
interpreter.Interpret(1);
}
public object Invoke(string routine, List<object> parameters)
{
if (routine == "print")
{
// do some stuff..
}
return null;
}
}
API entry point.
Definition Manager.cs:20
void Register(Model model)
Definition Manager.cs:169
The Interpreter finally interprets the parse tree in form of a token stream returned from the ScriptS...
uint Interpret(uint instructions)
A Routine is an abstract representation of a method.
Definition Routine.cs:70
Internal representation of a text file (source code) which can be passed to the Interpreter to execut...
Definition Script.cs:18
The main interface to create a Host. A Host can implement Routine's to extend its functionality.
Definition Host.cs:80
object Invoke(string routine, List< object > parameters)
Called when a Routine is invoked.

You can call Routine's directly by calling the Invoke method on the corresponding handler (Host / Model) passing its name and a list of parameters (if needed)

Routine myRoutine = manager.Routines["print"];
List<object> parameters = new List<object>();
parameters.Add("Hello world");
myRoutine.Handler.Invoke("print", parameters);
ReadOnlyDictionary< String, Routine > Routines
Definition Manager.cs:241

Definition at line 80 of file Host.cs.

Member Function Documentation

◆ Invoke()

object ScriptStack.Runtime.Host.Invoke ( string routine,
List< object > parameters )

Called when a Routine is invoked.

Parameters
routine
parameters
Returns

The documentation for this interface was generated from the following file: