[lua] Add possibility to set the whole properties object

This commit is contained in:
David Capello 2023-01-03 09:00:36 -03:00
parent b9537dbbe0
commit 427efef257
2 changed files with 16 additions and 0 deletions

View File

@ -13,6 +13,7 @@
#include "app/color.h"
#include "app/color_utils.h"
#include "app/script/luacpp.h"
#include "app/script/values.h"
#include "app/tx.h"
#include "doc/cel.h"
#include "doc/with_user_data.h"
@ -58,6 +59,15 @@ int UserData_get_properties(lua_State* L) {
return 1;
}
template<typename T>
int UserData_set_properties(lua_State* L) {
auto obj = get_docobj<T>(L, 1);
auto& properties = get_WithUserData<T>(obj)->userData().properties();
// TODO add undo information
properties = get_value_from_lua<doc::UserData::Properties>(L, 2);
return 0;
}
template<typename T>
int UserData_set_text(lua_State* L) {
auto obj = get_docobj<T>(L, 1);

View File

@ -53,6 +53,7 @@ do
e=Point(32, 20),
f=Size(40, 80),
g=Rectangle(2, 4, 6, 8) }
assert(#spr.properties == 6)
local m = spr.properties.m
assert(m.a == 10)
assert(m.b == "bye")
@ -73,6 +74,11 @@ do
assert(m.g.width == 6)
assert(m.g.height == 8)
-- Set all properties
spr.properties = { a=1000 }
assert(spr.properties.a == 1000)
assert(#spr.properties == 1)
-- Extension properties
spr.properties.a = 10
spr.properties("ext1").a = 20