| 1061 | } |
| 1062 | |
| 1063 | func (ls *LState) getField(obj LValue, key LValue) LValue { |
| 1064 | curobj := obj |
| 1065 | for i := 0; i < MaxTableGetLoop; i++ { |
| 1066 | tb, istable := curobj.(*LTable) |
| 1067 | if istable { |
| 1068 | ret := tb.RawGet(key) |
| 1069 | if ret != LNil { |
| 1070 | return ret |
| 1071 | } |
| 1072 | } |
| 1073 | metaindex := ls.metaOp1(curobj, "__index") |
| 1074 | if metaindex == LNil { |
| 1075 | if !istable { |
| 1076 | ls.RaiseError("attempt to index a non-table object(%v) with key '%s'", curobj.Type().String(), key.String()) |
| 1077 | } |
| 1078 | return LNil |
| 1079 | } |
| 1080 | if metaindex.Type() == LTFunction { |
| 1081 | ls.reg.Push(metaindex) |
| 1082 | ls.reg.Push(curobj) |
| 1083 | ls.reg.Push(key) |
| 1084 | ls.Call(2, 1) |
| 1085 | return ls.reg.Pop() |
| 1086 | } else { |
| 1087 | curobj = metaindex |
| 1088 | } |
| 1089 | } |
| 1090 | ls.RaiseError("too many recursions in gettable") |
| 1091 | return nil |
| 1092 | } |
| 1093 | |
| 1094 | func (ls *LState) getFieldString(obj LValue, key string) LValue { |
| 1095 | curobj := obj |