Hey ChatGPT, I have this large Lua code that I wrote. It's a code for a buffer that is drawn onto the screen. It uses hexadecimal characters to define a color. Here is the code:
---@alias blitargs string[]

---@class crove.Buffer
---@field __data blitargs[][]

---@type crove.Buffer
local buffer = {}
buffer.__data = {}

buffer.getBlitarg = function (x, y)
    x = math.floor(x)
    y = math.floor(y)
    if y > #buffer.__data or x > #buffer.__data[1] or x < 1 or y < 1 then error("Can't get Blitarg, out of bounds!") end
    return buffer.__data[y][x]
end

---@param x number
---@param y number
---@param char string
---@param charcol string
---@param bgcol string
buffer.setBlitarg = function (x, y, char, charcol, bgcol)
    x = math.floor(x)
    y = math.floor(y)
    if y > #buffer.__data or x > #buffer.__data[1] or x < 1 or y < 1 then return end
    buffer.__data[y][x][1] = char
    buffer.__data[y][x][2] = charcol
    buffer.__data[y][x][3] = bgcol
end

-- fill the buffer out
do
    local size = {term.getSize()}
    local width = size[1]
    local height = size[2]

    for y = 1, height do
        buffer.__data[y] = {}
        for x = 1, width do
            buffer.__data[y][x] = {" ", "0", "f"}
        end
    end
end

crove.graphics.flush = function ()
    ---@type blitargs[]
    local framebuffer = {}

    local txt = ""
    local txtcol = ""
    local bgcol = ""
    -- create a framebuffer
    for y, x_row in ipairs(buffer.__data) do
        framebuffer[y] = {}
        for _, blitarg in ipairs(x_row) do
            -- I do not understand why the second and third indecies are swapped, but it only works in this way??
            txt = txt..blitarg[1]
            txtcol = txtcol..blitarg[2]
            bgcol = bgcol..blitarg[3]
        end
        framebuffer[y][1] = txt
        framebuffer[y][2] = txtcol
        framebuffer[y][3] = bgcol
        txt = ""
        txtcol = ""
        bgcol = ""
    end
    -- finally draw to the screen
    for y, blitargs in ipairs(framebuffer) do
        term.setCursorPos(1, y)
        term.blit(blitargs[1], blitargs[2], blitargs[2])
    end
end

crove.graphics.clear = function ()
    for y = 1, #buffer.__data do
        for x = 1, #buffer.__data[y] do
            buffer.__data[y][x][1] = " "
            buffer.__data[y][x][2] = "0"
            buffer.__data[y][x][3] = "f"
        end
    end
end