2024-01-14 13:13:41 (UTC-03:00)
Marcel Rodrigues <marcelgmr@gmail.com>
sdl.gfx: make "Color" suffix and "SDL_" prefix optional
diff --git a/lib/arco/sdl2_gfx.lua b/lib/arco/sdl2_gfx.lua index cfb7784..bb83a58 100644 --- a/lib/arco/sdl2_gfx.lua +++ b/lib/arco/sdl2_gfx.lua @@ -51,10 +51,12 @@ local gfx = ffi.load("SDL2_gfx") return setmetatable({}, { __index = function (t, k) - local ok, obj = pcall(function () return gfx["gfx"..k] end) - if not ok then - obj = gfx[k] + local keys = {"SDL_"..k, k.."Color", k} + for _, key in ipairs(keys) do + local ok, obj = pcall(function () return gfx[key] end) + if ok then + return obj + end end - return obj end })