| 1298 | } |
| 1299 | |
| 1300 | func (ls *LState) Get(idx int) LValue { |
| 1301 | base := ls.currentLocalBase() |
| 1302 | if idx > 0 { |
| 1303 | reg := base + idx - 1 |
| 1304 | if reg < ls.reg.Top() { |
| 1305 | return ls.reg.Get(reg) |
| 1306 | } |
| 1307 | return LNil |
| 1308 | } else if idx == 0 { |
| 1309 | return LNil |
| 1310 | } else if idx > RegistryIndex { |
| 1311 | tidx := ls.reg.Top() + idx |
| 1312 | if tidx < base { |
| 1313 | return LNil |
| 1314 | } |
| 1315 | return ls.reg.Get(tidx) |
| 1316 | } else { |
| 1317 | switch idx { |
| 1318 | case RegistryIndex: |
| 1319 | return ls.G.Registry |
| 1320 | case EnvironIndex: |
| 1321 | if ls.currentFrame == nil { |
| 1322 | return ls.Env |
| 1323 | } |
| 1324 | return ls.currentFrame.Fn.Env |
| 1325 | case GlobalsIndex: |
| 1326 | return ls.G.Global |
| 1327 | default: |
| 1328 | fn := ls.currentFrame.Fn |
| 1329 | index := GlobalsIndex - idx - 1 |
| 1330 | if index < len(fn.Upvalues) { |
| 1331 | return fn.Upvalues[index].Value() |
| 1332 | } |
| 1333 | return LNil |
| 1334 | } |
| 1335 | } |
| 1336 | return LNil |
| 1337 | } |
| 1338 | |
| 1339 | func (ls *LState) Push(value LValue) { |
| 1340 | ls.reg.Push(value) |