Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- Combine values into valid blit strings, in the format of
- --- `a1 .. a2 .. a3, b1 .. b2 .. b3, c1 .. c2 .. c3`.
- --- The input values are expected to be in the format of
- --- `a1, b1, c1, a2, b2, c2, a3, b3, c3`.
- ---@vararg string|table The values to combine. Tables will be pulled apart to allow for multiple values if calling functions.
- ---@return string text The combined text values.
- ---@return string text_color The combined text color values.
- ---@return string bg_color The combined background color values.
- local function combine_blit(...)
- local text = ""
- local text_color = ""
- local bg_color = ""
- local args = table.pack(...)
- local fixed_args = {}
- -- Rip subtables out and insert them as if they were arguments.
- for i = 1, args.n do
- local arg = args[i]
- if type(arg) == "table" then
- for j = 1, #arg do
- table.insert(fixed_args, arg[j])
- end
- else
- table.insert(fixed_args, arg)
- end
- end
- for i = 1, #fixed_args, 3 do
- local s1, s2, s3 = fixed_args[i], fixed_args[i + 1], fixed_args[i + 2]
- expect(i, s1, "string")
- expect(i + 1, s2, "string")
- expect(i + 2, s3, "string")
- if #s1 ~= #s2 or #s1 ~= #s3 then
- error(("Bad arguments %d, %d, %d: Must be same length (got %d, %d, %d)"):format(i, i + 1, i + 2, #s1, #s2, #s3), 2)
- end
- text = text .. s1
- text_color = text_color .. s2
- bg_color = bg_color .. s3
- end
- return text, text_color, bg_color
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement