File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -114,6 +114,16 @@ std::shared_ptr<TestBaseType> null_factory()
114114 return std::shared_ptr<TestBaseType>();
115115}
116116
117+ void update_shared_ptr (std::shared_ptr<TestBaseType> &ptr)
118+ {
119+ ptr = std::make_shared<TestDerivedType>();
120+ }
121+
122+ void nullify_shared_ptr (std::shared_ptr<TestBaseType> &ptr)
123+ {
124+ ptr = nullptr ;
125+ }
126+
117127std::string hello_world ()
118128{
119129 return " Hello World" ;
@@ -209,6 +219,10 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_test_mo
209219 m->add (chaiscript::type_conversion<const char *, std::string>());
210220 m->add (chaiscript::constructor<Type2 (const TestBaseType &)>(), " Type2" );
211221
222+ m->add (chaiscript::fun (&update_shared_ptr), " update_shared_ptr" );
223+ m->add (chaiscript::fun (&nullify_shared_ptr), " nullify_shared_ptr" );
224+
225+
212226 return m;
213227}
214228
Original file line number Diff line number Diff line change 1+ load_module("test_module")
2+
3+ auto o := null_factory();
4+
5+ assert_true(o.is_var_null());
6+
7+ update_shared_ptr(o);
8+
9+ assert_false(o.is_var_null());
10+ assert_true(o.base_only_func() == -9);
11+
12+ nullify_shared_ptr(o);
13+
14+ assert_true(o.is_var_null());
15+
16+ try {
17+ o.func();
18+ } catch (e) {
19+ exit(0);
20+ }
21+
22+ assert_true(false);
23+
24+
You can’t perform that action at this time.
0 commit comments