From 5b6c35aa8679e1bae0d42ee8a5d89210dbd4cc96 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 18 Sep 2018 09:36:42 -0300 Subject: [PATCH] lua: add Layer.parent/previous/next properties --- src/app/script/layer_class.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/app/script/layer_class.cpp b/src/app/script/layer_class.cpp index b1def2b5e..c576969cc 100644 --- a/src/app/script/layer_class.cpp +++ b/src/app/script/layer_class.cpp @@ -40,6 +40,36 @@ int Layer_get_sprite(lua_State* L) return 1; } +int Layer_get_parent(lua_State* L) +{ + auto layer = get_ptr(L, 1); + if (layer->parent() == layer->sprite()->root()) + push_ptr(L, layer->sprite()); + else + push_ptr(L, layer->parent()); + return 1; +} + +int Layer_get_previous(lua_State* L) +{ + auto layer = get_ptr(L, 1); + if (auto previous = layer->getPrevious()) + push_ptr(L, previous); + else + lua_pushnil(L); + return 1; +} + +int Layer_get_next(lua_State* L) +{ + auto layer = get_ptr(L, 1); + if (auto next = layer->getNext()) + push_ptr(L, next); + else + lua_pushnil(L); + return 1; +} + int Layer_get_name(lua_State* L) { auto layer = get_ptr(L, 1); @@ -218,6 +248,9 @@ const luaL_Reg Layer_methods[] = { const Property Layer_properties[] = { { "sprite", Layer_get_sprite, nullptr }, + { "parent", Layer_get_parent, nullptr }, + { "previous", Layer_get_previous, nullptr }, + { "next", Layer_get_next, nullptr }, { "name", Layer_get_name, Layer_set_name }, { "opacity", Layer_get_opacity, Layer_set_opacity }, { "blendMode", Layer_get_blendMode, Layer_set_blendMode },