| 1336 | } |
| 1337 | |
| 1338 | func (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 | |
| 1370 | func (ls *LState) setFieldString(obj LValue, key string, value LValue) { |
| 1371 | curobj := obj |