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

Like Boo, but for Lua! Primitives for dealing with prototypical inheritance using Lua metatables :D

License

Notifications You must be signed in to change notification settings

sorellabs/loo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Like Boo, but for Lua! Primitives for dealing with prototypical inheritance using Lua metatables :D

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages