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

Method gettable

ogsr_engine/Luabind/src/class_rep.cpp:189–267  ·  view source on GitHub ↗

lua stack: userdata, key

Source from the content-addressed store, hash-verified

187
188// lua stack: userdata, key
189int luabind::detail::class_rep::gettable(lua_State* L)
190{
191 // if key is nil, return nil
192 if (lua_isnil(L, 2))
193 {
194 lua_pushnil(L);
195 return 1;
196 }
197
198 object_rep* obj = static_cast<object_rep*>(lua_touserdata(L, 1));
199
200 // we have to ignore the first argument since this may point to
201 // a method that is not present in this class (but in a subclass)
202 const char* key = lua_tostring(L, 2);
203
204#ifndef LUABIND_NO_ERROR_CHECKING
205
206 if (std::strlen(key) != lua_strlen(L, 2))
207 {
208 {
209 string_class msg("luabind does not support "
210 "member names with extra nulls:\n");
211 msg += string_class(lua_tostring(L, 2), lua_strlen(L, 2));
212 lua_pushstring(L, msg.c_str());
213 }
214 lua_error(L);
215 }
216
217#endif
218
219 // special case to see if this is a null-pointer
220 if (key && !std::strcmp(key, "__ok"))
221 {
222 class_rep* crep = obj->crep();
223
224 void* p = crep->extractor() ? crep->extractor()(obj->ptr())
225 : obj->ptr();
226
227 lua_pushboolean(L, p != 0);
228 return 1;
229 }
230
231// First, look in the instance's table
232 detail::lua_reference const& tbl = obj->get_lua_table();
233 if (tbl.is_valid())
234 {
235 tbl.get(L);
236 lua_pushvalue(L, 2);
237 lua_gettable(L, -2);
238 if (!lua_isnil(L, -1))
239 {
240 lua_remove(L, -2); // more table
241 return 1;
242 }
243 lua_pop(L, 2);
244 }
245
246// Then look in the class' table for this member

Callers 1

gettable_dispatcherMethod · 0.80

Calls 13

lua_pushnilFunction · 0.50
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
c_strMethod · 0.45
is_validMethod · 0.45
getMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected