mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Fixed tests spacing
This commit is contained in:
parent
d548fdaee8
commit
5930818891
67
tests.cpp
67
tests.cpp
|
@ -636,11 +636,11 @@ TEST_CASE("tables/issue-number-twenty-five", "Using pointers and references from
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
test* pget() {
|
test* pget() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
test create_get() {
|
test create_get() {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -665,42 +665,41 @@ TEST_CASE("tables/issue-number-twenty-five", "Using pointers and references from
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("userdata/issue-number-thirty-five", "using value types created from lua-called C++ code, fixing user-defined types with constructors") {
|
TEST_CASE("userdata/issue-number-thirty-five", "using value types created from lua-called C++ code, fixing user-defined types with constructors") {
|
||||||
struct Vec {
|
struct Vec {
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
Vec(float x, float y, float z) : x{x}, y{y}, z{z} {}
|
Vec(float x, float y, float z) : x{x}, y{y}, z{z} {}
|
||||||
float length() {
|
float length() {
|
||||||
return sqrtf(x*x + y*y + z*z);
|
return sqrtf(x*x + y*y + z*z);
|
||||||
}
|
}
|
||||||
Vec normalized() {
|
|
||||||
float invS = 1 / length();
|
|
||||||
return {x * invS, y * invS, z * invS};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Line {
|
Vec normalized() {
|
||||||
Vec p1, p2;
|
float invS = 1 / length();
|
||||||
Line() : p1{0, 0, 0}, p2{0, 0, 0} {}
|
return {x * invS, y * invS, z * invS};
|
||||||
Line(float x) : p1{x, x, x}, p2{x, x, x} {}
|
}
|
||||||
Line(const Vec& p1) : p1{p1}, p2{p1} {}
|
};
|
||||||
Line(Vec p1, Vec p2) : p1{p1}, p2{p2} {}
|
|
||||||
};
|
|
||||||
|
|
||||||
sol::state lua;
|
struct Line {
|
||||||
lua.open_libraries(sol::lib::base);
|
Vec p1, p2;
|
||||||
|
Line() : p1{0, 0, 0}, p2{0, 0, 0} {}
|
||||||
|
Line(float x) : p1{x, x, x}, p2{x, x, x} {}
|
||||||
|
Line(const Vec& p1) : p1{p1}, p2{p1} {}
|
||||||
|
Line(Vec p1, Vec p2) : p1{p1}, p2{p2} {}
|
||||||
|
};
|
||||||
|
|
||||||
sol::constructors<sol::types<>, sol::types<Vec>, sol::types<Vec, Vec>> lctor;
|
sol::state lua;
|
||||||
sol::userdata<Line> ludata("Line", lctor);
|
lua.open_libraries(sol::lib::base);
|
||||||
lua.set_userdata(ludata);
|
|
||||||
|
|
||||||
sol::constructors<sol::types<float, float, float>> ctor;
|
sol::constructors<sol::types<>, sol::types<Vec>, sol::types<Vec, Vec>> lctor;
|
||||||
sol::userdata<Vec> udata("Vec", ctor,
|
sol::userdata<Line> ludata("Line", lctor);
|
||||||
"normalized", &Vec::normalized,
|
lua.set_userdata(ludata);
|
||||||
"length", &Vec::length);
|
|
||||||
|
|
||||||
lua.set_userdata(udata);
|
sol::constructors<sol::types<float, float, float>> ctor;
|
||||||
|
sol::userdata<Vec> udata("Vec", ctor, "normalized", &Vec::normalized, "length", &Vec::length);
|
||||||
|
|
||||||
REQUIRE_NOTHROW(lua.script("v = Vec.new(1, 2, 3)\n"
|
lua.set_userdata(udata);
|
||||||
"print(v:length())"));
|
|
||||||
REQUIRE_NOTHROW(lua.script("v = Vec.new(1, 2, 3)\n"
|
REQUIRE_NOTHROW(lua.script("v = Vec.new(1, 2, 3)\n"
|
||||||
"print(v:normalized():length())" ));
|
"print(v:length())"));
|
||||||
|
REQUIRE_NOTHROW(lua.script("v = Vec.new(1, 2, 3)\n"
|
||||||
|
"print(v:normalized():length())" ));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user