Like Boo, but for Lua. Loo provides the basic prototypical primitives and combinators so you can structure your programs easily.
local loo = require("loo")
local Animal = loo.Base:derive({ name = 'Unknown' })
function Animal:say(thing)
return self.name .. ": " .. thing
end
local Cat = Animal:derive()
function Cat:purr(name)
return "*" .. self.name .. " purrs*"
end
local nyah = Cat:derive({ name = "Nyah" })
nyah:say("Nyan nyan nyan~")
-- => Nyah: Nyan nyan nyan~
nyah:purr()
-- => *Nyah purrs*
$ luarocks install loo
(Alternatively just download loo.lua
)
Install Busted, then run the specs:
$ luarocks install busted
$ busted
(this assumes you have LuaRocks already installed on your system.)
Extends the target Table
with the provided mixins, using a right-most
precedence rule.
extend: A:table, table... -> a
Creates a new Table
that merges the provided mixins using a right-most
precedence rule.
merge: table... -> table
Creates a new Table
inheriting from the given meta-Table
, and extends it
with the provided mixins.
derive: A:table, table... -> A <| B
Like derive()
but uses self
as the meta-table to inherit from.
Base:derive: @self:table => table... -> self <| A
MIT/X11.