Skip to content

Commit 496f5af

Browse files
committed
Add test for passing non-const ref param
1 parent b270a19 commit 496f5af

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/test_module.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ class TestBaseType
3434
int mdarray[2][3][5];
3535
std::function<int (int)> func_member;
3636

37+
void set_string_val(std::string &t_str)
38+
{
39+
t_str = "42";
40+
}
41+
3742
private:
3843
TestBaseType &operator=(const TestBaseType &) = delete;
3944
};
@@ -52,6 +57,7 @@ class Type2
5257
return m_bt.val;
5358
}
5459

60+
5561
const char *get_str() const
5662
{
5763
return m_str.c_str();
@@ -171,6 +177,7 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_test_mo
171177
m->add(chaiscript::fun(&TestBaseType::val), "val");
172178
m->add(chaiscript::fun(&TestBaseType::const_val), "const_val");
173179
m->add(chaiscript::fun(&TestBaseType::base_only_func), "base_only_func");
180+
m->add(chaiscript::fun(&TestBaseType::set_string_val), "set_string_val");
174181

175182
#ifndef CHAISCRIPT_MSVC_12
176183
// we cannot support these in MSVC_12 because of a bug in the implementation of

unittests/non_const_param.chai

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
load_module("test_module")
2+
3+
var t2 = TestBaseType();
4+
5+
var s = "5";
6+
t2.set_string_val(s);
7+
assert_equal(s, "42")
8+

0 commit comments

Comments
 (0)