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

Method setField

state.go:1338–1368  ·  view source on GitHub ↗
(obj LValue, key LValue, value LValue)

Source from the content-addressed store, hash-verified

1336}
1337
1338func (ls *LState) setField(obj LValue, key LValue, value LValue) {
1339 curobj := obj
1340 for i := 0; i < MaxTableGetLoop; i++ {
1341 tb, istable := curobj.(*LTable)
1342 if istable {
1343 if tb.RawGet(key) != LNil {
1344 ls.RawSet(tb, key, value)
1345 return
1346 }
1347 }
1348 metaindex := ls.metaOp1(curobj, "__newindex")
1349 if metaindex == LNil {
1350 if !istable {
1351 ls.RaiseError("attempt to index a non-table object(%v) with key '%s'", curobj.Type().String(), key.String())
1352 }
1353 ls.RawSet(tb, key, value)
1354 return
1355 }
1356 if metaindex.Type() == LTFunction {
1357 ls.reg.Push(metaindex)
1358 ls.reg.Push(curobj)
1359 ls.reg.Push(key)
1360 ls.reg.Push(value)
1361 ls.Call(3, 0)
1362 return
1363 } else {
1364 curobj = metaindex
1365 }
1366 }
1367 ls.RaiseError("too many recursions in settable")
1368}
1369
1370func (ls *LState) setFieldString(obj LValue, key string, value LValue) {
1371 curobj := obj

Callers 3

SetTableMethod · 0.95
initFunction · 0.45
initFunction · 0.45

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