9#include <unordered_map>
52 ScriptLoader(
const std::unordered_map<std::string, std::string>& compileDefines,
const uint32_t codeVersion,
53 const std::string& buildOptions,
const std::vector<std::string>& includePaths,
54 const std::vector<std::string>& libraryPaths,
const std::vector<std::string>& libraries,
55 std::shared_ptr<ResourceManager> resourceManager =
nullptr)
56 :
Component(
"ScriptLoader"), mCodeVersion(codeVersion), mBuildOptions(buildOptions),
57 mIncludePaths(includePaths), mLibraryPaths(libraryPaths), mLibraries(libraries),
58 mCompileDefines(compileDefines), mResourceManager(std::move(resourceManager)) {
65 void Compile(
const std::shared_ptr<Archive>& archive);
73 CompileAll(
const std::optional<std::function<
void(
const std::shared_ptr<Archive>&)>>& preCallback = std::nullopt,
74 const std::optional<std::function<
void()>>& postCallback = std::nullopt);
92 void*
GetFunction(
const std::string& name,
const std::string& function);
107 uint32_t mCodeVersion;
109 std::string mBuildOptions =
"-g -Wl";
110 std::vector<std::string> mIncludePaths;
111 std::vector<std::string> mLibraryPaths;
112 std::vector<std::string> mLibraries;
113 std::unordered_map<std::string, std::string> mCompileDefines;
114 std::unordered_map<std::string, Scripting::LibraryLoader> mLoadedScripts;
115 std::vector<std::shared_ptr<Archive>> mLoadedArchives;
116 std::shared_ptr<ResourceManager> mResourceManager;
A named Part with a parent/child hierarchy and optional thread safety.
Definition Component.h:34
Manages compilation, loading, and lifetime of runtime scripts.
Definition ScriptLoader.h:40
void CompileAll(const std::optional< std::function< void(const std::shared_ptr< Archive > &)> > &preCallback=std::nullopt, const std::optional< std::function< void()> > &postCallback=std::nullopt)
Compiles scripts from all mounted archives.
std::vector< std::string > GetLoadersInDependencyOrder() const
Returns the names of all loaded script modules sorted in dependency order.
void LoadAll()
Loads all previously compiled script modules into the runtime.
void Compile(const std::shared_ptr< Archive > &archive)
Compiles script sources from a single archive.
ScriptLoader(const std::unordered_map< std::string, std::string > &compileDefines, const uint32_t codeVersion, const std::string &buildOptions, const std::vector< std::string > &includePaths, const std::vector< std::string > &libraryPaths, const std::vector< std::string > &libraries, std::shared_ptr< ResourceManager > resourceManager=nullptr)
Constructs a ScriptLoader with the given compiler configuration.
Definition ScriptLoader.h:52
void * GetFunction(const std::string &name, const std::string &function)
Looks up a function exported by a loaded script module.
void SetSafeLevel(SafeLevel level)
Sets the security level for script loading.
void UnloadAll()
Unloads all currently loaded script modules.
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14
SafeLevel
Security level controlling which scripts are allowed to load and execute.
Definition ScriptLoader.h:21
@ DISABLE_SCRIPTS
No scripts are loaded or executed.
@ WARN_UNTRUSTED_SCRIPTS
Untrusted scripts are loaded with a warning.
@ ONLY_TRUSTED_SCRIPTS
Only scripts from signed/trusted archives are loaded.
@ ALLOW_ALL_SCRIPTS
All scripts are loaded without restriction.