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

Method getFieldString

_state.go:1094–1123  ·  view source on GitHub ↗
(obj LValue, key string)

Source from the content-addressed store, hash-verified

1092}
1093
1094func (ls *LState) getFieldString(obj LValue, key string) LValue {
1095 curobj := obj
1096 for i := 0; i < MaxTableGetLoop; i++ {
1097 tb, istable := curobj.(*LTable)
1098 if istable {
1099 ret := tb.RawGetString(key)
1100 if ret != LNil {
1101 return ret
1102 }
1103 }
1104 metaindex := ls.metaOp1(curobj, "__index")
1105 if metaindex == LNil {
1106 if !istable {
1107 ls.RaiseError("attempt to index a non-table object(%v) with key '%s'", curobj.Type().String(), key)
1108 }
1109 return LNil
1110 }
1111 if metaindex.Type() == LTFunction {
1112 ls.reg.Push(metaindex)
1113 ls.reg.Push(curobj)
1114 ls.reg.Push(LString(key))
1115 ls.Call(2, 1)
1116 return ls.reg.Pop()
1117 } else {
1118 curobj = metaindex
1119 }
1120 }
1121 ls.RaiseError("too many recursions in gettable")
1122 return nil
1123}
1124
1125func (ls *LState) setField(obj LValue, key LValue, value LValue) {
1126 curobj := obj

Callers 1

GetFieldMethod · 0.95

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