mirror of
https://github.com/Ukendio/jecs.git
synced 2025-11-18 17:22:52 +00:00
19 lines
393 B
Text
19 lines
393 B
Text
|
|
local world = require(script.Parent.world)
|
||
|
|
local handle = require(script.Parent.handle)
|
||
|
|
local refs = {}
|
||
|
|
|
||
|
|
local function ref(key)
|
||
|
|
if not key then
|
||
|
|
return handle(world:entity())
|
||
|
|
end
|
||
|
|
local e = refs[key]
|
||
|
|
if not e then
|
||
|
|
e = world:entity()
|
||
|
|
refs[key] = e
|
||
|
|
end
|
||
|
|
-- Cannot cache handles because they will get invalidated
|
||
|
|
return handle(e)
|
||
|
|
end
|
||
|
|
|
||
|
|
return ref
|