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

Method setField

_state.go:1125–1155  ·  view source on GitHub ↗
(obj LValue, key LValue, value LValue)

Source from the content-addressed store, hash-verified

1123}
1124
1125func (ls *LState) setField(obj LValue, key LValue, value LValue) {
1126 curobj := obj
1127 for i := 0; i < MaxTableGetLoop; i++ {
1128 tb, istable := curobj.(*LTable)
1129 if istable {
1130 if tb.RawGet(key) != LNil {
1131 ls.RawSet(tb, key, value)
1132 return
1133 }
1134 }
1135 metaindex := ls.metaOp1(curobj, "__newindex")
1136 if metaindex == LNil {
1137 if !istable {
1138 ls.RaiseError("attempt to index a non-table object(%v) with key '%s'", curobj.Type().String(), key.String())
1139 }
1140 ls.RawSet(tb, key, value)
1141 return
1142 }
1143 if metaindex.Type() == LTFunction {
1144 ls.reg.Push(metaindex)
1145 ls.reg.Push(curobj)
1146 ls.reg.Push(key)
1147 ls.reg.Push(value)
1148 ls.Call(3, 0)
1149 return
1150 } else {
1151 curobj = metaindex
1152 }
1153 }
1154 ls.RaiseError("too many recursions in settable")
1155}
1156
1157func (ls *LState) setFieldString(obj LValue, key string, value LValue) {
1158 curobj := obj

Callers 1

SetTableMethod · 0.95

Calls 8

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

Tested by

no test coverage detected