ecs/test/test2.lua

50 lines
1.0 KiB
Lua

local ecs = require "ecs"
require "ecs.Wrapper"
function init()
print("Registering components")
LuaData = ecs.register("LuaData", {
speed = "number",
something = "string",
alive = "boolean"
})
TestThing = ecs.register("TestThing", {
test = "string"
})
end
function run()
print("Running!")
manager = get_manager()
print("AAA")
manager:view("TestThing"):for_each(function(ent)
data = ent:get_component("TestThing")
print("test: " .. data.test)
end)
manager:view("LuaData"):for_each(function(ent)
-- @todo It would be nice if this could somehow be passed in as function arg
data = ent:get_component("LuaData")
print("speed: " .. data.speed)
print("something: " .. data.something)
-- @todo You cannot concatenate bool to string
print("alive: ")
print(data.alive)
end)
-- @todo Allow this
-- for i, v in pairs(manager:view("TestThing")) do
-- print(i, v)
-- end
print("Exists: ")
print(manager:has_entity("70bca3cf-33dd-40dc-8b0f-2e19aa0b4a17"))
print("Done running!")
end