aboutsummaryrefslogtreecommitdiffstats
path: root/src/components
diff options
context:
space:
mode:
authorAndy Belle-Isle <drumsetmonkey@gmail.com>2019-08-31 00:40:21 -0400
committerAndy Belle-Isle <drumsetmonkey@gmail.com>2019-08-31 00:40:21 -0400
commit4eeacc60cab3d6cb070bcd19a5259b7a95832a1d (patch)
tree7e26aea1b95dec5bb5bfaf4749cba0b71dd06cf9 /src/components
parent3a5718d4ab0d9f726686c601579a4c586a65e269 (diff)
Lua spawned entities have "Idle" function
Every entity spawned from Lua is given the "Scripted" component, this component holds onto the Entities master table and it's idle function
Diffstat (limited to 'src/components')
-rw-r--r--src/components/Script.hpp (renamed from src/components/IdleFunc.hpp)37
1 files changed, 27 insertions, 10 deletions
diff --git a/src/components/IdleFunc.hpp b/src/components/Script.hpp
index 29bcd7b..0e7c9db 100644
--- a/src/components/IdleFunc.hpp
+++ b/src/components/Script.hpp
@@ -16,24 +16,41 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef IDLEFUNC_HPP_
-#define IDLEFUNC_HPP_
+#ifndef SCRIPT_COMPONENT_HPP_
+#define SCRIPT_COMPONENT_HPP_
#include <components/Component.hpp>
-struct IdleFunc : Component<IdleFunc>, entityx::Component<IdleFunc>
+struct Scripted : Component<Scripted>, entityx::Component<Scripted>
{
- sol::function luafunc;
public:
- IdleFunc() {}
+ sol::table caller;
+ Scripted() {}
+ Scripted(sol::table call): caller(call) {}
- IdleFunc FromLua(sol::object ref)
+
+ ~Scripted()
+ {}
+
+ void cleanup()
{
- if (ref.get_type() == sol::type::function) {
- this->luafunc = ref;
- }
+ caller = sol::nil;
+ }
+
+ Scripted FromLua(sol::object)
+ {
+ //if (ref.get_type() == sol::type::function) {
+ // this->luafunc = ref;
+ //}
+ //init = true;
return *this;
}
+
+ void exec() {
+ if (caller["Idle"] == sol::type::function)
+ caller["Idle"](caller); // Call idle function and pass itself
+ // in or to fulfill the 'self' param
+ }
};
-#endif//IDLEFUNC_HPP_
+#endif//SCRIPT_COMPONENT_HPP_