libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
LibraryLoader.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <string>
5#include <vector>
6
7namespace Ship::Scripting {
8
10typedef void (*LibraryFunc_t)(void);
11
13typedef void* LibraryHandle_t;
14
31 public:
35 LibraryLoader() : mHandle(nullptr), mTempFile("") {
36 }
37
42 std::string GenerateTempFile();
43
50 void WriteToTempFile(const std::vector<uint8_t>& data);
51
64 void Init(const std::string& path);
65
82 void InitInMemory(void* tccState);
83
89 void* GetFunction(const std::string& name);
90
99 void Unload();
100
101 private:
102 LibraryHandle_t mHandle;
103 std::string mTempFile;
104 // Owned TCCState for in-memory JIT scripts; null for file-loaded libraries.
105 // maybe_unused: referenced only in TCC-enabled builds (not DISABLE_TCC_COMPILER).
106 [[maybe_unused]] void* mTccState = nullptr;
107};
108} // namespace Ship::Scripting
Loads and manages a single shared library (DLL / .so / .dylib) at runtime.
Definition LibraryLoader.h:30
void Unload()
Unloads the library from memory and cleans up platform resources.
void * GetFunction(const std::string &name)
Resolves an exported symbol from the loaded library.
void Init(const std::string &path)
Loads the shared library already written at path via the platform dynamic linker.
void WriteToTempFile(const std::vector< uint8_t > &data)
Writes raw library bytes to the temp file created by GenerateTempFile().
std::string GenerateTempFile()
Creates a temporary file path suitable for holding a library copy.
LibraryLoader()
Constructs an unloaded LibraryLoader with no associated library.
Definition LibraryLoader.h:35
void InitInMemory(void *tccState)
Relocates an in-memory TCC compilation unit and takes ownership of it.
Definition LibraryLoader.h:7
void(* LibraryFunc_t)(void)
Function pointer type for library entry points with no parameters and no return value.
Definition LibraryLoader.h:10
void * LibraryHandle_t
Opaque handle to a dynamically loaded shared library.
Definition LibraryLoader.h:13