• Stars
    star
    661
  • Rank 67,625 (Top 2 %)
  • Language
    Lua
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ECS for Lua

tiny-ecs

NOTE

Although there have been almost no commits in several years, this project is not abandoned. tiny-ecs is, for most intents and purposes, finished, and no bugs have been brought to my attention in a while. New issues on GitHub will be addressed.

Build StatusLicense

Tiny-ecs is an Entity Component System for Lua that's simple, flexible, and useful. Because of Lua's tabular nature, Entity Component Systems are a natural choice for simulating large and complex systems. For more explanation on Entity Component Systems, here is some basic info.

Tiny-ecs also works well with object-oriented programming in Lua because Systems and Entities do not use metatables. This means you can subclass your Systems and Entities and use existing Lua class frameworks with tiny-ecs, no problem. For an example on how to use tiny-ecs with object-oriented Lua, take a look at the demo branch, specifically the systems and entities subdirectories.

Overview

Tiny-ecs has four important types: Worlds, Filters, Systems, and Entities. Entities, however, can be any Lua table, and Filters are just functions that take an Entity as a parameter.

Entities

Entities are simply Lua tables of data that gets processed by Systems. Entities should contain primarily data rather than code, as it is the System's job to do logic on data. Henceforth, a key-value pair in an Entity will be referred to as a Component.

Worlds

Worlds are the outermost containers in tiny-ecs that contain both Systems and Entities. In typical use, only one World is used at a time.

Systems

Systems in tiny-ecs describe how to update Entities. Systems select certain Entities using a Filter, and then only update those select Entities. Some Systems don't update Entities, and instead just act as function callbacks every update. Tiny-ecs provides functions for creating Systems easily, as well as creating Systems that can be used in an object oriented fashion.

Filters

Filters are used to select Entities. Filters can be any Lua function, but tiny-ecs provides some functions for generating common ones, like selecting only Entities that have all required components.

Example

local tiny = require("tiny")

local talkingSystem = tiny.processingSystem()
talkingSystem.filter = tiny.requireAll("name", "mass", "phrase")
function talkingSystem:process(e, dt)
    e.mass = e.mass + dt * 3
    print(("%s who weighs %d pounds, says %q."):format(e.name, e.mass, e.phrase))
end

local joe = {
    name = "Joe",
    phrase = "I'm a plumber.",
    mass = 150,
    hairColor = "brown"
}

local world = tiny.world(talkingSystem, joe)

for i = 1, 20 do
    world:update(1)
end

Use It

Copy paste tiny.lua into your source folder. For stability and consistent API, please use a tagged release or use LuaRocks.

Luarocks

Tiny-ecs is also on LuaRocks and can be installed with luarocks install tiny-ecs.

Demo

Check out the demo, a game originally written for Ludum Dare 32 with the theme 'An Unconventional Weapon'. The demo uses LÖVE, an amazing game framework for Lua.

Testing

Tiny-ecs uses busted for testing. Install and run busted from the command line to test.

Documentation

See API here. For the most up-to-date documentation, read the source code, or generate the HTML locally with LDoc. See the original forum thread here.

More Repositories

1

Fennel

Lua Lisp Language
Fennel
2,378
star
2

binser

Customizable Lua Serializer
Lua
197
star
3

moonmint

A Web Framework for Lua
Lua
75
star
4

Splash.lua

2D Spatial Hashing in Lua
Lua
71
star
5

mendoza

A Static Site Generator
Janet
54
star
6

fennel.vim

Syntax highlighting for Fennel
Vim Script
51
star
7

Editgrid

gamera and HUMP compatible scaling grid for LÖVE
Lua
44
star
8

CommandoKibbles

Cannon Cat Game for Ludum Dare 32
Lua
39
star
9

luamd

Markdown to HTML in pure Lua.
Lua
33
star
10

corope

Lua threading utility using coroutines.
Lua
29
star
11

littleserver

A simple test HTTP server for Janet, circlet, and jpm.
13
star
12

ats-lua

An ATS to Lua compiler
ATS
9
star
13

janet-miniz

Janet bindings to the miniz library.
C
7
star
14

ldmath.h

Home rolled header only c game math lib.
C
7
star
15

ats2.vim

A vim package for working with the ATS2 language.
Vim Script
5
star
16

x43bot

Just an IRC bot.
4
star
17

weregoat

Game for Ludum Dare 33
Lua
4
star
18

libatscc2lua

Runtime library for code compiled from ATS to Lua
Lua
4
star
19

mcu-serve

HTTP Server for NodeMCU + ESP32
HTML
4
star
20

WTBUiOS

Boston University WTBU app
Swift
3
star
21

bkdoc

Markup format and compiler that can output to different document formats.
C
3
star
22

dotfiles

My Dotfiles
Shell
2
star
23

EGF

A Java entity-component game framework that uses slick.
Java
2
star
24

go

Go in ClojureScript - Play at
JavaScript
1
star
25

ldoomc

C GL code
C
1
star
26

msp432-morse

Example project for the msp432p401r microcontroller
C
1
star
27

truss-analysis

MATLAB
1
star
28

ezglib

An Easy Game Library in ClojureScript
Clojure
1
star
29

TankLand

A tank simulation written in Clojure
Clojure
1
star
30

heroku-buildpack-moonmint

A Heroku buildpack for LuaJIT and the moonmint server
CMake
1
star