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

Method getFieldString

state.go:1307–1336  ·  view source on GitHub ↗
(obj LValue, key string)

Source from the content-addressed store, hash-verified

1305}
1306
1307func (ls *LState) getFieldString(obj LValue, key string) LValue {
1308 curobj := obj
1309 for i := 0; i < MaxTableGetLoop; i++ {
1310 tb, istable := curobj.(*LTable)
1311 if istable {
1312 ret := tb.RawGetString(key)
1313 if ret != LNil {
1314 return ret
1315 }
1316 }
1317 metaindex := ls.metaOp1(curobj, "__index")
1318 if metaindex == LNil {
1319 if !istable {
1320 ls.RaiseError("attempt to index a non-table object(%v) with key '%s'", curobj.Type().String(), key)
1321 }
1322 return LNil
1323 }
1324 if metaindex.Type() == LTFunction {
1325 ls.reg.Push(metaindex)
1326 ls.reg.Push(curobj)
1327 ls.reg.Push(LString(key))
1328 ls.Call(2, 1)
1329 return ls.reg.Pop()
1330 } else {
1331 curobj = metaindex
1332 }
1333 }
1334 ls.RaiseError("too many recursions in gettable")
1335 return nil
1336}
1337
1338func (ls *LState) setField(obj LValue, key LValue, value LValue) {
1339 curobj := obj

Callers 3

GetFieldMethod · 0.95
initFunction · 0.45
initFunction · 0.45

Calls 9

metaOp1Method · 0.95
RaiseErrorMethod · 0.95
CallMethod · 0.95
LStringTypeAlias · 0.85
RawGetStringMethod · 0.80
StringMethod · 0.65
TypeMethod · 0.65
PushMethod · 0.65
PopMethod · 0.65

Tested by

no test coverage detected