Sheep
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
Public Member Functions | List of all members
Sheep::IVirtualMachine Class Referenceabstract

Represents a Sheep Virtual Machine which executes compiled Sheep scripts. More...

#include <sheepcpp.h>

Public Member Functions

virtual void Release ()=0
 
virtual SheepLanguageVersion GetLanguageVersion ()=0
 Gets the language version with which this virtual machine was created.
 
virtual void SetTag (void *tag)=0
 
virtual void * GetTag ()=0
 Gets the tag that was set earlier, or null if no tag has been set.
 
virtual int SetEndWaitCallback (EndWaitCallback callback)=0
 
virtual int SetImportCallback (const char *importName, ImportCallback callback)=0
 
virtual int PrepareScriptForExecution (IScript *script, const char *function, IExecutionContext **context)=0
 

Detailed Description

Represents a Sheep Virtual Machine which executes compiled Sheep scripts.

Member Function Documentation

virtual int Sheep::IVirtualMachine::PrepareScriptForExecution ( IScript script,
const char *  function,
IExecutionContext **  context 
)
pure virtual

Creates a new Sheep::IExecutionContext ready to run the specified function.

You must call this method before calling Execute(). After you call this method you can read and modify variable values before the script is executed. Be sure to call Sheep::IExecutionContext::Release() when you're done with the context.

Parameters
scriptA pointer to the script that should be executed
functionThe name of the function that should be executed
contextA pointer to a pointer to a Sheep::IExecutionContext that will store the new context
Returns
SHEEP_SUCCESS if successful, SHEEP_ERR_INVALID_ARGUMENT if any of the parameters are null, or SHEEP_ERR_NO_SUCH_FUNCTION if the function doesn't exist.
virtual void Sheep::IVirtualMachine::Release ( )
pure virtual

Releases the Virtual Machine, decreasing its reference count by 1.

Once the reference count reaches 0, the Virtual Machine and any IExecutionContexts that belong to it are destroyed. Be very careful when accessing IExecutionContext after the parent IVirtualMachine has been released. If you don't know what you're doing you could easily cause a crash.

virtual int Sheep::IVirtualMachine::SetEndWaitCallback ( EndWaitCallback  callback)
pure virtual

Sets the callback that will be called whenever Sheep encounters the end of a wait section

Generally, what you should do is check to see if there are any import functions still executing that were called within this wait section. If so, suspend the context and wait until everything has finished, then call Execute() to resume.

Parameters
callbackThe callback to call when the end of a wait section is encountered (can be null, though this is not recommended)
Returns
SHEEP_SUCCESS if successful
virtual int Sheep::IVirtualMachine::SetImportCallback ( const char *  importName,
ImportCallback  callback 
)
pure virtual

Sets the callback for an import function.

Sheep will call the specified callback whenever it encounters the given import function.

Parameters
importNameThe name of the import
callbackA pointer to a function handler that will be called when a script calls the import function (can be null, though this is not recommended)
Returns
SHEEP_SUCCESS if successful, SHEEP_ERR_INVALID_ARGUMENT if importName is null
virtual void Sheep::IVirtualMachine::SetTag ( void *  tag)
pure virtual

Sets a "tag," which is just a pointer to whatever you want. The Virtual Machine doesn't use it. It's just for convenience.


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