17 #ifndef AGXLUA_SCRIPTMANAGER_H
18 #define AGXLUA_SCRIPTMANAGER_H
21 # pragma warning( push )
22 # pragma warning( disable: 4512 ) // Disable warning about assignment operator could not be generated due to reference members.
56 #define LUA_SCRIPT_PLUGIN_VERSION "1.0"
84 virtual std::string getName()=0;
95 m_dependentPlugins.push_back( pluginName );
104 void registerDependentPlugins(
void );
107 virtual void init(lua_State* lua)=0;
115 virtual void close()=0;
140 "Plugin version (" << m_plugin->getPluginVersion() <<
141 ") does not match required version (" <<
146 for(; it != m_plugin->getDependentPlugins().end(); ++it)
201 bool registerLuaEntry(
const void* ptr,
const char* functionName);
202 bool unregisterLuaEntry(
const void* ptr);
204 #define ScriptManager_REGISTER_OBJECT( P, NAME ) agxLua::ScriptManager::instance()->registerLuaEntry(P, NAME) //this, typeid(this).name())
205 #define ScriptManager_UNREGISTER_OBJECT( P ) agxLua::ScriptManager::instance()->unregisterLuaEntry(P) //this, typeid(this).name())
208 void addScriptPlugin(ScriptPlugin *);
211 void removeScriptPlugin(ScriptPlugin *);
214 bool requestScriptPlugin(
const std::string& libraryName);
217 bool isLoaded(
const std::string& libraryName);
223 void setDebugMode(
bool flag =
true);
226 void setLogPath(
const std::string& path) { m_log_path=path; }
229 void init(lua_State* L=
nullptr,
unsigned int stacksize=1024);
232 lua_State*
getLua() {
return m_lua_state; }
238 bool doFile(
const std::string& path);
241 bool doString(
const std::string&
string);
250 void setGarbageCollectionEnabled(
bool b );
264 int getMemoryUsed()
const;
270 SINGLETON_CLASSNAME_METHOD();
273 void registerFunctions();
277 bool m_garbage_collection_enabled;
278 bool m_garbage_collection_requested;
279 agx::Real m_garbage_collection_frequency;
283 typedef ScriptPluginVector::iterator ScriptPluginVectorIterator;
285 ScriptPluginVector m_plugin_vector;
288 bool closeLibrary(
const std::string& fileName);
291 std::string createLibraryNameForExtension(
const std::string& ext);
294 DynamicLibraryList::iterator getLibraryItr(
const std::string& fileName);
300 DynamicLibraryList m_dllist;
302 std::string m_log_path;
303 lua_State* m_lua_state;
311 const std::string m_plugin_version;
315 ObjectReferenceMap m_object_references;
318 int m_incrementalSize;
319 bool m_shutdownInProgress;
320 bool m_treatInvalidAsErrors;
321 std::string m_lastErrorMessage;
326 #define g_luaScriptManager agxLua::ScriptManager::instance()
351 #if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__)
352 # if defined( AGX_LIBRARY_STATIC )
353 # define AGXLUAPLUGIN_EXPORT
355 # define AGXLUAPLUGIN_EXPORT __declspec(dllexport)
357 #elif !defined(_MSC_VER)
360 #define AGXLUAPLUGIN_EXPORT __attribute__ ((visibility("default")))
362 #define AGXLUAPLUGIN_EXPORT
365 #define AGXLUAPLUGIN_EXPORT
372 # pragma warning(pop)
LuaCallback(void *self, const char *className)
std::string getLastErrorMessage() const
void AGXPHYSICS_EXPORT init()
Initialize agx.
void setTreatInvalidAsErrors(const bool treatInvalidAsErrors)
~RegisterScriptPluginProxy()
void setLogPath(const std::string &path)
Set the filename of the log file containing debug information from lua.
void AGXPHYSICS_EXPORT shutdown()
Shutdown agx.
const StringVector & getDependentPlugins() const
AGXLUA_EXPORT int doFile(lua_State *L)
#define LUA_SCRIPT_PLUGIN_VERSION
AGXLUA_EXPORT int doString(lua_State *L)
const std::string * const_iterator
std::string getPluginVersion()
agx::ref_ptr< T > m_plugin
Base class providing referencing counted objects.
agx::ref_ptr< T > getPlugin()
StringVector m_dependentPlugins
ScriptManager * m_script_mgr
std::string getPluginVersion()
Return the compiled version of this plugin.
void addScriptPlugin(ScriptPlugin *)
Add A script-plugin to the list of registered plugins.
const char * getLogPath()
Return the path to the log file for lua debug text.
#define g_luaScriptManager
void removeScriptPlugin(ScriptPlugin *)
Remove a script plugin from the list of registered plugins.
bool getTreatInvalidAsErrors() const
agx::Vector< std::string > StringVector
void setLastErrorMessage(const std::string &errorMessage)
Smart pointer for handling referenced counted objects.
RegisterScriptPluginProxy()
lua_State * getLua()
Return the current lua state (cast to lua_State)
ScriptPlugin()
Constructor.
bool getGarbageCollectionEnabled() const
#define ScriptManager_UNREGISTER_OBJECT(P)
bool requestScriptPlugin(const std::string &libraryName)
Try to load and register a script plugin with the given libraryName.
Class for instantiating a plugin that is loaded from a dynamic library.
void setGarbageCollectionFrequency(agx::Real f)
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
void addDependentPlugin(const std::string pluginName)
Add a plugin name to the list of dependent plugins.
static ScriptManager * instance(bool erase=false)
Return the singleton object If erase is true then this singleton will be de-inititialized.
Inheritance with partial specialization due to bug with ref_ptr containers.
agx::Real getGarbageCollectionFrequency() const
#define ScriptManager_REGISTER_OBJECT(P, NAME)
Base class for Singletons that should have its shutdown called explicitly before exit of the applicat...