| 1511 | } |
| 1512 | |
| 1513 | func (ls *LState) Get(idx int) LValue { |
| 1514 | base := ls.currentLocalBase() |
| 1515 | if idx > 0 { |
| 1516 | reg := base + idx - 1 |
| 1517 | if reg < ls.reg.Top() { |
| 1518 | return ls.reg.Get(reg) |
| 1519 | } |
| 1520 | return LNil |
| 1521 | } else if idx == 0 { |
| 1522 | return LNil |
| 1523 | } else if idx > RegistryIndex { |
| 1524 | tidx := ls.reg.Top() + idx |
| 1525 | if tidx < base { |
| 1526 | return LNil |
| 1527 | } |
| 1528 | return ls.reg.Get(tidx) |
| 1529 | } else { |
| 1530 | switch idx { |
| 1531 | case RegistryIndex: |
| 1532 | return ls.G.Registry |
| 1533 | case EnvironIndex: |
| 1534 | if ls.currentFrame == nil { |
| 1535 | return ls.Env |
| 1536 | } |
| 1537 | return ls.currentFrame.Fn.Env |
| 1538 | case GlobalsIndex: |
| 1539 | return ls.G.Global |
| 1540 | default: |
| 1541 | fn := ls.currentFrame.Fn |
| 1542 | index := GlobalsIndex - idx - 1 |
| 1543 | if index < len(fn.Upvalues) { |
| 1544 | return fn.Upvalues[index].Value() |
| 1545 | } |
| 1546 | return LNil |
| 1547 | } |
| 1548 | } |
| 1549 | return LNil |
| 1550 | } |
| 1551 | |
| 1552 | func (ls *LState) Push(value LValue) { |
| 1553 | ls.reg.Push(value) |