24 m_internal
.name_
= "internal name";
32 void set(int a
) { a_
= a
; feedback
= a
; }
33 int get() const { feedback
= a_
; return a_
; }
35 void set_name(const char* name
) { name_
= name
; str
= name
; feedback
= 0; }
36 const char* get_name() const { return name_
.c_str(); }
38 const internal
& get_internal() const { return m_internal
; }
41 int tester(lua_State
* L
)
43 if (!lua_isnumber(L
, 1))
46 if (lua_isstring(L
, 1))
48 str
= lua_tostring(L
, 1);
53 feedback
= static_cast<int>(lua_tonumber(L
, 1));
57 } // anonymous namespace
59 bool test_attributes()
61 using namespace luabind
;
63 lua_State
* L
= lua_open();
66 int top
= lua_gettop(L
);
70 lua_pushstring(L
, "tester");
71 lua_pushcfunction(L
, tester
);
72 lua_settable(L
, LUA_GLOBALSINDEX
);
74 class_
<internal
>(L
, "internal")
75 .def_readonly("name", &internal::name_
)
78 class_
<property_test
>(L
, "property")
80 .def("get", &property_test::get
)
81 .def("get_name", &property_test::get_name
)
82 .property("a", &property_test::get
, &property_test::set
)
83 .property("name", &property_test::get_name
, &property_test::set_name
)
84 .def_readonly("o", &property_test::o
)
86 .property("internal", &property_test::get_internal
, dependency(result
, self
))
90 if (dostring(L
, "test = property()")) return false;
91 if (dostring(L
, "test.a = 5")) return false;
92 if (feedback
!= 5) return false;
94 if (dostring(L
, "test.name = 'Dew'")) return false;
95 if (dostring(L
, "tester(test.name)")) return false;
96 if (feedback
!= 0) return false;
97 if (str
!= "Dew") return false;
99 if (dostring(L
, "function d(x) end d(test.a)")) return false;
100 if (feedback
!= 5) return false;
102 if (dostring(L
, "test.name = 'red brigade | mango'")) return false;
103 if (feedback
!= 0) return false;
104 if (str
!= "red brigade | mango") return false;
106 if (dostring(L
, "tester(test.o)")) return false;
107 if (feedback
!= 6) return false;
109 // TODO: this test should be moved to a section for testing error messages
110 if (dostring2(L
, "test.o = 5") != 1) return false;
111 if (std::string("cannot set attribute 'property.o'") != lua_tostring(L
, -1)) return false;
114 if (dostring(L
, "tester(test.name)")) return false;
115 if (feedback
!= 0) return false;
116 if (str
!= "red brigade | mango") return false;
118 if (top
!= lua_gettop(L
)) return false;
120 dostring(L
, "a = property()");
122 dostring(L
, "b = a.internal");
124 dostring(L
, "a = nil");
125 dostring(L
, "collectgarbage(0)");
126 dostring(L
, "collectgarbage(0)");
128 dostring(L
, "print(b.name)");