Skip to content

Commit 0e4362a

Browse files
committed
add test for addProperty by external function
1 parent 77da776 commit 0e4362a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/test_02_classreg.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,4 +1401,26 @@ KAGUYA_TEST_FUNCTION_DEF(self_refcounted_object)(kaguya::State& )
14011401

14021402
}
14031403

1404+
int Base_a_getter(const Base* self)
1405+
{
1406+
return self->a;
1407+
}
1408+
void Base_a_setter(Base* self,int v)
1409+
{
1410+
self->a = v;
1411+
}
1412+
KAGUYA_TEST_FUNCTION_DEF(add_property_external)(kaguya::State& state)
1413+
{
1414+
1415+
state["Base"].setClass(kaguya::UserdataMetatable<Base>()
1416+
.setConstructors<Base()>()
1417+
.addProperty("a", &Base_a_getter,&Base_a_setter)
1418+
);
1419+
Base base;
1420+
state["base"] = &base;
1421+
TEST_CHECK(state("base.a=1"));
1422+
TEST_CHECK(state("assert(1 == base.a)"));
1423+
TEST_EQUAL(base.a, 1);
1424+
}
1425+
14041426
KAGUYA_TEST_GROUP_END(test_02_classreg)

0 commit comments

Comments
 (0)