test register on component

This commit is contained in:
Bluub
2021-06-17 18:20:37 +02:00
parent 6bfcac515f
commit 8914579fd7
2 changed files with 19 additions and 2 deletions
@@ -11,11 +11,25 @@
namespace BBM
{
IAControllableComponent::IAControllableComponent(WAL::Entity &entity, std::string scriptPath)
: Component(entity), _scriptPath(scriptPath), _state()
auto a = [](lua_State *L) -> int
{
const int *pThis = (const int*) lua_topointer(L, lua_upvalueindex(1));
//const float x = lua_tonumber(state, -1);
std::cout << *pThis;
return 0;
};
IAControllableComponent::IAControllableComponent(WAL::Entity &entity, std::string scriptPath)
: Component(entity), _scriptPath(scriptPath), _state(), registered(false)
{
static int x = 1;
lua_pushlightuserdata(_state.getState(), &x);
//lua_pushnumber(state, x);
lua_pushcclosure(_state.getState(), a, 1);
lua_setglobal(_state.getState(), "a");
x++;
if (std::filesystem::exists(scriptPath))
_state.dofile(scriptPath);
}
WAL::Component *IAControllableComponent::clone(WAL::Entity &entity) const
@@ -22,6 +22,9 @@ namespace BBM
const std::string _scriptPath;
public:
//! @brief Is the binding registered
bool registered;
//! @brief LuaGate state
LuaG::State _state;