simple but effective Lua type system using metatables
Metatype is a library and specification for creating performant, documented, and typo-safe Lua record-types which can be formatted.
Turn off typo checking by setting the global LUA_OPT=3 or higher.

local G = G or _G
--- module documentation
local M = G.mod and mod'myMod' or {} -- (see pkg)

local mty = require'metaty'

-- Documentation for Pos (position)
M.Pos = mty'Pos' {
  'x[int]: x coordinate',
  'y[int]: y coordinate', y = 0,
}

local p1 = Pos{x=4}
local p1 = Pos{x=4, y=3, z=5} -- error if checking turned on

The above expands to the following. Note that the "typosafe" elements are removed when LUA_OPT > 3
local M = {}
local metaty = require'metaty'

local Pos = setmetatable({
  __name='Pos',
  y = 0,
  -- used with metaty.Fmt and help()
  __fields={'x', 'y', x='[int]', y='[int]'},
  __newindex = metaty.newindex, -- typosafe setting
}, {
  __call = function(T, t)
    metaty.fieldsCheck(T.__fields, t) -- typosafe constructor
    return setmetatable(t, T)
  end,
  __index = metaty.index, -- typosafe getting
})
Pos.__index = Pos

-- `mod` gives documentation reflection
PKG_LOCS[M.myFn]         = 'path/to/file.lua:123'
PKG_NAMES[M.myFn]        = 'mymod.Pos'
PKG_LOOKUP['myMod.Pos'] = M.Pos

API