1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-29 15:47:46 +00:00
sapphire/src/servers/sapphire_zone/Script/ScriptLoader.h

103 lines
2.7 KiB
C
Raw Normal View History

2018-03-02 07:39:38 -03:00
#ifndef CORE_SCRIPTLOADER_H
#define CORE_SCRIPTLOADER_H
2017-12-12 17:29:31 +11:00
#include <unordered_map>
#include <set>
#include "NativeScriptApi.h"
#include "ScriptInfo.h"
#ifdef _WIN32
2018-03-04 18:13:05 +11:00
#define WIN32_LEAN_AND_MEAN
2018-03-04 18:13:05 +11:00
#include <winbase.h>
using ModuleHandle = HMODULE;
#else
#include <dlfcn.h>
using ModuleHandle = void*;
#endif
namespace Core {
namespace Scripting {
/*!
* Provides low level functionality for loading modules on different platforms along with managing those loaded modules.
*/
class ScriptLoader
{
protected:
/*!
* The internal list of all modules that are loaded.
*/
std::unordered_map< std::string, ScriptInfo* > m_scriptMap;
/*!
* Unload a loaded module from it's ModuleHandle
* @return true if the unload was successful, false if not
*/
bool unloadModule( ModuleHandle );
public:
ScriptLoader() = default;
/*!
* Gets the module file extention for the current platform (windows, linux, osx)
* @return The file extension for the current platform
*/
const std::string getModuleExtension();
/*!
* Load a module from a path
* @return A pointer to ScriptInfo if the load was successful, nullptr if it failed
*/
ScriptInfo* loadModule( const std::string& );
2017-12-12 17:29:31 +11:00
/*!
* Unload a script from it's ScriptInfo object
* @return true if successful, false if not
*/
bool unloadScript( ScriptInfo* );
/*!
* Unload a script via it's module handle
* @return true if successful, false if not
*/
bool unloadScript( ModuleHandle );
/*!
* 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
*/
ScriptInfo* getScriptInfo( std::string name );
/*!
* 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
*/
ScriptObject** getScripts( ModuleHandle handle );
/*!
* 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
*/
bool isModuleLoaded( std::string name );
/*!
* Case-insensitive search for modules, useful for debug commands
* @param scripts a set of ScriptInfo ptrs
* @param search the search term
*/
void findScripts( std::set< Core::Scripting::ScriptInfo* >& scripts, const std::string& search );
};
}
}
2018-03-02 07:39:38 -03:00
#endif // CORE_SCRIPTLOADER_H