Skip to content

Commit 244aa55

Browse files
luigi-rossoluigi-rosso
andcommitted
feature: test.blob(name) reads blob assets from test scripts (#13005) afd68206e6
* fix(lua): register the name atom so Blob.name resolves instead of erroring * feat(tests): test.blob(name) reads blob assets from test scripts Co-authored-by: Luigi Rosso <luigi-rosso@users.noreply.github.com>
1 parent afc52ab commit 244aa55

4 files changed

Lines changed: 34 additions & 1 deletion

File tree

.rive_head

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a77c1355bdd6e26f733edfd531ec7871f942efcf
1+
afd68206e676b8b4d360a720a86068094740d330

include/rive/lua/rive_lua_libs.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,5 +2252,15 @@ int lua_gpu_push_shader_by_name(lua_State* L, const char* name);
22522252
// Implemented in lua_scripted_context.cpp.
22532253
int lua_push_gpu_features(lua_State* L);
22542254

2255+
#ifdef WITH_RIVE_TOOLS
2256+
// Push a ScriptedBlob copying `data`, or an empty blob when data is null or
2257+
// size is 0. Only tooling constructs blobs from loose bytes; the runtime
2258+
// wraps in-file assets. Implemented in lua_blob.cpp.
2259+
int lua_push_blob(lua_State* L,
2260+
const char* name,
2261+
const uint8_t* data,
2262+
size_t size);
2263+
#endif
2264+
22552265
#endif
22562266
#endif

src/lua/renderer/lua_blob.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,28 @@ static int blob_index(lua_State* L)
6767
return 0;
6868
}
6969

70+
#ifdef WITH_RIVE_TOOLS
71+
int lua_push_blob(lua_State* L,
72+
const char* name,
73+
const uint8_t* data,
74+
size_t size)
75+
{
76+
auto scriptedBlob = lua_newrive<ScriptedBlob>(L);
77+
if (data != nullptr && size > 0)
78+
{
79+
auto blobAsset = make_rcp<BlobAsset>();
80+
if (name != nullptr)
81+
{
82+
blobAsset->name(name);
83+
}
84+
SimpleArray<uint8_t> bytes(data, size);
85+
blobAsset->decode(bytes, nullptr);
86+
scriptedBlob->asset = blobAsset;
87+
}
88+
return 1;
89+
}
90+
#endif
91+
7092
int luaopen_rive_blob(lua_State* L)
7193
{
7294
lua_register_rive<ScriptedBlob>(L);

src/lua/rive_lua_libs.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ std::unordered_map<std::string, int16_t> atoms = {
163163
{"image", (int16_t)LuaAtoms::image},
164164
{"blob", (int16_t)LuaAtoms::blob},
165165
{"size", (int16_t)LuaAtoms::size},
166+
{"name", (int16_t)LuaAtoms::name},
166167
{"duration", (int16_t)LuaAtoms::duration},
167168
{"setTime", (int16_t)LuaAtoms::setTime},
168169
{"setTimeFrames", (int16_t)LuaAtoms::setTimeFrames},

0 commit comments

Comments
 (0)