31 lines
676 B
C++
31 lines
676 B
C++
#pragma once
|
|
|
|
#include "sol.hpp"
|
|
#include "ecs.h"
|
|
|
|
#include <iostream>
|
|
|
|
namespace ecs::lua {
|
|
struct LuaWrapper : Component {
|
|
LuaWrapper(sol::object _object) : object(_object) {}
|
|
LuaWrapper() {}
|
|
|
|
sol::object object;
|
|
};
|
|
|
|
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...);
|
|
}), args...
|
|
);
|
|
lua.set_function("_internal_to_" + get_typename<T>(), [] (Component* component) {
|
|
return (T*)component;
|
|
});
|
|
}
|
|
|
|
void init(sol::state& lua);
|
|
}
|
|
|