Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/base
diff options
context:
space:
mode:
authorWereTech <17415815+WereTech@users.noreply.github.com>2025-02-23 16:30:28 -0600
committerWereTech <17415815+WereTech@users.noreply.github.com>2025-02-23 16:30:28 -0600
commit3108120076bad6b934c43526200f2beed4c96753 (patch)
treecd93426801ef017da057693b6a291df486314dcc /source/base
parentadad44c582d7cbbaf161a12d98533515c25d56e3 (diff)
add sourcePaths and origin callbacks
The purpose is to get metadata and origin from the Root callbacks. Slight changes by swapping "root->assets()" to "this"
Diffstat (limited to 'source/base')
-rw-r--r--source/base/StarAssets.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/source/base/StarAssets.cpp b/source/base/StarAssets.cpp
index 7db8efe..8471a0c 100644
--- a/source/base/StarAssets.cpp
+++ b/source/base/StarAssets.cpp
@@ -134,6 +134,27 @@ Assets::Assets(Settings settings, StringList assetSources) {
callbacks.registerCallbackWithSignature<Json, String>("json", bind(&Assets::json, this, _1));
callbacks.registerCallbackWithSignature<bool, String>("exists", bind(&Assets::assetExists, this, _1));
+ callbacks.registerCallback("sourcePaths", [this](LuaEngine& engine, Maybe<bool> withMetaData) -> LuaTable {
+ auto assetSources = this->assetSources();
+ auto table = engine.createTable(assetSources.size(), 0);
+ if (withMetaData.value()) {
+ for (auto& assetSource : assetSources)
+ table.set(assetSource, this->assetSourceMetadata(assetSource));
+ }
+ else {
+ size_t i = 0;
+ for (auto& assetSource : assetSources)
+ table.set(++i, assetSource);
+ }
+ return table;
+ });
+
+ callbacks.registerCallback("origin", [this](String const& path) -> Maybe<String> {
+ if (auto descriptor = this->assetDescriptor(path))
+ return this->assetSourcePath(descriptor->source);
+ return {};
+ });
+
callbacks.registerCallback("bytes", [this](String const& path) -> String {
auto assetBytes = bytes(path);
return String(assetBytes->ptr(), assetBytes->size());