| 1123 | } |
| 1124 | |
| 1125 | func (ls *LState) setField(obj LValue, key LValue, value LValue) { |
| 1126 | curobj := obj |
| 1127 | for i := 0; i < MaxTableGetLoop; i++ { |
| 1128 | tb, istable := curobj.(*LTable) |
| 1129 | if istable { |
| 1130 | if tb.RawGet(key) != LNil { |
| 1131 | ls.RawSet(tb, key, value) |
| 1132 | return |
| 1133 | } |
| 1134 | } |
| 1135 | metaindex := ls.metaOp1(curobj, "__newindex") |
| 1136 | if metaindex == LNil { |
| 1137 | if !istable { |
| 1138 | ls.RaiseError("attempt to index a non-table object(%v) with key '%s'", curobj.Type().String(), key.String()) |
| 1139 | } |
| 1140 | ls.RawSet(tb, key, value) |
| 1141 | return |
| 1142 | } |
| 1143 | if metaindex.Type() == LTFunction { |
| 1144 | ls.reg.Push(metaindex) |
| 1145 | ls.reg.Push(curobj) |
| 1146 | ls.reg.Push(key) |
| 1147 | ls.reg.Push(value) |
| 1148 | ls.Call(3, 0) |
| 1149 | return |
| 1150 | } else { |
| 1151 | curobj = metaindex |
| 1152 | } |
| 1153 | } |
| 1154 | ls.RaiseError("too many recursions in settable") |
| 1155 | } |
| 1156 | |
| 1157 | func (ls *LState) setFieldString(obj LValue, key string, value LValue) { |
| 1158 | curobj := obj |