lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


The following code won't work on Lua 5.1:

local env = setmetatable({}, {
    __index = function()
        coroutine.yield("bar")
    end
})

local f = coroutine.wrap(function()
    local var = env.foo
end)

f()

-- fails with this message
lua5.1: pcall.lua:11: attempt to yield across metamethod/C-call boundary
stack traceback:
        [C]: in function 'f'
        pcall.lua:11: in main chunk
        [C]: ?

While it works fine with Lua 5.2.0-work1

However, the following code:

local env = setmetatable({}, {
    __index = function()
        coroutine.yield("bar")
    end
})

local f = coroutine.wrap(function()
    local var = env.foo
end)

f()

local var = env.foo

gives this error with Lua 5.2.0-work1

lua5.2: attempt to yield across metamethod/C-call boundary
stack traceback:
        [C]: in function 'yield'
        pcall.lua:3: in function '__index'
        pcall.lua:13: in main chunk
        [C]: in ?

It's obvious that my code is wrong since I'm yielding, but I'm not within a coroutine. Is the error message misleading or I'm missing something?

Regards
Ignacio