You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nvim-libmodal/lua/libmodal/src/classes.lua

38 lines
683 B
Lua

return {
-------------------------
--[[ SUMMARY:
* Define a class-metatable.
]]
--[[
* `name` => the name of the class.
* `base` => the base class to use (`{}` by default).
]]
-------------------------
new = function(name, ...)
-- set self to `base`, or `{}` if nil.
local self = unpack({...}) or {}
-- set `__index`.
if not self.__index then
self.__index = self
end
-- set `__type`.
self.__type = name
return self
end,
------------------
--[[ SUMMARY:
* Get the type of some value `v`, if it has one.
]]
--[[ PARAMS:
* `v` => the value to get the type of.
]]
------------------
type = function(v)
return v.__type or type(v)
end
}