Yate
ScriptRun Class Reference

Script runtime execution. More...

#include <yatescript.h>

Inheritance diagram for ScriptRun:
GenObject ScriptMutex Mutex Lockable

Public Types

enum  Status {
  Invalid , Running , Incomplete , Succeeded ,
  Failed
}
 

Public Member Functions

 ScriptRun (ScriptCode *code, ScriptContext *context=0)
 
virtual ~ScriptRun ()
 
ScriptCodecode () const
 
ScriptContextcontext () const
 
Status state () const
 
const char * textState () const
 
ObjListstack ()
 
const ObjListstack () const
 
ScriptRunclone () const
 
virtual Status reset (bool init=false)
 
virtual Status execute ()
 
virtual Status run (bool init=true)
 
virtual bool pause ()
 
virtual Status call (const String &name, ObjList &args, ExpOperation *thisObj=0, ExpOperation *scopeObj=0)
 
virtual bool callable (const String &name)
 
virtual bool insertAsync (ScriptAsync *oper)
 
virtual bool appendAsync (ScriptAsync *oper)
 
virtual unsigned int currentLineNo () const
 
virtual const StringcurrentFileName (bool wholePath=false) const
 
virtual const StringtraceId () const
 
virtual void setTraceId (const String &tid)
 
bool runAssign (const ExpOperation &oper, GenObject *context=0)
 
void objCreated (GenObject *obj)
 
void objDeleted (GenObject *obj)
 
- Public Member Functions inherited from GenObject
 GenObject ()
 
virtual ~GenObject ()
 
virtual bool alive () const
 
virtual void destruct ()
 
virtual const StringtoString () const
 
virtual void * getObject (const String &name) const
 
NamedCountergetObjCounter () const
 
NamedCountersetObjCounter (NamedCounter *counter)
 
- Public Member Functions inherited from ScriptMutex
 ScriptMutex (bool recursive, const char *name)
 
bool objTrack () const
 
- Public Member Functions inherited from Mutex
 Mutex (bool recursive=false, const char *name=0)
 
 Mutex (const Mutex &original)
 
 ~Mutex ()
 
Mutexoperator= (const Mutex &original)
 
virtual bool lock (long maxwait=-1)
 
virtual bool unlock ()
 
virtual bool locked () const
 
const char * owner () const
 
bool recursive () const
 
- Public Member Functions inherited from Lockable
virtual ~Lockable ()
 
virtual bool check (long maxwait=-1)
 
virtual bool unlockAll ()
 

Static Public Member Functions

static const char * textState (Status state)
 
- Static Public Member Functions inherited from GenObject
static void * getObject (const String &name, const GenObject *obj)
 
static bool getObjCounting ()
 
static void setObjCounting (bool enable)
 
static NamedCountergetObjCounter (const String &name, bool create=true)
 
static ObjListgetObjCounters ()
 
- Static Public Member Functions inherited from Mutex
static int count ()
 
static int locks ()
 
static bool efficientTimedLock ()
 
- Static Public Member Functions inherited from Lockable
static void wait (unsigned long maxwait)
 
static unsigned long wait ()
 
static void startUsingNow ()
 
static void enableSafety (bool safe=true)
 
static bool safety ()
 

Protected Member Functions

virtual Status resume ()
 

Friends

class ScriptCode
 

Additional Inherited Members

- Protected Attributes inherited from ScriptMutex
bool m_objTrack
 

Detailed Description

Script runtime execution.

An instance of script code and data, status machine run by a single thread at a time

Member Enumeration Documentation

◆ Status

enum Status

Runtime states

Constructor & Destructor Documentation

◆ ScriptRun()

ScriptRun ( ScriptCode * code,
ScriptContext * context = 0 )

Constructor

Parameters
codeCode fragment to execute
contextScript context, an empty one will be allocated if NULL

References code(), and context().

Referenced by clone().

◆ ~ScriptRun()

virtual ~ScriptRun ( )
virtual

Destructor, disposes the code and context

Member Function Documentation

◆ appendAsync()

virtual bool appendAsync ( ScriptAsync * oper)
virtual

Append an asynchronous operation to be executed

Parameters
operOperation to be appended, will be owned by the runtime instance
Returns
True if the operation was added

◆ call()

virtual Status call ( const String & name,
ObjList & args,
ExpOperation * thisObj = 0,
ExpOperation * scopeObj = 0 )
virtual

Call a script function or method

Parameters
nameName of the function to call
argsValues to pass as actual function arguments
thisObjObject to pass as "this" if applicable
scopeObjOptional object to be used for scope resolution inside the call
Returns
Final status of the runtime after function call

◆ callable()

virtual bool callable ( const String & name)
virtual

Check if a script has a certain function or method

Parameters
nameName of the function to check
Returns
True if function exists in code

◆ clone()

ScriptRun * clone ( ) const
inline

Create a duplicate of the runtime with its own stack and state

Returns
New clone of the runtime

References code(), context(), and ScriptRun().

◆ code()

ScriptCode * code ( ) const
inline

Retrieve the parsed code being executed

Returns
Pointer to ScriptCode object

Referenced by clone(), and ScriptRun().

◆ context()

ScriptContext * context ( ) const
inline

Retrieve the execution context associated with the runtime

Returns
Pointer to ScriptContext object

Referenced by clone(), runAssign(), and ScriptRun().

◆ currentFileName()

virtual const String & currentFileName ( bool wholePath = false) const
inlinevirtual

Retrieve the name of the source file from which code is being executed

Parameters
wholePathRetrieve name including path
Returns
The file name

References String::empty().

◆ currentLineNo()

virtual unsigned int currentLineNo ( ) const
inlinevirtual

Retrieve current file line being executed

Returns
The file line being evaluated

◆ execute()

virtual Status execute ( )
virtual

Execute script from where it was left, may stop and return Incomplete state

Returns
Status of the runtime after code execution

◆ insertAsync()

virtual bool insertAsync ( ScriptAsync * oper)
virtual

Insert an asynchronous operation to be executed

Parameters
operOperation to be inserted, will be owned by the runtime instance
Returns
True if the operation was added

◆ objCreated()

void objCreated ( GenObject * obj)
inlinevirtual

Notification that an object was created in context serialized by this mutex

Parameters
objCreated object

Implements ScriptMutex.

References GenObject::GenObject().

◆ objDeleted()

void objDeleted ( GenObject * obj)
inlinevirtual

Notification that an object was destroyed in context serialized by this mutex

Parameters
objDestroyed object

Implements ScriptMutex.

References GenObject::GenObject().

◆ pause()

virtual bool pause ( )
virtual

Pause the script, make it return Incomplete state

Returns
True if pausing the script succeeded or was already paused

◆ reset()

virtual Status reset ( bool init = false)
virtual

Resets code execution to the beginning, does not clear context

Parameters
initInitialize context
Returns
Status of the runtime after reset

◆ resume()

virtual Status resume ( )
protectedvirtual

Resume script from where it was left, may stop and return Incomplete state

Returns
Status of the runtime after code execution

◆ run()

virtual Status run ( bool init = true)
virtual

Execute script from the beginning until it returns a final state

Parameters
initInitialize context
Returns
Final status of the runtime after code execution

◆ runAssign()

bool runAssign ( const ExpOperation & oper,
GenObject * context = 0 )

Try to assign a value to a single field in the script context

Parameters
operField to assign to, contains the field name and new value
contextPointer to arbitrary object to be passed to called methods
Returns
True if assignment succeeded

References context(), and GenObject::GenObject().

◆ setTraceId()

virtual void setTraceId ( const String & tid)
inlinevirtual

Set an associated trace ID for this instance

Parameters
tidTrace ID to associate

◆ stack() [1/2]

ObjList & stack ( )
inline

Access the runtime execution stack

Returns
The internal execution stack

◆ stack() [2/2]

const ObjList & stack ( ) const
inline

Const access the runtime execution stack

Returns
The internal execution stack

◆ state()

Status state ( ) const
inline

Current state of the runtime

Referenced by textState().

◆ textState() [1/2]

const char * textState ( ) const
inline

Get the text description of the current runtime state

Returns
Description of the runtime state

References textState().

◆ textState() [2/2]

static const char * textState ( Status state)
static

Get the text description of a runtime state

Parameters
stateState to describe
Returns
Description of the runtime state

References state().

Referenced by textState().

◆ traceId()

virtual const String & traceId ( ) const
inlinevirtual

Get the trace ID associated with this instance

Returns
The trace ID

Reimplemented from GenObject.


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