type check

This commit is contained in:
Bluub
2021-06-09 14:53:41 +02:00
parent 41ff375d6a
commit 5f7bcf2a8f
4 changed files with 26 additions and 10 deletions
+7 -1
View File
@@ -2,7 +2,13 @@ function Sum(a,b)
return a + b;
end
function Update(info)
function Update(infos)
for i, info in ipairs(infos) do
print (info.x);
print (info.y);
print (info.z);
print (info.type);
end
return 1, 1, false, false;
--return info.x, info.y, (info.z ~= 1), (info.type ~= 0);
end
+4
View File
@@ -10,6 +10,10 @@ namespace BBM
: x(pos.x), y(pos.y), z(pos.z), type(type)
{ }
MapInfo::MapInfo(const MapInfo &other)
: x(other.x), y(other.y), z(other.z), type(other.type)
{ }
MapInfo &MapInfo::operator=(MapInfo &other)
{
this->x = other.x;
+2 -2
View File
@@ -20,7 +20,7 @@ namespace BBM
float z;
//! @brief Type of the block
MapGenerator::BlockType type;
int type;
//! @brief Constructor
MapInfo(Vector3f pos, MapGenerator::BlockType type);
@@ -29,7 +29,7 @@ namespace BBM
~MapInfo() = default;
//! @brief Default copy constructor
MapInfo(MapInfo &) = default;
MapInfo(const MapInfo &);
//! @brief Assignment operator
MapInfo &operator=(MapInfo &);
@@ -6,6 +6,8 @@
#include "Component/Controllable/ControllableComponent.hpp"
#include "Component/IAControllable/IAControllableComponent.hpp"
#include "System/IAControllable/IAControllableSystem.hpp"
#include <vector>
#include <string>
namespace BBM
{
@@ -44,18 +46,22 @@ namespace BBM
{
auto &ia = entity.get<IAControllableComponent>();
auto &controllable = entity.get<ControllableComponent>();
MapInfo info({1, 2, 3}, MapGenerator::NOTHING);
std::vector<MapInfo> infos;
luabridge::LuaRef updateFunc = luabridge::getGlobal(ia.state, "Update");
if (!updateFunc.isFunction())
return;
luabridge::LuaResult res = updateFunc(info);
return;
luabridge::LuaResult res = updateFunc(infos);
if (res.hasFailed() || res.size() != 4)
return;
controllable.bomb = res[3];
controllable.jump = res[2];
controllable.move.y = res[1];
controllable.move.x = res[0];
if (res[3].isBool())
controllable.bomb = res[3];
if (res[2].isBool())
controllable.jump = res[2];
if (res[1].isNumber())
controllable.move.y = res[1];
if (res[0].isNumber())
controllable.move.x = res[0];
}
}