-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
69 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "UnitTest.hh" | ||
#include "nua/nua.hh" | ||
|
||
TEST_CASE(const_string_reference) | ||
{ | ||
nua::Context ctx; | ||
ctx["test"] = [](const std::string& s) { TEST_CHECK(s == "nua"); }; | ||
ctx["test"]("nua"); | ||
} | ||
|
||
TEST_CASE(const_function_reference) | ||
{ | ||
nua::Context ctx; | ||
|
||
ctx["take_fun_arg"] = [](const nua::function<int(int, int)>& func, int a, int b) | ||
{ | ||
return func(a, b); | ||
}; | ||
|
||
ctx(R"( | ||
function add(a, b) | ||
return a + b | ||
end | ||
function pass_add(x, y) | ||
return take_fun_arg(add, x, y) | ||
end | ||
)"); | ||
|
||
TEST_CHECK(ctx["pass_add"](3, 5).get<int>() == 8); | ||
} | ||
|
||
TEST_CASE(const_number_reference) | ||
{ | ||
nua::Context ctx; | ||
ctx["test_int"] = [](const int& v) { TEST_CHECK(v == 47); }; | ||
ctx["test_int"](47); | ||
ctx["test_long"] = [](const long& v) { TEST_CHECK(v == 233); }; | ||
ctx["test_long"](233); | ||
ctx["test_float"] = [](const float& v) { TEST_CHECK(v == 2.5); }; | ||
ctx["test_float"](2.5); | ||
ctx["test_double"] = [](const double& v) { TEST_CHECK(v == 3.14159); }; | ||
ctx["test_double"](3.14159); | ||
} | ||
|
||
TEST_CASE(const_nullptr_type) | ||
{ | ||
nua::Context ctx; | ||
ctx["test"] = [](const std::nullptr_t& v) { TEST_CHECK(v == nullptr); }; | ||
ctx["test"](nullptr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,2 @@ | ||
#define TEST_MAIN | ||
#include "UnitTest.hh" | ||
#include "nua/nua.hh" | ||
|
||
TEST_CASE(test) | ||
{ | ||
nua::Context st{true}; | ||
struct Obj2 | ||
{ void print() { std::cout << "obj2" << std::endl; } }; | ||
struct Obj | ||
{ | ||
Obj2& get_obj2() | ||
{return obj2; } | ||
void print() | ||
{ std::cout << "obj1" << std::endl; } | ||
Obj2 obj2; | ||
}; | ||
|
||
st.setClass<Obj>("obj2", &Obj::get_obj2, "print", &Obj::print); | ||
st.setClass<Obj2>("print", &Obj2::print); | ||
st(R"( | ||
function test(cpp_obj) | ||
cpp_obj:print() | ||
local cpp_obj2 = cpp_obj:obj2() | ||
cpp_obj:print() | ||
cpp_obj2:print() | ||
end | ||
)"); | ||
Obj o; | ||
st["test"](o); | ||
} |