AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
agxLua::ScriptManager Class Referenceabstract

#include <ScriptManager.h>

+ Inheritance diagram for agxLua::ScriptManager:

Classes

class  RegisterScriptPluginProxy
 Class for instantiating a plugin that is loaded from a dynamic library. More...
 
class  ScriptPlugin
 

Public Types

enum  Priority { HIGHEST_PRIORITY = 2147483647, LOWEST_PRIORITY = 10000, DEFAULT_PRIORITY = 1073741824 }
 Specifies the ranges of the priority which can be assigned to a singleton at the time of creation. More...
 

Public Member Functions

void addScriptPlugin (ScriptPlugin *)
 Add A script-plugin to the list of registered plugins. More...
 
bool doFile (const std::string &path)
 Execute a lua script file. The file will be searched for in the specified filepath. More...
 
bool doGarbageCollection (agx::Real now=agx::Real(-1.0))
 Request garbage collection in lua, if currentTime < 0 then do it immediately. More...
 
bool doString (const std::string &string)
 Execute a string containing lua code. Returns true upon success. More...
 
virtual std::string getClassName () const =0
 
bool getGarbageCollectionEnabled () const
 
agx::Real getGarbageCollectionFrequency () const
 
std::string getLastErrorMessage () const
 
const char * getLogPath ()
 Return the path to the log file for lua debug text. More...
 
lua_State * getLua ()
 Return the current lua state (cast to lua_State) More...
 
int getMemoryUsed () const
 
std::string getPluginVersion ()
 
int getPriority () const
 Return the shutdown priority of the singleton instance. More...
 
bool getTreatInvalidAsErrors () const
 
void init (lua_State *L=nullptr, unsigned int stacksize=1024)
 Initializes the ScriptManager. More...
 
bool isLoaded (const std::string &libraryName)
 
bool registerLuaEntry (const void *ptr, const char *functionName)
 This method is used for registering a reference in a lua table. More...
 
bool registerSimulation (agxSDK::Simulation *simulation)
 
void removeScriptPlugin (ScriptPlugin *)
 Remove a script plugin from the list of registered plugins. More...
 
bool requestScriptPlugin (const std::string &libraryName)
 Try to load and register a script plugin with the given libraryName. More...
 
void setDebugMode (bool flag=true)
 Print debug information to the log-path (set in setLogPath) More...
 
void setGarbageCollectionEnabled (bool b)
 
void setGarbageCollectionFrequency (agx::Real f)
 
void setLastErrorMessage (const std::string &errorMessage)
 
void setLogPath (const std::string &path)
 Set the filename of the log file containing debug information from lua. More...
 
void setTreatInvalidAsErrors (const bool treatInvalidAsErrors)
 
void shutdown () override
 Deallocates any allocated memory. More...
 
bool unregisterLuaEntry (const void *ptr)
 

Static Public Member Functions

static ScriptManager * instance (bool erase=false)
 Return the singleton object If erase is true then this singleton will be de-inititialized. More...
 

Protected Member Functions

void _shutdown ()
 

Detailed Description

Definition at line 58 of file agxLua/ScriptManager.h.

Member Enumeration Documentation

enum agx::Singleton::Priority
inherited

Specifies the ranges of the priority which can be assigned to a singleton at the time of creation.

Enumerator
HIGHEST_PRIORITY 

The highest priority that can be given to a singleton.

LOWEST_PRIORITY 

The lowest priority that can be given to a singleton.

DEFAULT_PRIORITY 

The default priority given to a singleton.

Definition at line 35 of file Singleton.h.

Member Function Documentation

void agx::Singleton::_shutdown ( )
protectedinherited
void agxLua::ScriptManager::addScriptPlugin ( ScriptPlugin *  )

Add A script-plugin to the list of registered plugins.

Referenced by agxLua::ScriptManager::RegisterScriptPluginProxy< T >::RegisterScriptPluginProxy().

bool agxLua::ScriptManager::doFile ( const std::string &  path)

Execute a lua script file. The file will be searched for in the specified filepath.

bool agxLua::ScriptManager::doGarbageCollection ( agx::Real  now = agx::Real(-1.0))

Request garbage collection in lua, if currentTime < 0 then do it immediately.

Otherwise do garbage collection only if it was more than 1/getGarbageCollectionFrequency() seconds since it was last performed.

Returns
true if actual garbage collection was performed.
bool agxLua::ScriptManager::doString ( const std::string &  string)

Execute a string containing lua code. Returns true upon success.

virtual std::string agx::Singleton::getClassName ( ) const
pure virtualinherited
bool agxLua::ScriptManager::getGarbageCollectionEnabled ( ) const
inline

Definition at line 251 of file agxLua/ScriptManager.h.

agx::Real agxLua::ScriptManager::getGarbageCollectionFrequency ( ) const
inline

Definition at line 254 of file agxLua/ScriptManager.h.

std::string agxLua::ScriptManager::getLastErrorMessage ( ) const
inline

Definition at line 266 of file agxLua/ScriptManager.h.

const char* agxLua::ScriptManager::getLogPath ( )
inline

Return the path to the log file for lua debug text.

Definition at line 235 of file agxLua/ScriptManager.h.

lua_State* agxLua::ScriptManager::getLua ( )
inline

Return the current lua state (cast to lua_State)

Definition at line 232 of file agxLua/ScriptManager.h.

int agxLua::ScriptManager::getMemoryUsed ( ) const
Returns
num kbytes allocated by LUA
std::string agxLua::ScriptManager::getPluginVersion ( )
inline
int agx::Singleton::getPriority ( ) const
inherited

Return the shutdown priority of the singleton instance.

bool agxLua::ScriptManager::getTreatInvalidAsErrors ( ) const
inline

Definition at line 260 of file agxLua/ScriptManager.h.

void agxLua::ScriptManager::init ( lua_State *  L = nullptr,
unsigned int  stacksize = 1024 
)

Initializes the ScriptManager.

static ScriptManager* agxLua::ScriptManager::instance ( bool  erase = false)
static
bool agxLua::ScriptManager::isLoaded ( const std::string &  libraryName)
Returns
true if the named plugin is loaded
bool agxLua::ScriptManager::registerLuaEntry ( const void *  ptr,
const char *  functionName 
)

This method is used for registering a reference in a lua table.

The reason is the following:

Assume you have a object called Event. You create a Event inside a function as a local variable, local to avoid a clash with other global variables with the same name. Now this variable perhaps has a function defined: callback. So you write function myFunc() local e = Event:new() function e:callback() – do stuff end

– register the event manager:registerEvent(e) end

Now assume that the manager later on calls the callback method from the lua C API. As the variable e was declared local in the function myFunc, the call to e:callback() will fail.

This is the reason for registering a reference of the Event instance in a global table. This table is initially empty and is created by the tolua export file.

bool agxLua::ScriptManager::registerSimulation ( agxSDK::Simulation *  simulation)
void agxLua::ScriptManager::removeScriptPlugin ( ScriptPlugin *  )

Remove a script plugin from the list of registered plugins.

Referenced by agxLua::ScriptManager::RegisterScriptPluginProxy< T >::~RegisterScriptPluginProxy().

bool agxLua::ScriptManager::requestScriptPlugin ( const std::string &  libraryName)

Try to load and register a script plugin with the given libraryName.

Referenced by agxLua::ScriptManager::RegisterScriptPluginProxy< T >::RegisterScriptPluginProxy().

void agxLua::ScriptManager::setDebugMode ( bool  flag = true)

Print debug information to the log-path (set in setLogPath)

void agxLua::ScriptManager::setGarbageCollectionEnabled ( bool  b)
void agxLua::ScriptManager::setGarbageCollectionFrequency ( agx::Real  f)
inline

Definition at line 253 of file agxLua/ScriptManager.h.

void agxLua::ScriptManager::setLastErrorMessage ( const std::string &  errorMessage)
inline

Definition at line 267 of file agxLua/ScriptManager.h.

void agxLua::ScriptManager::setLogPath ( const std::string &  path)
inline

Set the filename of the log file containing debug information from lua.

Definition at line 226 of file agxLua/ScriptManager.h.

void agxLua::ScriptManager::setTreatInvalidAsErrors ( const bool  treatInvalidAsErrors)
inline

Definition at line 261 of file agxLua/ScriptManager.h.

void agxLua::ScriptManager::shutdown ( )
overridevirtual

Deallocates any allocated memory.

Reimplemented from agx::Singleton.

bool agxLua::ScriptManager::unregisterLuaEntry ( const void *  ptr)

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