diff --git a/tag_methods.go b/tag_methods.go index eb15a99..a2dfa32 100644 --- a/tag_methods.go +++ b/tag_methods.go @@ -84,11 +84,17 @@ func (l *State) tagMethodByObject(o value, event tm) value { } func (l *State) callTagMethod(f, p1, p2 value) value { + top := l.top + if l.callInfo.isLua() && l.top < l.callInfo.top { + l.top = l.callInfo.top + } l.push(f) l.push(p1) l.push(p2) l.call(l.top-3, 1, l.callInfo.isLua()) - return l.pop() + v := l.pop() + l.top = top + return v } func (l *State) callTagMethodV(f, p1, p2, p3 value) { diff --git a/vm_test.go b/vm_test.go index e78570c..d7b82ad 100644 --- a/vm_test.go +++ b/vm_test.go @@ -209,6 +209,27 @@ func TestVarArgMeta(t *testing.T) { testString(t, s) } +func TestConcatWithMetatableIndexInTableConstructor(t *testing.T) { + testString(t, `local meta = { + __index = function(self, key) + return "ASD" + end + } + + TEST = {} + setmetatable(TEST, meta) + assert('b ' .. TEST.B .. ' b' == 'b ASD b') + + local x = { + 'a ' .. TEST.A .. ' a', + 'b ' .. TEST.B .. ' b' + } + + assert(x[1] == 'a ASD a') + assert(x[2] == 'b ASD b', 'got ' .. tostring(x[2])) + assert('c ' .. TEST.C == 'c ASD')`) +} + func TestCanRemoveNilObjectFromStack(t *testing.T) { defer func() { if r := recover(); r != nil {