Scripting Engine interface.
struct IScriptSystem { };
IScriptSystem.h
This interface is mapped 1:1 on a script state. All scripts loaded from the same interface instance are visible with each others.
virtual ~IScriptSystem();
virtual HBREAKPOINT AddBreakPoint(const char * sFile, int nLineNumber) = 0;
virtual HSCRIPTFUNCTION AddFuncRef(HSCRIPTFUNCTION f) = 0;
Adds new reference to function referenced by HSCRIPTFUNCTION.
Allocate or deallocate through the script system's allocator
virtual void* Allocate(size_t sz) = 0;
Calls a named method inside specified table.
virtual int BeginCall(HSCRIPTFUNCTION hFunc) = 0;
Márcio: changed the return type .
virtual int BeginCall(IScriptTable * pTable, const char * sFuncName) = 0;
virtual int BeginCall(const char * sFuncName) = 0;
From void to int for error checking.
Calls a named method inside specified table.
virtual int BeginCall(const char * sTableName, const char * sFuncName) = 0;
virtual int BeginPreCachedBuffer(int iIndex) = 0;
virtual void ClearPreCachedBuffer() = 0;
virtual ScriptAnyValue CloneAny(const ScriptAnyValue& any) = 0;
Properly clones a ScriptAnyValue. It will create new references to objects if appropriate.
virtual bool CompareFuncRef(HSCRIPTFUNCTION f1, HSCRIPTFUNCTION f2) = 0;
Adds new reference to function referenced by HSCRIPTFUNCTION.
Facility to pre-catch any Lua buffer.
virtual HSCRIPTFUNCTION CompileBuffer(const char * sBuffer, size_t nSize, const char* sBufferDesc) = 0;
Creates a new IScriptTable table accessible to the scripts.
virtual IScriptTable* CreateTable(bool bEmpty = false) = 0;
A pointer to the created object, with the reference count of 0.
virtual IScriptTable * CreateUserData(void * ptr, size_t size) = 0;
virtual size_t Deallocate(void* ptr) = 0;
virtual void DebugContinue() = 0;
virtual void DebugDisable() = 0;
virtual void DebugStepInto() = 0;
virtual void DebugStepNext() = 0;
virtual void DumpCallStack() = 0;
dump callstack to log, can be used during exception handling
Generates a OnLoadedScriptDump() for every loaded script.
virtual void DumpLoadedScripts() = 0;
Ends a call to script function.
virtual bool EndCall() = 0;
template <class T> bool EndCall(T & value);
virtual bool EndCallAny(ScriptAnyValue & any) = 0;
virtual bool EndCallAnyN(int n, ScriptAnyValue* anys) = 0;
Executes an ASCII buffer.
virtual bool ExecuteBuffer(const char * sBuffer, size_t nSize, const char * sBufferDescription = "", IScriptTable* pEnv = 0) = 0;
Parameters |
Description |
const char * sBuffer |
An 8bit ASCII buffer containing the script that must be executed. |
const char * sBufferDescription = "" |
Used as a name to describe the buffer. |
bRaiseError |
When set to true, the script engine will call CryWarning when an error in the script file occurs. |
False if the execution fails, otherwise it will be true.
All global variables and functions declared in the executed script will persist for all the script system lifetime.
Loads and runs a script file.
virtual bool ExecuteFile(const char * sFileName, bool bRaiseError = true, bool bForceReload = false, IScriptTable* pEnv = 0) = 0;
Parameters |
Description |
const char * sFileName |
Path of the script file. |
bool bRaiseError = true |
When set to true, the script engine will call CryWarning when an error in the script file occurs. |
False if the execution fails, otherwise it will be true.
All global variables and functions declared in the executed script will persist for all the script system lifetime.
virtual void ForceGarbageCollection() = 0;
Forces a Garbage collection cycle. Notes: In the current status of the engine the automatic GC is disabled so this function must be called explicitly.
virtual BreakState GetBreakState() = 0;
virtual IScriptTable * GetCallsStack() = 0;
[1]={ description="function bau()", line=234, sourcefile="/scripts/bla/bla/bla.lua"
Gets number of "garbaged" object.
virtual int GetCGCount() = 0;
Gets the environment of the given function
virtual IScriptTable* GetEnvironment(HSCRIPTFUNCTION scriptFunction) = 0;
Parameters |
Description |
HSCRIPTFUNCTION scriptFunction |
Function to receive the environment |
Pointer to a script table containing the environment
virtual HSCRIPTFUNCTION GetFunctionPtr(const char * sFuncName) = 0;
Gets reference to the Lua function. Notes: This reference must be released with IScriptSystem::ReleaseFunc().
virtual HSCRIPTFUNCTION GetFunctionPtr(const char * sTableName, const char * sFuncName) = 0;
virtual bool GetGlobalAny(const char * sKey, ScriptAnyValue & any) = 0;
Get Global value.
template <class T> bool GetGlobalValue(const char * sKey, T & value);
Get Global value.
virtual IScriptTable * GetLocalVariables(int nLevel = 0) = 0;
virtual void GetMemoryStatistics(ICrySizer * pSizer) const = 0;
Retrieves size of memory allocated in script.
virtual uint32 GetScriptAllocSize() = 0;
virtual void GetScriptHash(const char * sPath, const char * szKey, unsigned int & dwHash) = 0;
Parameters |
Description |
const char * sPath |
Zero terminated path to the variable (e.g. _localplayer.cnt), max 255 characters. |
const char * szKey |
Zero terminated name of the variable (e.g. luaFunc), max 255 characters. |
unsigned int & dwHash |
It is used as input and output. |
Notes: Is not recursive but combines the hash values of the whole table when the specifies variable is a table otherwise has to be a Lua function.
virtual int GetStackSize() = 0;
virtual void LoadScriptedSurfaceTypes(const char * sFolder, bool bReload) = 0;
virtual void PostInit() = 0;
Notes: Called one time after initialization of system to register script system console vars.
virtual int PreCacheBuffer(const char * sBuffer, size_t nSize, const char* sBufferDesc) = 0;
template <class T> void PushFuncParam(const T & value);
virtual void PushFuncParamAny(const ScriptAnyValue & any) = 0;
Push a parameter during a function call.
virtual void RaiseError(const char * format, ...);
Releases and destroys the script system.
virtual void Release() = 0;
virtual void ReleaseAny(const ScriptAnyValue& any) = 0;
Properly releases a ScriptAnyValue. It will release references to objects if appropriate.
virtual void ReleaseFunc(HSCRIPTFUNCTION f) = 0;
Frees references created with GetFunctionPtr or GetValue for HSCRIPTFUNCTION.
Reloads a script.
virtual bool ReloadScript(const char * sFileName, bool bRaiseError = true) = 0;
Parameters |
Description |
const char * sFileName |
Path of the script file to reload. |
bool bRaiseError = true |
When set to true, the script engine will call CryWarning when an error in the script file occurs. |
False if the execution fails, otherwise it will be true.
Reloads all the scripts previously loaded.
virtual bool ReloadScripts() = 0;
False if the execution of one of the script fails, otherwise it will be true.
Resets all the script timers.
virtual void ResetTimers() = 0;
Serializes script timers.
virtual void SerializeTimers(ISerialize * pSer) = 0;
Sets the environment of the given function
virtual void SetEnvironment(HSCRIPTFUNCTION scriptFunction, IScriptTable* pEnv) = 0;
Parameters |
Description |
HSCRIPTFUNCTION scriptFunction |
Function to receive the environment |
IScriptTable* pEnv |
Environment to set |
Sets the rate of Garbage Collection for script system.
virtual void SetGCFrequency(const float fRate) = 0;
Parameters |
Description |
const float fRate |
The rate in seconds. |
virtual void SetGCThreshhold(int nKb) = 0;
Legacy function.
virtual void SetGlobalAny(const char * sKey, const ScriptAnyValue & any) = 0;
Set Global value.
virtual void SetGlobalToNull(const char * sKey);
Set Global value to Null.
template <class T> void SetGlobalValue(const char * sKey, const T & value);
Set Global value.
virtual void ShowDebugger(const char * pszSourceFile, int iLine, const char * pszReason) = 0;
Notes: Debug functions.
virtual void UnloadScript(const char * sFileName) = 0;
Parameters |
Description |
const char * sFileName |
Path of the script file. |
Unloads a script.
The script engine never loads twice the same file because it internally stores a list of the loaded files. Calling this functions will remove the script file from this list.
Unloads all the scripts.
virtual void UnloadScripts() = 0;
Updates the system, per frame.
virtual void Update() = 0;