A fast, portable Entity Component System for Luau. https://ukendio.github.io/jecs/
Find a file
2025-06-13 01:06:33 +02:00
.github Delete luau specific files 2025-06-11 01:08:03 +02:00
assets Fix line endings (#233) 2025-06-05 22:00:29 +02:00
examples Modify example 2025-02-05 22:26:12 +01:00
thesis Add tests for scheduler example 2024-08-21 01:59:25 +02:00
tools Fix line endings (#233) 2025-06-05 22:00:29 +02:00
.gitattributes Fix line endings (#233) 2025-06-05 22:00:29 +02:00
.gitignore Fix line endings (#233) 2025-06-05 22:00:29 +02:00
.luacheckrc lua51 2025-06-11 00:53:13 +02:00
.prettierrc Update ts type definitions (#142) 2024-10-12 03:45:37 +02:00
.stylua.toml Fix line endings (#233) 2025-06-05 22:00:29 +02:00
bench.project.json Update changelog 2024-11-23 20:52:01 +01:00
CHANGELOG.md Cleanup changelog 2025-05-10 23:27:35 +02:00
default.project.json Cleanup repository 2024-11-23 04:42:54 +01:00
jecs.lua lua51 2025-06-11 00:53:13 +02:00
LICENSE Create LICENSE 2024-06-11 21:06:27 +02:00
README.md Update README.md 2025-06-13 01:06:33 +02:00

jecs jit

Standalone ecs module in luajit that can iterate 800,000 entities at 60 frames per second with pure lua. Comes with support for entity relationships, zero-sized-tags, query caching and more.

Installation

If you are on the luajit branch, the recommended approach to install the library is just copy-pasting the source at jecs.lua

Example

local world = jecs.World.new()
local pair = jecs.pair

-- These components and functions are actually already builtin
-- but have been illustrated for demonstration purposes
local ChildOf = world:component()
local Name = world:component()

local function parent(entity)
    return world:target(entity, ChildOf)
end
local function getName(entity)
    return world:get(entity, Name)
end

local alice = world:entity()
world:set(alice, Name, "alice")

local bob = world:entity()
world:add(bob, pair(ChildOf, alice))
world:set(bob, Name, "bob")

local sara = world:entity()
world:add(sara, pair(ChildOf, alice))
world:set(sara, Name, "sara")

print(getName(parent(sara)))

for e, name in world:query(Name, pair(ChildOf, alice)) do
    print(name, "is the child of alice")
end

-- Output
-- "alice"
-- bob is the child of alice
-- sara is the child of alice

local Position = world:component()
local Velocity = world:component()

local function things_move(world, dt) 
    for e, p, v in world:query(Position, Velocity) do 
        world:set(e, Position, p + v * dt)
    end
end

things_move(world, 1/60)