lua-users home
lua-l archive

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


I am getting the following assertion in Lua 5.0.2:

Assertion failed: !iscollectable(o2) || (ttype(o2) ==
(o2)->value.gc->gch.tt), 
file ...\lua-5.0.2\src\lfunc.c, line 69

This is triggered by garbage-collecting an unfinished coroutine
containing a function referencing a local in the containing scope.  

It's taken me a while to trim my test code down to that below, but now
I'm stuck.  Additionally: if I don't yield it's OK; if t is global it's
OK; and if I don't reference t inside func() it's OK.  If I compile Lua
without assertions, this example survives, but in my real application, I
get access violations later on.

Help!

Martin.


#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"


int main() {

    lua_State* L = lua_open();
    luaopen_base(L);

    lua_dostring(L, 
        "coroutine.wrap(function()"
        "  local t={}; "
        "  local func=function() print(type(t)) end; "
        "  func(); "
        "  coroutine.yield()"
        "end)()"
        );

    lua_setgcthreshold(L, 0); // assert happens in here

    return 0;
}