From 30a3b38fe15e7864f8e6661acfae83d523990421 Mon Sep 17 00:00:00 2001 From: Justin van der Leij Date: Mon, 30 Jul 2018 12:45:35 +0200 Subject: [PATCH] Allowed for component access via Entity[Component] --- lib/entity.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/entity.lua b/lib/entity.lua index 25fe897..e637277 100644 --- a/lib/entity.lua +++ b/lib/entity.lua @@ -29,7 +29,9 @@ function Entity:give(component, ...) error("bad argument #1 to 'Entity:give' (Component expected, got "..type(component)..")", 2) end - self.components[component] = component:__initialize(...) + local comp = component:__initialize(...) + self.components[component] = comp + self[component] = comp return self end @@ -56,6 +58,7 @@ function Entity:apply() for component, _ in pairs(self.removed) do self.components[component] = nil + self[component] = nil self.removed[component] = nil end