called from the metamethod for __index obj is the object pointer
| 1081 | // called from the metamethod for __index |
| 1082 | // obj is the object pointer |
| 1083 | int luabind::detail::class_rep::lua_class_gettable(lua_State* L) |
| 1084 | { |
| 1085 | object_rep* obj = static_cast<object_rep*>(lua_touserdata(L, 1)); |
| 1086 | class_rep* crep = obj->crep(); |
| 1087 | |
| 1088 | #ifndef LUABIND_NO_ERROR_CHECKING |
| 1089 | |
| 1090 | if (obj->flags() & object_rep::call_super) |
| 1091 | { |
| 1092 | lua_pushstring(L, "derived class must call super on base"); |
| 1093 | lua_error(L); |
| 1094 | } |
| 1095 | |
| 1096 | #endif |
| 1097 | |
| 1098 | // we have to ignore the first argument since this may point to |
| 1099 | // a method that is not present in this class (but in a subclass) |
| 1100 | |
| 1101 | // BUG: This might catch members called "__ok\0foobar" |
| 1102 | const char* key = lua_tostring(L, 2); |
| 1103 | |
| 1104 | if (key && !std::strcmp(key, "__ok")) |
| 1105 | { |
| 1106 | class_rep* crep = obj->crep(); |
| 1107 | |
| 1108 | void* p = crep->extractor() ? crep->extractor()(obj->ptr()) |
| 1109 | : obj->ptr(); |
| 1110 | |
| 1111 | lua_pushboolean(L, p != 0); |
| 1112 | return 1; |
| 1113 | } |
| 1114 | |
| 1115 | // first look in the instance's table |
| 1116 | detail::lua_reference const& tbl = obj->get_lua_table(); |
| 1117 | assert(tbl.is_valid()); |
| 1118 | tbl.get(L); |
| 1119 | lua_pushvalue(L, 2); |
| 1120 | lua_gettable(L, -2); |
| 1121 | if (!lua_isnil(L, -1)) |
| 1122 | { |
| 1123 | lua_remove(L, -2); // remove table |
| 1124 | return 1; |
| 1125 | } |
| 1126 | lua_pop(L, 2); |
| 1127 | |
| 1128 | // then look in the class' table |
| 1129 | crep->get_table(L); |
| 1130 | lua_pushvalue(L, 2); |
| 1131 | lua_gettable(L, -2); |
| 1132 | |
| 1133 | if (!lua_isnil(L, -1)) |
| 1134 | { |
| 1135 | lua_remove(L, -2); // more table |
| 1136 | return 1; |
| 1137 | } |
| 1138 | |
| 1139 | lua_pop(L, 2); |
| 1140 |
nothing calls this directly
no test coverage detected