From bd33333f156ba4a2845c4d4ee14a4d4adde6f4ca Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 13 Sep 2018 11:50:04 -0300 Subject: [PATCH] lua: add Palette() ctor to copy palettes --- src/app/script/palette_class.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/app/script/palette_class.cpp b/src/app/script/palette_class.cpp index 98d14b342..7d16b7556 100644 --- a/src/app/script/palette_class.cpp +++ b/src/app/script/palette_class.cpp @@ -36,9 +36,14 @@ struct PaletteObj { int Palette_new(lua_State* L) { - int ncolors = lua_tointeger(L, 1); - push_new(L, nullptr, - new Palette(0, ncolors > 0 ? ncolors: 256)); + if (auto pal2 = may_get_obj(L, 1)) { + push_new(L, nullptr, new Palette(*pal2->palette)); + } + else { + int ncolors = lua_tointeger(L, 1); + push_new(L, nullptr, + new Palette(0, ncolors > 0 ? ncolors: 256)); + } return 1; }