mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-29 03:32:48 +00:00
lua: add support to use ipairs() with some collections (sprites/tags/slices/layers/frames/cels)
This commit is contained in:
parent
02388e2d6a
commit
ce9f064438
@ -50,9 +50,10 @@ int Cels_index(lua_State* L)
|
||||
{
|
||||
auto obj = get_obj<CelsObj>(L, 1);
|
||||
const int i = lua_tointeger(L, 2);
|
||||
if (i < 1 || i > obj->cels.size())
|
||||
return luaL_error(L, "index out of bounds %d", i);
|
||||
push_ptr<Cel>(L, obj->cels[i-1]);
|
||||
if (i >= 1 && i <= obj->cels.size())
|
||||
push_ptr<Cel>(L, obj->cels[i-1]);
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -45,9 +45,10 @@ int Frames_index(lua_State* L)
|
||||
{
|
||||
auto obj = get_obj<FramesObj>(L, 1);
|
||||
const int i = lua_tonumber(L, 2);
|
||||
if (i < 1 || i > obj->sprite->totalFrames())
|
||||
return luaL_error(L, "index out of bounds %d", i);
|
||||
push_sprite_frame(L, obj->sprite, i-1);
|
||||
if (i >= 1 && i <= obj->sprite->totalFrames())
|
||||
push_sprite_frame(L, obj->sprite, i-1);
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -48,9 +48,10 @@ int Layers_index(lua_State* L)
|
||||
{
|
||||
auto obj = get_obj<LayersObj>(L, 1);
|
||||
const int i = lua_tonumber(L, 2);
|
||||
if (i < 1 || i > int(obj->layers.size()))
|
||||
return luaL_error(L, "index out of bounds %d", i);
|
||||
push_ptr<Layer>(L, obj->layers[i-1]);
|
||||
if (i >= 1 && i <= int(obj->layers.size()))
|
||||
push_ptr<Layer>(L, obj->layers[i-1]);
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -44,9 +44,10 @@ int Slices_index(lua_State* L)
|
||||
auto obj = get_obj<SlicesObj>(L, 1);
|
||||
auto& slices = obj->sprite->slices();
|
||||
const int i = lua_tonumber(L, 2);
|
||||
if (i < 1 || i > int(slices.size()))
|
||||
return luaL_error(L, "index out of bounds %d", i);
|
||||
push_ptr<Slice>(L, *(slices.begin()+i-1));
|
||||
if (i >= 1 && i <= int(slices.size()))
|
||||
push_ptr<Slice>(L, *(slices.begin()+i-1));
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -52,9 +52,10 @@ int Sprites_index(lua_State* L)
|
||||
{
|
||||
auto obj = get_obj<SpritesObj>(L, 1);
|
||||
const int i = lua_tonumber(L, 2);
|
||||
if (i < 1 || i > int(obj->docs.size()))
|
||||
return luaL_error(L, "index out of bounds %d", i);
|
||||
push_ptr<Sprite>(L, obj->docs[i-1]->sprite());
|
||||
if (i >= 1 && i <= int(obj->docs.size()))
|
||||
push_ptr<Sprite>(L, obj->docs[i-1]->sprite());
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -46,9 +46,10 @@ int Tags_index(lua_State* L)
|
||||
auto obj = get_obj<TagsObj>(L, 1);
|
||||
auto& tags = obj->sprite->frameTags();
|
||||
const int i = lua_tonumber(L, 2);
|
||||
if (i < 1 || i > int(tags.size()))
|
||||
return luaL_error(L, "index out of bounds %d", i);
|
||||
push_ptr<FrameTag>(L, *(tags.begin()+i-1));
|
||||
if (i >= 1 && i <= int(tags.size()))
|
||||
push_ptr<FrameTag>(L, *(tags.begin()+i-1));
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user