| 1274 | } |
| 1275 | |
| 1276 | func (ls *LState) getField(obj LValue, key LValue) LValue { |
| 1277 | curobj := obj |
| 1278 | for i := 0; i < MaxTableGetLoop; i++ { |
| 1279 | tb, istable := curobj.(*LTable) |
| 1280 | if istable { |
| 1281 | ret := tb.RawGet(key) |
| 1282 | if ret != LNil { |
| 1283 | return ret |
| 1284 | } |
| 1285 | } |
| 1286 | metaindex := ls.metaOp1(curobj, "__index") |
| 1287 | if metaindex == LNil { |
| 1288 | if !istable { |
| 1289 | ls.RaiseError("attempt to index a non-table object(%v) with key '%s'", curobj.Type().String(), key.String()) |
| 1290 | } |
| 1291 | return LNil |
| 1292 | } |
| 1293 | if metaindex.Type() == LTFunction { |
| 1294 | ls.reg.Push(metaindex) |
| 1295 | ls.reg.Push(curobj) |
| 1296 | ls.reg.Push(key) |
| 1297 | ls.Call(2, 1) |
| 1298 | return ls.reg.Pop() |
| 1299 | } else { |
| 1300 | curobj = metaindex |
| 1301 | } |
| 1302 | } |
| 1303 | ls.RaiseError("too many recursions in gettable") |
| 1304 | return nil |
| 1305 | } |
| 1306 | |
| 1307 | func (ls *LState) getFieldString(obj LValue, key string) LValue { |
| 1308 | curobj := obj |