Skip to content
This repository has been archived by the owner on May 23, 2022. It is now read-only.

Latest commit

 

History

History
101 lines (60 loc) · 1.69 KB

README.md

File metadata and controls

101 lines (60 loc) · 1.69 KB

Loo

Build Status stable

Like Boo, but for Lua. Loo provides the basic prototypical primitives and combinators so you can structure your programs easily.

Example

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*

Installing

$ luarocks install loo

(Alternatively just download loo.lua)

Testing

Install Busted, then run the specs:

$ luarocks install busted
$ busted

(this assumes you have LuaRocks already installed on your system.)

Docs & Reference

extend(a, ...)

Extends the target Table with the provided mixins, using a right-most precedence rule.

extend: A:table, table... -> a

merge(...)

Creates a new Table that merges the provided mixins using a right-most precedence rule.

merge: table... -> table

derive(a, ...)

Creates a new Table inheriting from the given meta-Table, and extends it with the provided mixins.

derive: A:table, table... -> A <| B

Base:derive(...)

Like derive() but uses self as the meta-table to inherit from.

Base:derive: @self:table => table... -> self <| A

Licence

MIT/X11.