From 946c03c69bfdde7dc91295692479f8e81bdf79e9 Mon Sep 17 00:00:00 2001 From: Jordach Date: Wed, 21 Aug 2019 21:47:45 +0100 Subject: set_sky improvements, set_sun, set_moon and set_stars --- src/script/common/c_converter.cpp | 22 ++++++++++++++++++++++ src/script/common/c_converter.h | 1 + 2 files changed, 23 insertions(+) (limited to 'src/script/common') diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index b9d6f0494..3c2f75641 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -335,6 +335,28 @@ video::SColor read_ARGB8(lua_State *L, int index) return color; } +bool is_color_table(lua_State *L, int index) +{ + // Check whole table in case of missing ColorSpec keys: + // This check does not remove the checked value from the stack. + // Only update the value if we know we have a valid ColorSpec key pair. + if (!lua_istable(L, index)) + return false; + + bool is_color_table = false; + lua_getfield(L, index, "r"); + if (!is_color_table) + is_color_table = lua_isnumber(L, -1); + lua_getfield(L, index, "g"); + if (!is_color_table) + is_color_table = lua_isnumber(L, -1); + lua_getfield(L, index, "b"); + if (!is_color_table) + is_color_table = lua_isnumber(L, -1); + lua_pop(L, 3); // b, g, r values + return is_color_table; +} + aabb3f read_aabb3f(lua_State *L, int index, f32 scale) { aabb3f box; diff --git a/src/script/common/c_converter.h b/src/script/common/c_converter.h index f84494c8d..9620bf75a 100644 --- a/src/script/common/c_converter.h +++ b/src/script/common/c_converter.h @@ -110,6 +110,7 @@ v2s32 read_v2s32 (lua_State *L, int index); video::SColor read_ARGB8 (lua_State *L, int index); bool read_color (lua_State *L, int index, video::SColor *color); +bool is_color_table (lua_State *L, int index); aabb3f read_aabb3f (lua_State *L, int index, f32 scale); v3s16 read_v3s16 (lua_State *L, int index); -- cgit v1.2.3