Allow using alpha with hexcode when setting color

Implements #411 proposal
This commit is contained in:
Josip Miskovic 2021-04-15 16:40:08 +02:00 committed by Bjorn
parent b02c30a0e4
commit 8b5d3af9b8
1 changed files with 2 additions and 4 deletions

View File

@ -400,14 +400,12 @@ void luax_readcolor(lua_State* L, int index, Color* color) {
color->g = luax_checkfloat(L, index + 1);
color->b = luax_checkfloat(L, index + 2);
color->a = luax_optfloat(L, index + 3, 1.);
} else if (lua_gettop(L) == index) {
} else if (lua_gettop(L) <= index + 1) {
uint32_t x = luaL_checkinteger(L, index);
color->r = ((x >> 16) & 0xff) / 255.f;
color->g = ((x >> 8) & 0xff) / 255.f;
color->b = ((x >> 0) & 0xff) / 255.f;
color->a = 1.f;
} else {
luaL_error(L, "Invalid color, expected a hexcode, 3 numbers, 4 numbers, or a table");
color->a = luax_optfloat(L, index + 1, 1.);
}
}