minor scripting dogfood fixes (mat2d setters & artboard input) (#10934) a15901421d

chore: add missed setters and fix artboard inputs

Co-authored-by: Luigi Rosso <luigi-rosso@users.noreply.github.com>
This commit is contained in:
luigi-rosso
2025-10-29 19:36:59 +00:00
parent f40c37e1ba
commit bb53d90d1b
3 changed files with 167 additions and 1 deletions

View File

@@ -1 +1 @@
4e366e3ddb05e7738e93609ee8fe40ed1f829c26
a15901421df38b16aca3622ff6e5602e18c86001

View File

@@ -107,6 +107,88 @@ static int mat2d_withScaleAndTranslation(lua_State* L)
return 1;
}
static int mat2d_newindex(lua_State* L)
{
auto mat = lua_torive<ScriptedMat2D>(L, 1);
size_t namelen = 0;
const char* name = luaL_checklstring(L, 2, &namelen);
switch (namelen)
{
case 2:
switch (name[0])
{
case 'x':
switch (name[1])
{
case 'x':
mat->value.xx(luaL_checknumber(L, 3));
return 0;
case 'y':
mat->value.xy(luaL_checknumber(L, 3));
return 0;
}
break;
case 'y':
switch (name[1])
{
case 'x':
mat->value.yx(luaL_checknumber(L, 3));
return 0;
case 'y':
mat->value.yy(luaL_checknumber(L, 3));
return 0;
}
break;
case 't':
switch (name[1])
{
case 'x':
mat->value.tx(luaL_checknumber(L, 3));
return 0;
case 'y':
mat->value.ty(luaL_checknumber(L, 3));
return 0;
}
return 1;
default:
break;
}
break;
case 1:
switch (name[0])
{
case '1':
mat->value.xx(luaL_checknumber(L, 3));
return 0;
case '2':
mat->value.xy(luaL_checknumber(L, 3));
return 0;
case '3':
mat->value.yx(luaL_checknumber(L, 3));
return 0;
case '4':
mat->value.yy(luaL_checknumber(L, 3));
return 0;
case '5':
mat->value.tx(luaL_checknumber(L, 3));
return 0;
case '6':
mat->value.ty(luaL_checknumber(L, 3));
return 0;
default:
break;
}
break;
}
luaL_error(L,
"'%s' is not a valid index of %s",
name,
ScriptedMat2D::luaName);
return 0;
}
static int mat2d_index(lua_State* L)
{
auto mat = lua_torive<ScriptedMat2D>(L, 1);
@@ -270,6 +352,9 @@ int luaopen_rive_mat2d(lua_State* L)
lua_pushcfunction(L, mat2d_index, nullptr);
lua_setfield(L, -2, "__index");
lua_pushcfunction(L, mat2d_newindex, nullptr);
lua_setfield(L, -2, "__newindex");
lua_pushcfunction(L, mat2d_mul, nullptr);
lua_setfield(L, -2, "__mul");

View File

@@ -176,3 +176,84 @@ TEST_CASE("mat2d meta methods work", "[scripting]")
.state(),
-1) == 4);
}
TEST_CASE("mat2d setters work", "[scripting]")
{
CHECK(
lua_toboolean(ScriptingTest("local mat = Mat2D.identity()\n"
"mat.xx = 23\n"
"return mat == Mat2D.values(23,0,0,1,0,0)")
.state(),
-1) == 1);
CHECK(
lua_toboolean(ScriptingTest("local mat = Mat2D.identity()\n"
"mat[1] = 23\n"
"return mat == Mat2D.values(23,0,0,1,0,0)")
.state(),
-1) == 1);
CHECK(
lua_toboolean(ScriptingTest("local mat = Mat2D.identity()\n"
"mat.xy = 23\n"
"return mat == Mat2D.values(1,23,0,1,0,0)")
.state(),
-1) == 1);
CHECK(
lua_toboolean(ScriptingTest("local mat = Mat2D.identity()\n"
"mat[2] = 23\n"
"return mat == Mat2D.values(1,23,0,1,0,0)")
.state(),
-1) == 1);
CHECK(
lua_toboolean(ScriptingTest("local mat = Mat2D.identity()\n"
"mat.yx = 24\n"
"return mat == Mat2D.values(1,0,24,1,0,0)")
.state(),
-1) == 1);
CHECK(
lua_toboolean(ScriptingTest("local mat = Mat2D.identity()\n"
"mat[3] = 24\n"
"return mat == Mat2D.values(1,0,24,1,0,0)")
.state(),
-1) == 1);
CHECK(
lua_toboolean(ScriptingTest("local mat = Mat2D.identity()\n"
"mat.yy = 25\n"
"return mat == Mat2D.values(1,0,0,25,0,0)")
.state(),
-1) == 1);
CHECK(
lua_toboolean(ScriptingTest("local mat = Mat2D.identity()\n"
"mat[4] = 25\n"
"return mat == Mat2D.values(1,0,0,25,0,0)")
.state(),
-1) == 1);
CHECK(
lua_toboolean(ScriptingTest("local mat = Mat2D.identity()\n"
"mat.tx = 26\n"
"return mat == Mat2D.values(1,0,0,1,26,0)")
.state(),
-1) == 1);
CHECK(
lua_toboolean(ScriptingTest("local mat = Mat2D.identity()\n"
"mat[5] = 26\n"
"return mat == Mat2D.values(1,0,0,1,26,0)")
.state(),
-1) == 1);
CHECK(
lua_toboolean(ScriptingTest("local mat = Mat2D.identity()\n"
"mat.ty = 27\n"
"return mat == Mat2D.values(1,0,0,1,0,27)")
.state(),
-1) == 1);
CHECK(
lua_toboolean(ScriptingTest("local mat = Mat2D.identity()\n"
"mat[6] = 27\n"
"return mat == Mat2D.values(1,0,0,1,0,27)")
.state(),
-1) == 1);
}