test_class_info.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright Daniel Wallin 2009. Use, modification and distribution is
  2. // subject to the Boost Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #include "test.hpp"
  5. #include <luabind/luabind.hpp>
  6. #include <luabind/class_info.hpp>
  7. struct X
  8. {
  9. void f()
  10. {}
  11. int x;
  12. int y;
  13. };
  14. void test_main(lua_State* L)
  15. {
  16. using namespace luabind;
  17. bind_class_info(L);
  18. module(L) [
  19. class_<X>("X")
  20. .def(constructor<>())
  21. .def("f", &X::f)
  22. .def_readonly("x", &X::x)
  23. .def_readonly("y", &X::y)
  24. ];
  25. DOSTRING(L,
  26. "x = X()\n"
  27. "info = class_info(x)\n"
  28. "assert(info.name == 'X')\n"
  29. "assert(info.methods['f'] == x.f)\n"
  30. "assert(info.methods['__init'] == x.__init)\n"
  31. "assert(info.attributes[1] == 'y')\n"
  32. "assert(info.attributes[2] == 'x')\n"
  33. "info = class_info(2)\n"
  34. "assert(info.name == 'number')\n"
  35. "assert(#info.methods == 0)\n"
  36. "assert(#info.attributes == 0)\n"
  37. "names = class_names()\n"
  38. "assert(type(names) == 'table')\n"
  39. "assert(#names == 2)\n"
  40. "assert(names[1] == 'X' or names[2] == 'X')\n"
  41. "assert(names[1] == 'class_info_data' or names[2] == 'class_info_data')\n"
  42. );
  43. }