diff --git a/src/lua_colorlib.c b/src/lua_colorlib.c index dfb45f44d55f48119255fb9ceebd4eb76e21e575..e1665a0296d5c1c7fb6e83ecf818ca2d1da67a79 100644 --- a/src/lua_colorlib.c +++ b/src/lua_colorlib.c @@ -122,7 +122,7 @@ const char *const colormap_gen_opt[] = { static void GenerateColormap(lua_State *L, UINT8 *colormap) { - INT32 mode = luaL_checkoption(L, 1, NULL, colormap_gen_opt), i; + INT32 mode = luaL_checkoption(L, 1, "default", colormap_gen_opt), i; for (i = 0; i < NUM_PALETTE_ENTRIES; i++) colormap[i] = i; @@ -202,14 +202,7 @@ static int lib_colormapCreate(lua_State *L) UINT8 generated_colormap[NUM_PALETTE_ENTRIES]; - if (!lua_isnoneornil(L, 1)) - GenerateColormap(L, generated_colormap); - else - { - INT32 i; - for (i = 0; i < NUM_PALETTE_ENTRIES; i++) - generated_colormap[i] = i; - } + GenerateColormap(L, generated_colormap); colormap = Z_MallocAlign(sizeof(colormap_t) + NUM_PALETTE_ENTRIES, PU_STATIC, NULL, 8); colormap->rows = 1; @@ -230,16 +223,12 @@ static int lib_colormapGenerate(lua_State *L) { colormap_t *colormap = *((colormap_t **)luaL_checkudata(L, 1, META_COLORMAP)); + if (colormap->flags & GTC_CACHE) + return luaL_error(L, "colormap is read-only"); + lua_remove(L, 1); - if (!lua_isnoneornil(L, 1)) - GenerateColormap(L, colormap->map); - else - { - INT32 i; - for (i = 0; i < NUM_PALETTE_ENTRIES; i++) - colormap->map[i] = i; - } + GenerateColormap(L, colormap->map); return 0; } @@ -253,6 +242,9 @@ static int lib_colormapMix(lua_State *L) INT32 start = luaL_optinteger(L, 5, 0); INT32 end = luaL_optinteger(L, 6, NUM_PALETTE_ENTRIES-1), i; + if (colormapA->flags & GTC_CACHE) + return luaL_error(L, "colormap is read-only"); + if (amt < 0 || amt > 255) luaL_error(L, "blend amount %d out of range (0 - %d)", amt, 255); @@ -295,6 +287,9 @@ static int lib_colormapMixRGB(lua_State *L) RGBA_t fg; + if (colormap->flags & GTC_CACHE) + return luaL_error(L, "colormap is read-only"); + if (amt < 0 || amt > 255) luaL_error(L, "blend amount %d out of range (0 - %d)", amt, 255); @@ -335,6 +330,9 @@ static int lib_colormapCopy(lua_State *L) INT32 start = luaL_optinteger(L, 3, 0); INT32 end = luaL_optinteger(L, 4, NUM_PALETTE_ENTRIES-1), i; + if (colormapA->flags & GTC_CACHE) + return luaL_error(L, "colormap is read-only"); + if (start < 0 || start >= NUM_PALETTE_ENTRIES) luaL_error(L, "index %d out of range (0 - %d)", start, NUM_PALETTE_ENTRIES-1); if (end <= 0) @@ -357,6 +355,9 @@ static int lib_colormapCopySkinColor(lua_State *L) INT32 start = luaL_optinteger(L, 3, DEFAULT_STARTTRANSCOLOR); INT32 end, i, j = 0; + if (colormap->flags & GTC_CACHE) + return luaL_error(L, "colormap is read-only"); + if (skincolor < 0 || skincolor >= numskincolors) luaL_error(L, "skin color %d out of range (0 - %d)", skincolor, numskincolors-1);