mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Fix formatting on tests file
This commit is contained in:
parent
63bc2b06cb
commit
b6c2f1c6d5
68
tests.cpp
68
tests.cpp
|
@ -8,50 +8,41 @@ std::string free_function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct object {
|
struct object {
|
||||||
|
|
||||||
std::string operator() () {
|
std::string operator() () {
|
||||||
std::cout << "member_test()" << std::endl;
|
std::cout << "member_test()" << std::endl;
|
||||||
return "test";
|
return "test";
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct fuser {
|
struct fuser {
|
||||||
int x;
|
int x;
|
||||||
|
fuser() : x(0) {}
|
||||||
|
|
||||||
fuser( ) : x( 0 ) {
|
fuser(int x) : x(x) {}
|
||||||
|
|
||||||
}
|
int add(int y) {
|
||||||
|
|
||||||
fuser( int x ) : x( x ) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int add( int y ) {
|
|
||||||
return x + y;
|
return x + y;
|
||||||
}
|
}
|
||||||
|
|
||||||
int add2( int y ) {
|
int add2(int y) {
|
||||||
return x + y + 2;
|
return x + y + 2;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace crapola {
|
namespace crapola {
|
||||||
struct fuser {
|
struct fuser {
|
||||||
int x;
|
int x;
|
||||||
fuser( ) : x( 0 ) {
|
fuser() : x(0) {}
|
||||||
}
|
fuser(int x) : x(x) {}
|
||||||
fuser( int x ) : x( x ) {
|
fuser(int x, int x2) : x(x * x2) {}
|
||||||
}
|
|
||||||
fuser( int x, int x2 ) : x( x * x2 ) {
|
int add(int y) {
|
||||||
}
|
return x + y;
|
||||||
int add( int y ) {
|
}
|
||||||
return x + y;
|
int add2(int y) {
|
||||||
}
|
return x + y + 2;
|
||||||
int add2( int y ) {
|
}
|
||||||
return x + y + 2;
|
};
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int plop_xyz(int x, int y, std::string z) {
|
int plop_xyz(int x, int y, std::string z) {
|
||||||
|
@ -368,11 +359,11 @@ TEST_CASE("tables/userdata", "Show that we can create classes from userdata and
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
|
|
||||||
sol::userdata<fuser> lc{ &fuser::add, "add", &fuser::add2, "add2" };
|
sol::userdata<fuser> lc{ &fuser::add, "add", &fuser::add2, "add2" };
|
||||||
lua.set_class( lc );
|
lua.set_class(lc);
|
||||||
|
|
||||||
lua.script("a = fuser:new()\n"
|
lua.script("a = fuser:new()\n"
|
||||||
"b = a:add(1)\n"
|
"b = a:add(1)\n"
|
||||||
"c = a:add2(1)\n");
|
"c = a:add2(1)\n");
|
||||||
|
|
||||||
sol::object a = lua.get<sol::object>("a");
|
sol::object a = lua.get<sol::object>("a");
|
||||||
sol::object b = lua.get<sol::object>("b");
|
sol::object b = lua.get<sol::object>("b");
|
||||||
|
@ -399,16 +390,15 @@ TEST_CASE("tables/userdata constructors", "Show that we can create classes from
|
||||||
lua.set_class(lc);
|
lua.set_class(lc);
|
||||||
|
|
||||||
lua.script(
|
lua.script(
|
||||||
"a = crapola_fuser.new(2)\n"
|
"a = crapola_fuser.new(2)\n"
|
||||||
"u = a:add(1)\n"
|
"u = a:add(1)\n"
|
||||||
"v = a:add2(1)\n"
|
"v = a:add2(1)\n"
|
||||||
"b = crapola_fuser:new()\n"
|
"b = crapola_fuser:new()\n"
|
||||||
"w = b:add(1)\n"
|
"w = b:add(1)\n"
|
||||||
"x = b:add2(1)\n"
|
"x = b:add2(1)\n"
|
||||||
"c = crapola_fuser.new(2, 3)\n"
|
"c = crapola_fuser.new(2, 3)\n"
|
||||||
"y = c:add(1)\n"
|
"y = c:add(1)\n"
|
||||||
"z = c:add2(1)\n"
|
"z = c:add2(1)\n");
|
||||||
);
|
|
||||||
sol::object a = lua.get<sol::object>("a");
|
sol::object a = lua.get<sol::object>("a");
|
||||||
auto atype = a.get_type();
|
auto atype = a.get_type();
|
||||||
REQUIRE((atype == sol::type::userdata));
|
REQUIRE((atype == sol::type::userdata));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user