MCPcopy Create free account
hub / github.com/yuin/gopher-lua / getField

Method getField

_state.go:1063–1092  ·  view source on GitHub ↗
(obj LValue, key LValue)

Source from the content-addressed store, hash-verified

1061}
1062
1063func (ls *LState) getField(obj LValue, key LValue) LValue {
1064 curobj := obj
1065 for i := 0; i < MaxTableGetLoop; i++ {
1066 tb, istable := curobj.(*LTable)
1067 if istable {
1068 ret := tb.RawGet(key)
1069 if ret != LNil {
1070 return ret
1071 }
1072 }
1073 metaindex := ls.metaOp1(curobj, "__index")
1074 if metaindex == LNil {
1075 if !istable {
1076 ls.RaiseError("attempt to index a non-table object(%v) with key '%s'", curobj.Type().String(), key.String())
1077 }
1078 return LNil
1079 }
1080 if metaindex.Type() == LTFunction {
1081 ls.reg.Push(metaindex)
1082 ls.reg.Push(curobj)
1083 ls.reg.Push(key)
1084 ls.Call(2, 1)
1085 return ls.reg.Pop()
1086 } else {
1087 curobj = metaindex
1088 }
1089 }
1090 ls.RaiseError("too many recursions in gettable")
1091 return nil
1092}
1093
1094func (ls *LState) getFieldString(obj LValue, key string) LValue {
1095 curobj := obj

Callers 1

GetTableMethod · 0.95

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