mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-06 03:39:51 +00:00
[lua] Add __len operator to Properties
This commit is contained in:
parent
c77c95181a
commit
ef0596fd01
@ -26,6 +26,18 @@ struct Properties {
|
||||
Properties(doc::ObjectId id) : id(id) { }
|
||||
};
|
||||
|
||||
int Properties_len(lua_State* L)
|
||||
{
|
||||
auto propObj = get_obj<Properties>(L, 1);
|
||||
auto obj = static_cast<doc::WithUserData*>(get_object(propObj->id));
|
||||
if (!obj)
|
||||
return luaL_error(L, "the object with these properties was destroyed");
|
||||
|
||||
auto& properties = obj->userData().properties();
|
||||
lua_pushinteger(L, properties.size());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Properties_index(lua_State* L)
|
||||
{
|
||||
auto propObj = get_obj<Properties>(L, 1);
|
||||
@ -105,6 +117,7 @@ int Properties_newindex(lua_State* L)
|
||||
}
|
||||
|
||||
const luaL_Reg Properties_methods[] = {
|
||||
{ "__len", Properties_len },
|
||||
{ "__index", Properties_index },
|
||||
{ "__newindex", Properties_newindex },
|
||||
{ nullptr, nullptr }
|
||||
|
@ -15,6 +15,7 @@ do
|
||||
assert(spr.properties.c == "hi")
|
||||
-- TODO we don't have too much precision saving fixed points in properties
|
||||
assert(math.abs(spr.properties.d - 2.3) < 0.00001)
|
||||
assert(#spr.properties == 4)
|
||||
|
||||
spr.properties.a = false
|
||||
assert(spr.properties.a == false)
|
||||
|
Loading…
x
Reference in New Issue
Block a user