New example.

This commit is contained in:
ThePhD 2020-01-28 14:01:34 -05:00
parent 11d6e8c8d4
commit 5d7d1329fa
No known key found for this signature in database
GPG Key ID: 1509DB1C0F702BFA
2 changed files with 35 additions and 4 deletions

View File

@ -0,0 +1,33 @@
#define SOL_ALL_SAFETIES_ON 1
#include <sol/sol.hpp>
#include "assert.hpp"
struct Vector {
int x;
int y;
Vector() = default;
Vector(int _x, int _y) : x { _x }, y { _y } {
}
};
int main() {
sol::state lua;
lua.open_libraries(sol::lib::base);
lua.new_usertype<Vector>(
"Vector", sol::constructors<Vector(), Vector(int, int)>(), "x", sol::property(&Vector::x, &Vector::x), "y", sol::property(&Vector::y, &Vector::y));
lua.script("vectors = { Vector.new(3, 6), Vector.new(6, 3) }");
auto vectors = lua["vectors"].get<std::vector<Vector>>();
c_assert(vectors[0].x == 3);
c_assert(vectors[0].y == 6);
c_assert(vectors[1].x == 6);
c_assert(vectors[1].y == 3);
return 0;
}

View File

@ -3,8 +3,6 @@
#include "assert.hpp" #include "assert.hpp"
#include <iostream>
int main() { int main() {
const auto& code = R"( const auto& code = R"(