Experiments in using Lua with sol2 and how best to structure the data. Contains a shoot out of SOA, vs AOS vs. MOA. SOA = Struct of Arrays AOS = Array of Structs MOA = Many Array of Structs (kind of a hybrid)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
sol2_test/tests/bao_tests.cpp

50 lines
1016 B

#include <fmt/core.h>
#include <deque>
#include <string>
#include <fuc2/testing.hpp>
#define SOL_ALL_SAFETIES_ON 1
#include <sol/sol.hpp>
using namespace fuc2;
namespace bao_tests {
struct BAEntity {
std::string name;
int hp=0;
int damage=0;
bool dead=false;
};
void test_bao_basics() {
std::vector<BAEntity> entities;
for(int i = 0; i < 10; i++) {
auto name = fmt::format("Fighter-{}", i);
entities.emplace_back(name, i+10, i+1);
}
sol::state lua;
lua.open_libraries(sol::lib::base);
lua.new_usertype<BAEntity>("BAEntity",
"name", &BAEntity::name,
"hp", &BAEntity::hp,
"damage", &BAEntity::damage,
"dead", &BAEntity::dead);
lua.script_file("tests/bao_tests.lua");
sol::function handler = lua["handler"];
for(auto& fighter : entities) {
handler(fighter);
}
}
fuc2::Set TESTS{
.name="bao",
.options={ .fail_fast=false },
.tests={
TEST(test_bao_basics),
}
};
}