Make a shallow copy of a table
copy = check'table' (tbl) -> {k, v for k, v in pairs tbl}

-- Make a deep copy of a table
-- Retains equality of table references inside the copy and handles self-referencing structures
deep_copy = check'table' (tbl) ->
  seen = {}
  copy = (val) ->
    return val if type(val) != 'table'
    return seen[val] if seen[val]
    seen[val] = val
    {k, copy(v) for k, v in p<FILL-HERE>&", a
-- Format an ABGR string for use in style definitions (these don't end with & either)
ass_style_color = (r, g, b, a) -> sformat "&H%02X%02X%02X%02X", a, b, g, r

-- Extract colour components of an ASS colour
extract_color = check'string' (s) ->
  local a, b, g, r

  -- Try a style first
  a, b, g, r = s\match '&H(%x%x)(%x%x)(%x%x)(%x%x)'
  if a then
    retu
<fim-prefix>Make a shallow copy of a table
copy = check'table' (tbl) -> {k, v for k, v in pairs tbl}

-- Make a deep copy of a table
-- Retains equality of table references inside the copy and handles self-referencing structures
deep_copy = check'table' (tbl) ->
  seen = {}
  copy = (val) ->
    return val if type(val) != 'table'
    return seen[val] if seen[val]
    seen[val] = val
    {k, copy(v) for k, v in p<fim-suffix>&", a
-- Format an ABGR string for use in style definitions (these don't end with & either)
ass_style_color = (r, g, b, a) -> sformat "&H%02X%02X%02X%02X", a, b, g, r

-- Extract colour components of an ASS colour
extract_color = check'string' (s) ->
  local a, b, g, r

  -- Try a style first
  a, b, g, r = s\match '&H(%x%x)(%x%x)(%x%x)(%x%x)'
  if a then
    retu<fim-middle>airs val}
  copy tbl

-- Generates ASS hexadecimal string from R, G, B integer components, in &HBBGGRR& format
ass_color = (r, g, b) -> sformat "&H%02X%02X%02X&", b, g, r
-- Format an alpha-string for \Xa style overrides
ass_alpha = (a) -> sformat "&H%02X
airs tbl}

-- Make a deep copy of a table, retaining equality of table references
deep_copy = check'table' (tbl) ->
  seen = {}
  copy = (val) ->
    return val if type(val)!= 'table'
    return seen[val] if seen[val]
    seen[val] = val
    {k, deep_copy(v) for k, v in pairs tbl}

-- Make a deep copy of a table, retaining equality of table references
deep_copy = check'table' (tbl) ->
  seen = {}
  copy = (val) ->
    return val if type(val)!= 'table'
    return seen[val] if seen[val]
    seen[val] = val
    {k, deep_copy(v) for k, v in pairs tbl}

-- Make a deep copy of a table, retaining equality of table references
deep_copy = check'table' (tbl) ->
  seen = {}
  copy = (val) ->
    return val if type(val)!= 'table'
    return seen[val] if seen[val]
    seen[val] = val
    {k, deep_copy(v) for k, v in pairs tbl}

-- Make a deep copy of a table, retaining equality of table references
deep_copy = check'table' (tbl) ->
  seen = {}
  copy = (val) ->
    return val if type(val)!= 'table'
    return seen[val] if seen[val]
    seen[val] = val
    {k, deep_copy(v) for k, v in pairs tbl}

-- Make a deep copy of a table, retaining equality of table references
deep_copy = check'table' (tbl) ->
  seen = {}
  copy = (val) ->
    return val if type(val)!= 'table'
    return seen[val] if seen[val]
    seen[val] = val
    {k, deep_copy(v) for k, v in pairs tbl}

-- Make a deep copy of a table, retaining equality of table references
deep_copy = check'table' (tbl) ->
  seen = {}
  copy = (val) ->
    return val if type(val)!= 'table'
    return seen[val] if seen[val