MCPcopy Create free account
hub / github.com/OGSR/OGSR-Engine / lua_class_gettable

Method lua_class_gettable

ogsr_engine/Luabind/src/class_rep.cpp:1083–1156  ·  view source on GitHub ↗

called from the metamethod for __index obj is the object pointer

Source from the content-addressed store, hash-verified

1081// called from the metamethod for __index
1082// obj is the object pointer
1083int 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

Callers

nothing calls this directly

Calls 13

flagsMethod · 0.80
lua_touserdataFunction · 0.50
lua_pushstringFunction · 0.50
lua_errorFunction · 0.50
lua_pushbooleanFunction · 0.50
lua_pushvalueFunction · 0.50
lua_gettableFunction · 0.50
lua_removeFunction · 0.50
lua_pushnilFunction · 0.50
is_validMethod · 0.45
getMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected