PixelLightAPI  .
Public Member Functions | Protected Member Functions
PLCore::Script Class Reference

Abstract script base class. More...

#include <Script.h>

Inheritance diagram for PLCore::Script:
Inheritance graph
[legend]

List of all members.

Public Member Functions

virtual PLCORE_API ~Script ()
 Destructor.
PLCORE_API String GetScriptLanguage () const
 Returns the name of the script language the script is using.
PLCORE_API void GetFormats (Array< String > &lstFormats) const
 Returns a list of file formats this script supports.
PLCORE_API void AddBinding (Object &cObject, const String &sNamespace="")
 Adds a script binding to connect the given RTTI class instance with this script.
PLCORE_API void AddBindings ()
 Add all script bindings to this script.
virtual bool IsGlobalFunction (const String &sName, const String &sNamespace="")=0
 Returns whether or not the given name belongs to a global function.
virtual bool AddGlobalFunction (const String &sFunction, const DynFunc &cDynFunc, const String &sNamespace="")=0
 Adds a global function to the script.
virtual bool RemoveAllGlobalFunctions ()=0
 Removes all global functions from the script.
virtual String GetSourceCode () const =0
 Returns the script source code.
virtual bool SetSourceCode (const String &sSourceCode)=0
 Sets the script source code.
virtual void GetAssociatedFilenames (Array< String > &lstFilenames)=0
 Returns a list of filenames associated with this script.
virtual bool Execute (const String &sSourceCode)=0
 Executes a given script source code string.
virtual void GetGlobalVariables (Array< String > &lstGlobalVariables, const String &sNamespace="")=0
 Adds the names of found global variables to a given list.
virtual bool IsGlobalVariable (const String &sName, const String &sNamespace="")=0
 Returns whether or not the given name belongs to a global variable.
virtual ETypeID GetGlobalVariableTypeID (const String &sName, const String &sNamespace="")=0
 Returns the type ID a global variable.
virtual String GetGlobalVariable (const String &sName, const String &sNamespace="")=0
 Returns the current value of a global variable.
virtual void SetGlobalVariable (const String &sName, const DynVar &cValue, const String &sNamespace="")=0
 Sets the current value of a global variable.
virtual bool BeginCall (const String &sFunctionName, const String &sFunctionSignature, const String &sNamespace="")=0
 Starts a function call.
virtual void PushArgument (bool bValue)=0
 Pushes an argument required for the current function call.
virtual void PushArgument (float fValue)=0
virtual void PushArgument (double fValue)=0
virtual void PushArgument (int8 nValue)=0
virtual void PushArgument (int16 nValue)=0
virtual void PushArgument (int32 nValue)=0
virtual void PushArgument (int64 nValue)=0
virtual void PushArgument (uint8 nValue)=0
virtual void PushArgument (uint16 nValue)=0
virtual void PushArgument (uint32 nValue)=0
virtual void PushArgument (uint64 nValue)=0
virtual void PushArgument (const String &sString)=0
virtual void PushArgument (Object *pObject)=0
virtual void PushArgument (Object &cObject)=0
virtual bool EndCall ()=0
 Ends a function call.
virtual bool GetReturn (bool nValue)=0
 Returns the result of a function call.
virtual float GetReturn (float nValue)=0
virtual double GetReturn (double nValue)=0
virtual int8 GetReturn (int8 nValue)=0
virtual int16 GetReturn (int16 nValue)=0
virtual int32 GetReturn (int32 nValue)=0
virtual int64 GetReturn (int64 nValue)=0
virtual uint8 GetReturn (uint8 nValue)=0
virtual uint16 GetReturn (uint16 nValue)=0
virtual uint32 GetReturn (uint32 nValue)=0
virtual uint64 GetReturn (uint64 nValue)=0
virtual String GetReturn (String nValue)=0
virtual ObjectGetReturn (Object *nValue)=0
virtual ObjectGetReturn (Object &nValue)=0

Protected Member Functions

PLCORE_API Script ()
 Constructor.
PLCORE_API bool LogOutput (uint8 nLogLevel, const String &sText)
 Write a string into the log.

Detailed Description

Abstract script base class.

Remarks:
Each script should have the following properties:
  • "Language": Script language (for example: "JavaScript" or "Lua")
  • "Formats": File format extensions this script can load in (for example: "js" or "lua")

Supported script features:

Supported primitive data types: bool, float, double, int8, int16, int32, int64, uint8, uint16, uint32, uint64, PLCore::Object*, PLCore::Object& Please note that not each script language/API may make such a detailed data type distinction. Because strings are fundamental within scripts, String is supported as well.


Constructor & Destructor Documentation

virtual PLCORE_API PLCore::Script::~Script ( ) [virtual]

Destructor.

PLCORE_API PLCore::Script::Script ( ) [protected]

Member Function Documentation

Returns the name of the script language the script is using.

Returns:
The name of the script language the script is using (for example "Lua" or "JavaScript")
PLCORE_API void PLCore::Script::GetFormats ( Array< String > &  lstFormats) const

Returns a list of file formats this script supports.

Parameters:
[out]lstFormatsList of file formats this script supports (the given list is not cleared before new entries are added)
PLCORE_API void PLCore::Script::AddBinding ( Object cObject,
const String sNamespace = "" 
)

Adds a script binding to connect the given RTTI class instance with this script.

Parameters:
[in]cObjectRTTI class instance, must stay valid as long as this script lives
[in]sNamespaceOptional namespace (e.g. "MyNamespace", "MyNamespace.MyOtherNamespace" and so on)
Note:
  • The added RTTI class instance methods will be available to the script as simple global functions
PLCORE_API void PLCore::Script::AddBindings ( )

Add all script bindings to this script.

Remarks:
Iterates over all available script binding instances and adds them to this script.
Note:
  • The added RTTI class instance methods will be available to the script as simple global functions
virtual bool PLCore::Script::IsGlobalFunction ( const String sName,
const String sNamespace = "" 
) [pure virtual]

Returns whether or not the given name belongs to a global function.

Parameters:
[in]sNameName of the global function
[in]sNamespaceOptional namespace (e.g. "MyNamespace", "MyNamespace.MyOtherNamespace" and so on)
Returns:
'true' if the given name belongs to a global function, else 'false'
Remarks:
When calling a global script function, the script backend usually writes an error into the log when the given global script function wasn't found. So, when using optional global script functions, it's a good idea to check whether there's such a global script function by using "IsGlobalFunction()".
virtual bool PLCore::Script::AddGlobalFunction ( const String sFunction,
const DynFunc cDynFunc,
const String sNamespace = "" 
) [pure virtual]

Adds a global function to the script.

Parameters:
[in]sFunctionFunction name used inside the script to call the global function
[in]cDynFuncDynamic function
[in]sNamespaceOptional namespace (e.g. "MyNamespace", "MyNamespace.MyOtherNamespace" and so on)
Returns:
'true' if all went fine, else 'false' (maybe a script is already set?)
Note:
  • If there's already a set script ("SetSourceCode()") this method will return an error
virtual bool PLCore::Script::RemoveAllGlobalFunctions ( ) [pure virtual]

Removes all global functions from the script.

Returns:
'true' if all went fine, else 'false' (maybe a script is already set?)
Note:
  • If there's already a set script ("SetSourceCode()") this method will return an error
virtual String PLCore::Script::GetSourceCode ( ) const [pure virtual]

Returns the script source code.

Returns:
The script source code
virtual bool PLCore::Script::SetSourceCode ( const String sSourceCode) [pure virtual]

Sets the script source code.

Parameters:
[in]sSourceCodeScript source code, usually blank ASCII code, empty string to set to script at all
Returns:
'true' if all went fine, else 'false'
virtual void PLCore::Script::GetAssociatedFilenames ( Array< String > &  lstFilenames) [pure virtual]

Returns a list of filenames associated with this script.

Parameters:
[out]lstFilenamesReceives a list of filenames associated with this script (list is not cleared before adding new entries)
Remarks:
For example Lua allows to use the keyword "require" to add the content of another script. This method returns a list of the filenames of the files which are included within this script. One can use this information to e.g. reload the script when the one of the associated files was changed, beside reloading when just the original script file was changed.
virtual bool PLCore::Script::Execute ( const String sSourceCode) [pure virtual]

Executes a given script source code string.

Parameters:
[in]sSourceCodeScript source code to execute, usually blank ASCII code
Returns:
'true' if all went fine, else 'false'
Note:
  • Only works if there's already a valid script currently used
  • Lua example statement: "Speed=42"
virtual void PLCore::Script::GetGlobalVariables ( Array< String > &  lstGlobalVariables,
const String sNamespace = "" 
) [pure virtual]

Adds the names of found global variables to a given list.

Parameters:
[out]lstGlobalVariablesList to be filled with the names (without namespace) of the found global variables, the given list is not cleared before new entries are added
[in]sNamespaceOptional namespace (e.g. "MyNamespace", "MyNamespace.MyOtherNamespace" and so on)
virtual bool PLCore::Script::IsGlobalVariable ( const String sName,
const String sNamespace = "" 
) [pure virtual]

Returns whether or not the given name belongs to a global variable.

Parameters:
[in]sNameName of the global variable
[in]sNamespaceOptional namespace (e.g. "MyNamespace", "MyNamespace.MyOtherNamespace" and so on)
Returns:
'true' if the given name belongs to a global variable, else 'false'
virtual ETypeID PLCore::Script::GetGlobalVariableTypeID ( const String sName,
const String sNamespace = "" 
) [pure virtual]

Returns the type ID a global variable.

Parameters:
[in]sNameName of the global variable
[in]sNamespaceOptional namespace (e.g. "MyNamespace", "MyNamespace.MyOtherNamespace" and so on)
Returns:
The type ID of the global variable (e.g. "PLCore::TypeFloat" for "float") or "PLCore::TypeInvalid" on error
virtual String PLCore::Script::GetGlobalVariable ( const String sName,
const String sNamespace = "" 
) [pure virtual]

Returns the current value of a global variable.

Parameters:
[in]sNameName of the global variable
[in]sNamespaceOptional namespace (e.g. "MyNamespace", "MyNamespace.MyOtherNamespace" and so on)
Returns:
The current value of the global variable
virtual void PLCore::Script::SetGlobalVariable ( const String sName,
const DynVar cValue,
const String sNamespace = "" 
) [pure virtual]

Sets the current value of a global variable.

Parameters:
[in]sNameName of the global variable
[in]cValueNew value of the global variable
[in]sNamespaceOptional namespace (e.g. "MyNamespace", "MyNamespace.MyOtherNamespace" and so on)
Note:
  • If there's no global variable with the given name, a new global variable is added to the script
  • Please note that it depends on the used script language/API which data types are really available, this means that "GetGlobalVariableTypeID()" may return another data type as the one you specified
virtual bool PLCore::Script::BeginCall ( const String sFunctionName,
const String sFunctionSignature,
const String sNamespace = "" 
) [pure virtual]

Starts a function call.

Parameters:
[in]sFunctionNameName of the function to call
[in]sFunctionSignatureSignature of the function to call (e.g. "void(int,float)")
[in]sNamespaceOptional namespace (e.g. "MyNamespace", "MyNamespace.MyOtherNamespace" and so on)
Returns:
'true' if all went fine, else 'false'
Note:
  • It's not recommended to use this method directly, use "FuncScriptPtr" instead
See also:
  • Have a look at "IsGlobalFunction()" for additional information
virtual void PLCore::Script::PushArgument ( bool  bValue) [pure virtual]

Pushes an argument required for the current function call.

Parameters:
[in]nValueArgument value
Note:
  • It's not recommended to use this method directly, use "FuncScriptPtr" instead
virtual void PLCore::Script::PushArgument ( float  fValue) [pure virtual]
virtual void PLCore::Script::PushArgument ( double  fValue) [pure virtual]
virtual void PLCore::Script::PushArgument ( int8  nValue) [pure virtual]
virtual void PLCore::Script::PushArgument ( int16  nValue) [pure virtual]
virtual void PLCore::Script::PushArgument ( int32  nValue) [pure virtual]
virtual void PLCore::Script::PushArgument ( int64  nValue) [pure virtual]
virtual void PLCore::Script::PushArgument ( uint8  nValue) [pure virtual]
virtual void PLCore::Script::PushArgument ( uint16  nValue) [pure virtual]
virtual void PLCore::Script::PushArgument ( uint32  nValue) [pure virtual]
virtual void PLCore::Script::PushArgument ( uint64  nValue) [pure virtual]
virtual void PLCore::Script::PushArgument ( const String sString) [pure virtual]
virtual void PLCore::Script::PushArgument ( Object pObject) [pure virtual]
virtual void PLCore::Script::PushArgument ( Object cObject) [pure virtual]
virtual bool PLCore::Script::EndCall ( ) [pure virtual]

Ends a function call.

Returns:
'true' if all went fine, else 'false'
Note:
  • It's not recommended to use this method directly, use "FuncScriptPtr" instead
  • This actually performs the prepared function call
virtual bool PLCore::Script::GetReturn ( bool  nValue) [pure virtual]

Returns the result of a function call.

Parameters:
[in]nValueUnused value... just there so the compiler can figure out the proper method
Returns:
The result of a function call
Note:
  • It's not recommended to use this method directly, use "FuncScriptPtr" instead
virtual float PLCore::Script::GetReturn ( float  nValue) [pure virtual]
virtual double PLCore::Script::GetReturn ( double  nValue) [pure virtual]
virtual int8 PLCore::Script::GetReturn ( int8  nValue) [pure virtual]
virtual int16 PLCore::Script::GetReturn ( int16  nValue) [pure virtual]
virtual int32 PLCore::Script::GetReturn ( int32  nValue) [pure virtual]
virtual int64 PLCore::Script::GetReturn ( int64  nValue) [pure virtual]
virtual uint8 PLCore::Script::GetReturn ( uint8  nValue) [pure virtual]
virtual uint16 PLCore::Script::GetReturn ( uint16  nValue) [pure virtual]
virtual uint32 PLCore::Script::GetReturn ( uint32  nValue) [pure virtual]
virtual uint64 PLCore::Script::GetReturn ( uint64  nValue) [pure virtual]
virtual String PLCore::Script::GetReturn ( String  nValue) [pure virtual]
virtual Object* PLCore::Script::GetReturn ( Object nValue) [pure virtual]
virtual Object& PLCore::Script::GetReturn ( Object nValue) [pure virtual]
PLCORE_API bool PLCore::Script::LogOutput ( uint8  nLogLevel,
const String sText 
) [protected]

Write a string into the log.

Parameters:
[in]nLogLevelLog level
[in]sTextText which should be written into the log
Returns:
'true' if all went fine, else 'false'
Remarks:
The text is written to the log only if the current log level is greater or equal to the specified value. This method is an extension of "Log::Output()" which also adds the name of the script to the given text.

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


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:09:27
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported