2018-03-02 07:39:38 -03:00
|
|
|
#ifndef CORE_SCRIPTLOADER_H
|
|
|
|
#define CORE_SCRIPTLOADER_H
|
2017-12-10 15:31:48 +11:00
|
|
|
|
2017-12-12 17:29:31 +11:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <set>
|
|
|
|
|
2017-12-10 15:31:48 +11:00
|
|
|
#include "NativeScriptApi.h"
|
2017-12-12 01:45:24 +11:00
|
|
|
#include "ScriptInfo.h"
|
2017-12-10 15:31:48 +11:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2018-03-04 18:13:05 +11:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2018-03-06 00:10:36 +01:00
|
|
|
|
2018-03-04 18:13:05 +11:00
|
|
|
#include <winbase.h>
|
2018-04-24 20:34:36 +10:00
|
|
|
using ModuleHandle = HMODULE;
|
2017-12-10 15:31:48 +11:00
|
|
|
#else
|
|
|
|
#include <dlfcn.h>
|
2018-04-24 20:34:36 +10:00
|
|
|
using ModuleHandle = void*;
|
2017-12-10 15:31:48 +11:00
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
namespace Scripting {
|
|
|
|
|
2018-07-24 22:22:19 +10:00
|
|
|
/*!
|
|
|
|
* Provides low level functionality for loading modules on different platforms along with managing those loaded modules.
|
|
|
|
*/
|
2017-12-27 18:47:51 +11:00
|
|
|
class ScriptLoader
|
|
|
|
{
|
2017-12-10 15:31:48 +11:00
|
|
|
protected:
|
2018-07-24 22:22:19 +10:00
|
|
|
/*!
|
|
|
|
* The internal list of all modules that are loaded.
|
|
|
|
*/
|
2017-12-27 18:47:51 +11:00
|
|
|
std::unordered_map< std::string, ScriptInfo* > m_scriptMap;
|
2017-12-10 15:31:48 +11:00
|
|
|
|
2018-07-24 22:22:19 +10:00
|
|
|
/*!
|
|
|
|
* Unload a loaded module from it's ModuleHandle
|
|
|
|
* @return true if the unload was successful, false if not
|
|
|
|
*/
|
2017-12-27 18:47:51 +11:00
|
|
|
bool unloadModule( ModuleHandle );
|
2017-12-10 15:31:48 +11:00
|
|
|
|
|
|
|
public:
|
2018-07-24 22:22:19 +10:00
|
|
|
ScriptLoader() = default;
|
2017-12-10 15:31:48 +11:00
|
|
|
|
2018-07-24 22:22:19 +10:00
|
|
|
/*!
|
|
|
|
* Gets the module file extention for the current platform (windows, linux, osx)
|
|
|
|
* @return The file extension for the current platform
|
|
|
|
*/
|
2017-12-27 18:47:51 +11:00
|
|
|
const std::string getModuleExtension();
|
2018-07-24 22:22:19 +10:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Load a module from a path
|
|
|
|
* @return A pointer to ScriptInfo if the load was successful, nullptr if it failed
|
|
|
|
*/
|
2017-12-27 18:47:51 +11:00
|
|
|
ScriptInfo* loadModule( const std::string& );
|
2017-12-12 17:29:31 +11:00
|
|
|
|
2018-07-24 22:22:19 +10:00
|
|
|
/*!
|
|
|
|
* Unload a script from it's ScriptInfo object
|
|
|
|
* @return true if successful, false if not
|
|
|
|
*/
|
2017-12-27 18:47:51 +11:00
|
|
|
bool unloadScript( ScriptInfo* );
|
2018-07-24 22:22:19 +10:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Unload a script via it's module handle
|
|
|
|
* @return true if successful, false if not
|
|
|
|
*/
|
2017-12-27 18:47:51 +11:00
|
|
|
bool unloadScript( ModuleHandle );
|
|
|
|
|
2018-07-24 22:22:19 +10:00
|
|
|
/*!
|
|
|
|
* Look up a ScriptInfo* by a module name
|
|
|
|
* @param name The exact module name to search for, case-sensitive
|
|
|
|
* @return The ScriptInfo ptr if successful, nullptr if it wasn't found
|
|
|
|
*/
|
2017-12-27 18:47:51 +11:00
|
|
|
ScriptInfo* getScriptInfo( std::string name );
|
|
|
|
|
2018-07-24 22:22:19 +10:00
|
|
|
/*!
|
|
|
|
* Get all scripts assoicated with a module
|
|
|
|
* @param handle The handle to the module
|
|
|
|
* @return An array of unknown size ending with nullptr if success, nullptr if not
|
|
|
|
*/
|
2017-12-27 18:47:51 +11:00
|
|
|
ScriptObject** getScripts( ModuleHandle handle );
|
|
|
|
|
2018-07-24 22:22:19 +10:00
|
|
|
/*!
|
|
|
|
* Checks to see if a module with the specified name exists
|
|
|
|
* @param name The module name to lookup
|
|
|
|
* @return true if loaded, false if not
|
|
|
|
*/
|
2017-12-27 18:47:51 +11:00
|
|
|
bool isModuleLoaded( std::string name );
|
|
|
|
|
2018-07-24 22:22:19 +10:00
|
|
|
/*!
|
|
|
|
* Case-insensitive search for modules, useful for debug commands
|
|
|
|
* @param scripts a set of ScriptInfo ptrs
|
|
|
|
* @param search the search term
|
|
|
|
*/
|
2017-12-27 18:47:51 +11:00
|
|
|
void findScripts( std::set< Core::Scripting::ScriptInfo* >& scripts, const std::string& search );
|
2017-12-10 15:31:48 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-02 07:39:38 -03:00
|
|
|
#endif // CORE_SCRIPTLOADER_H
|