jecs/docs/index.md
2024-06-18 18:50:24 -05:00

1.7 KiB

layout hero features
home
name text tagline image actions
JECS Just an ECS JECS is a stupidly fast Entity Component System (ECS) github
theme text link
brand Learn JECS /learn
theme text link
alt API Usage /reference
title icon details
Relational 🧑‍🤝‍🧑 Entity Relationships as first class citizens
title icon details
Powerful 🔨 Iterate 350,000 entities at 60 frames per second
title icon details
Type Safe 👷 Type-safe Luau API (and soon Typescript 😊)
title icon details
Independent Zero-dependency package
title icon details
Fast Optimized for column-major operations
title icon details
Memory Safe 💾 Cache friendly archetype/SoA storage
title icon details
Stable 🛡️ Unit tested for stability

Code Example

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

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 in world:query(pair(ChildOf, alice)) do 
    print(getName(e), "is the child of alice")
end

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