Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wscherphof/lua-set
Straightforward Set library for Lua
https://github.com/wscherphof/lua-set
Last synced: about 1 month ago
JSON representation
Straightforward Set library for Lua
- Host: GitHub
- URL: https://github.com/wscherphof/lua-set
- Owner: wscherphof
- Created: 2013-03-26T22:05:42.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2016-08-24T12:48:19.000Z (about 8 years ago)
- Last Synced: 2024-09-14T02:58:34.786Z (2 months ago)
- Language: Lua
- Size: 367 KB
- Stars: 11
- Watchers: 2
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#LuaRock "set"
Straightforward Set library for Lua##Install
Set is a listed [LuaRock](http://luarocks.org/repositories/rocks/). Install using [LuaRocks](http://www.luarocks.org/): `luarocks install set`###Dependencies
Set depends on [Lua 5.2](http://www.lua.org/download.html). [lunitx](https://github.com/dcurrie/lunit) is needed to run the tests and will be installed if not present##Usage
Start off with
```lua
require("luarocks.loader")
local Set = require("Set")
```
Then, to create a set:
```lua
local ilike = Set:new()
```
to add items to a set:
```lua
ilike:add("apples")
ilike:add("bananas")
```
or, we could have done:
```lua
local ilike = Set:new({"apples", "bananas"})
```
Let's have another set:
```lua
local ulike = Set:new({"apples", "strawberries"})
```
Then we can:
```lua
local welike = ilike + ulike -- union: apples, bananas, strawberries
local webothlike = ilike * ulike -- intersection: apples
local udontlike = ilike - ulike -- subtraction: bananas
```
Lastly, some conveniences:
```lua
ilike:len() -- 2
local somethingilike = ilike:anelement()
print(ilike) -- {"apples", "bananas"}
```##Tests
See `./tst/init.lua`##License
LGPL+; see `./doc/LICENSE`