libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
ScriptLoader.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef ENABLE_SCRIPTING
4
8
9#include <unordered_map>
10#include <string>
11#include <optional>
12#include <functional>
13#include <memory>
14
15namespace Ship {
16class ResourceManager;
17
27
40class ScriptLoader : public Component {
41 public:
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)) {
59 }
60
65 void Compile(const std::shared_ptr<Archive>& archive);
66
72 void
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);
75
79 void LoadAll();
80
84 void UnloadAll();
85
92 void* GetFunction(const std::string& name, const std::string& function);
93
98 std::vector<std::string> GetLoadersInDependencyOrder() const;
99
105
106 private:
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;
117};
118
119} // namespace Ship
120
121#endif // ENABLE_SCRIPTING
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.