LUABIND_API class_info get_class_info(argument const& o) { lua_State* L = o.interpreter(); o.push(L); detail::object_rep* obj = detail::get_instance(L, -1); if (!obj) { class_info result; result.name = lua_typename(L, lua_type(L, -1)); lua_pop(L, 1); result.methods = newtable(L); result.attributes = newtable(L); return result; } lua_pop(L, 1); obj->crep()->get_table(L); object table(from_stack(L, -1)); lua_pop(L, 1); class_info result; result.name = obj->crep()->name(); result.methods = newtable(L); result.attributes = newtable(L); std::size_t index = 1; for (iterator i(table), e; i != e; ++i) { if (type(*i) != LUA_TFUNCTION) continue; // We have to create a temporary `object` here, otherwise the proxy // returned by operator->() will mess up the stack. This is a known // problem that probably doesn't show up in real code very often. object member(*i); member.push(L); detail::stack_pop pop(L, 1); if (lua_tocfunction(L, -1) == &detail::property_tag) { result.attributes[index++] = i.key(); } else { result.methods[i.key()] = *i; } } return result; }