(obj LValue, key string)
| 1092 | } |
| 1093 | |
| 1094 | func (ls *LState) getFieldString(obj LValue, key string) LValue { |
| 1095 | curobj := obj |
| 1096 | for i := 0; i < MaxTableGetLoop; i++ { |
| 1097 | tb, istable := curobj.(*LTable) |
| 1098 | if istable { |
| 1099 | ret := tb.RawGetString(key) |
| 1100 | if ret != LNil { |
| 1101 | return ret |
| 1102 | } |
| 1103 | } |
| 1104 | metaindex := ls.metaOp1(curobj, "__index") |
| 1105 | if metaindex == LNil { |
| 1106 | if !istable { |
| 1107 | ls.RaiseError("attempt to index a non-table object(%v) with key '%s'", curobj.Type().String(), key) |
| 1108 | } |
| 1109 | return LNil |
| 1110 | } |
| 1111 | if metaindex.Type() == LTFunction { |
| 1112 | ls.reg.Push(metaindex) |
| 1113 | ls.reg.Push(curobj) |
| 1114 | ls.reg.Push(LString(key)) |
| 1115 | ls.Call(2, 1) |
| 1116 | return ls.reg.Pop() |
| 1117 | } else { |
| 1118 | curobj = metaindex |
| 1119 | } |
| 1120 | } |
| 1121 | ls.RaiseError("too many recursions in gettable") |
| 1122 | return nil |
| 1123 | } |
| 1124 | |
| 1125 | func (ls *LState) setField(obj LValue, key LValue, value LValue) { |
| 1126 | curobj := obj |
no test coverage detected