| 1305 | } |
| 1306 | |
| 1307 | func (ls *LState) getFieldString(obj LValue, key string) LValue { |
| 1308 | curobj := obj |
| 1309 | for i := 0; i < MaxTableGetLoop; i++ { |
| 1310 | tb, istable := curobj.(*LTable) |
| 1311 | if istable { |
| 1312 | ret := tb.RawGetString(key) |
| 1313 | if ret != LNil { |
| 1314 | return ret |
| 1315 | } |
| 1316 | } |
| 1317 | metaindex := ls.metaOp1(curobj, "__index") |
| 1318 | if metaindex == LNil { |
| 1319 | if !istable { |
| 1320 | ls.RaiseError("attempt to index a non-table object(%v) with key '%s'", curobj.Type().String(), key) |
| 1321 | } |
| 1322 | return LNil |
| 1323 | } |
| 1324 | if metaindex.Type() == LTFunction { |
| 1325 | ls.reg.Push(metaindex) |
| 1326 | ls.reg.Push(curobj) |
| 1327 | ls.reg.Push(LString(key)) |
| 1328 | ls.Call(2, 1) |
| 1329 | return ls.reg.Pop() |
| 1330 | } else { |
| 1331 | curobj = metaindex |
| 1332 | } |
| 1333 | } |
| 1334 | ls.RaiseError("too many recursions in gettable") |
| 1335 | return nil |
| 1336 | } |
| 1337 | |
| 1338 | func (ls *LState) setField(obj LValue, key LValue, value LValue) { |
| 1339 | curobj := obj |