summaryrefslogtreecommitdiff
path: root/mac/.config/mpv/script-modules/utf8/init.lua
blob: d2f72a4156b74f6ee28bbe8e7cb38f65d8d79054 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
local module_path = ...
module_path = module_path:match("^(.-)init$") or (module_path .. '.')

local ffi_enabled, ffi = pcall(require, 'ffi')

local utf8 = {
  config = {},
  default = {
    debug = nil,
    logger = io.write,
    loadstring = (loadstring or load),
    unpack = (unpack or table.unpack),
    cache = {
      regex = setmetatable({},{
        __mode = 'kv'
      }),
      plain = setmetatable({},{
        __mode = 'kv'
      }),
    },
    locale = nil,
    int32array = function(size)
      if ffi_enabled then
        return ffi.new("uint32_t[?]", size + 1)
      else
        return {}
      end
    end,
    conversion = {
      uc_lc = nil,
      lc_uc = nil
    }
  },
  regex = {
    compiletime = {
      charclass = {},
      begins = {},
      ends = {},
      modifier = {},
    }
  },
  util = {},
}

function utf8:require(name)
  local full_module_path = module_path .. name
  if package.loaded[full_module_path] then
    return package.loaded[full_module_path]
  end

  local mod = require(full_module_path)
  if type(mod) == 'function' then
    mod = mod(self)
    package.loaded[full_module_path] = mod
  end
  return mod
end

function utf8:init()
  for k, v in pairs(self.default) do
    self.config[k] = self.config[k] or v
  end

  self:require "util"
  self:require "primitives.init"
  self:require "functions.lua53"

  return self
end

return utf8