MCPcopy Index your code
hub / github.com/yuin/gopher-lua / getField

Method getField

state.go:1276–1305  ·  view source on GitHub ↗
(obj LValue, key LValue)

Source from the content-addressed store, hash-verified

1274}
1275
1276func (ls *LState) getField(obj LValue, key LValue) LValue {
1277 curobj := obj
1278 for i := 0; i < MaxTableGetLoop; i++ {
1279 tb, istable := curobj.(*LTable)
1280 if istable {
1281 ret := tb.RawGet(key)
1282 if ret != LNil {
1283 return ret
1284 }
1285 }
1286 metaindex := ls.metaOp1(curobj, "__index")
1287 if metaindex == LNil {
1288 if !istable {
1289 ls.RaiseError("attempt to index a non-table object(%v) with key '%s'", curobj.Type().String(), key.String())
1290 }
1291 return LNil
1292 }
1293 if metaindex.Type() == LTFunction {
1294 ls.reg.Push(metaindex)
1295 ls.reg.Push(curobj)
1296 ls.reg.Push(key)
1297 ls.Call(2, 1)
1298 return ls.reg.Pop()
1299 } else {
1300 curobj = metaindex
1301 }
1302 }
1303 ls.RaiseError("too many recursions in gettable")
1304 return nil
1305}
1306
1307func (ls *LState) getFieldString(obj LValue, key string) LValue {
1308 curobj := obj

Callers 3

GetTableMethod · 0.95
initFunction · 0.45
initFunction · 0.45

Calls 8

metaOp1Method · 0.95
RaiseErrorMethod · 0.95
CallMethod · 0.95
StringMethod · 0.65
TypeMethod · 0.65
PushMethod · 0.65
PopMethod · 0.65
RawGetMethod · 0.45

Tested by

no test coverage detected