|
28 | 28 | #include <luabind/class_info.hpp>
|
29 | 29 | #include <luabind/detail/class_registry.hpp>
|
30 | 30 |
|
| 31 | +/* |
| 32 | +#include <iostream> |
| 33 | +#define VERBOSE(X) std::cout << __FILE__ << ":" << __LINE__ << ": " << X << std::endl |
| 34 | +*/ |
| 35 | +#define VERBOSE(X) |
| 36 | + |
31 | 37 | namespace luabind
|
32 | 38 | {
|
33 | 39 | LUABIND_API class_info get_class_info(argument const& o)
|
34 | 40 | {
|
35 | 41 | lua_State* L = o.interpreter();
|
| 42 | + detail::class_rep * crep = NULL; |
| 43 | + bool givenClassRep = false; |
36 | 44 |
|
37 | 45 | o.push(L);
|
38 |
| - detail::object_rep* obj = detail::get_instance(L, -1); |
39 |
| - |
40 |
| - if (!obj) |
41 |
| - { |
42 |
| - class_info result; |
43 |
| - result.name = lua_typename(L, lua_type(L, -1)); |
| 46 | + if (detail::is_class_rep(L, -1)) { |
| 47 | + VERBOSE("OK, got a class rep"); |
| 48 | + // OK, o is a class rep, now at the top of the stack |
| 49 | + givenClassRep = true; |
| 50 | + crep = static_cast<detail::class_rep *>(lua_touserdata(L, -1)); |
44 | 51 | lua_pop(L, 1);
|
45 |
| - result.methods = newtable(L); |
46 |
| - result.attributes = newtable(L); |
47 |
| - return result; |
48 |
| - } |
| 52 | + } else { |
49 | 53 |
|
50 |
| - lua_pop(L, 1); |
| 54 | + VERBOSE("Not a class rep"); |
| 55 | + detail::object_rep* obj = detail::get_instance(L, -1); |
51 | 56 |
|
52 |
| - obj->crep()->get_table(L); |
| 57 | + if (!obj) |
| 58 | + { |
| 59 | + VERBOSE("Not a obj rep"); |
| 60 | + class_info result; |
| 61 | + result.name = lua_typename(L, lua_type(L, -1)); |
| 62 | + lua_pop(L, 1); |
| 63 | + result.methods = newtable(L); |
| 64 | + result.attributes = newtable(L); |
| 65 | + return result; |
| 66 | + } else { |
| 67 | + lua_pop(L, 1); |
| 68 | + // OK, we were given an object - gotta get the crep. |
| 69 | + crep = obj->crep(); |
| 70 | + } |
| 71 | + } |
| 72 | + crep->get_table(L); |
53 | 73 | object table(from_stack(L, -1));
|
54 | 74 | lua_pop(L, 1);
|
55 | 75 |
|
56 | 76 | class_info result;
|
57 |
| - result.name = obj->crep()->name(); |
| 77 | + result.name = crep->name(); |
58 | 78 | result.methods = newtable(L);
|
59 | 79 | result.attributes = newtable(L);
|
60 | 80 |
|
|
0 commit comments