Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
peacalm committed Jun 27, 2023
1 parent 863ac1f commit 9677c7b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/unit_test/set_and_get.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,11 @@ struct Callable {
}
};

template <typename T>
T tadd(T a, T b) {
return a + b;
}

TEST(set_and_get, set_function) {
luaw l;

Expand All @@ -567,6 +572,15 @@ TEST(set_and_get, set_function) {
EXPECT_EQ(l.gettop(), 0);
}

// C++ template function
{
l.set("tadd", tadd<int>);
EXPECT_EQ(l.eval_int("return tadd(1, 1)"), 2);

l.set<double(double, double)>("tadd2", tadd);
EXPECT_EQ(l.eval_int("return tadd2(1.5, 1.5)"), 3);
}

// std::function
{
std::function<int(int, int)> fadd = [](int a, int b) { return a + b; };
Expand Down

0 comments on commit 9677c7b

Please sign in to comment.