Skip to content

superzazu/sequence.lua

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

sequence.lua

A Lua library that provides a doubly linked list, allowing you to safely add and remove elements to a sequence, even while iterating on it.

This library is heavily inspired by PICO-8 functions "add", "del", "all" and "foreach".

Example:

local sequence = require "sequence"

monsters = sequence.new()
monsters:add({["hp"] = 3})
monsters:add({["hp"] = 2})
monsters:add({["hp"] = 3})
monsters:add({["hp"] = 4})

for monster in monsters:all() do
    monster.hp = monster.hp - 2

    if monster.hp <= 0 then
        monsters:del(monster)
    end
end

monsters:foreach(function(m)
    print(m.hp)
end)

print(monsters.count) -- 3
print(#monsters) -- only available for Lua 5.2+

About

A double linked list implementation in Lua

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages