Added codegen to register components, and started reworking lua

This commit is contained in:
2019-06-07 15:52:57 +02:00
parent 53a0b98341
commit 7ff9e21b4d
14 changed files with 381 additions and 110 deletions

View File

@@ -4,20 +4,22 @@
#include "ecs.h"
#include <iostream>
#include <utility>
namespace ecs::lua {
struct LuaWrapper : Component {
LuaWrapper(sol::object _object) : object(_object) {}
LuaWrapper() {}
struct Wrapper : Component {
Wrapper(std::string _name, sol::table _table) : name(_name), table(_table) {}
Wrapper() {}
sol::object object;
std::string name;
sol::table table;
};
template <typename T, typename... Constructor, typename... Args>
void register_component(sol::state& lua, sol::table& table, Args... args) {
table.new_usertype<T>(get_typename<T>(),
"new", sol::factories([](Constructor... constructor) {
return new T(constructor...);
return std::make_pair(new T(constructor...), get_typename<T>());
}), args...
);
lua.set_function("_internal_to_" + get_typename<T>(), [] (Component* component) {