lua-users home
lua-l archive

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


Hi,

I'm trying to set a table that is part of an userdata. I inherit the
userdata from lua in this way:

    lua_getglobal(L, "foo"); /* get the global lua table */
    lua_getfield(L, -1, "new");  /* get the function from the table */
    lua_insert(L, -2); /* move new up a position so self is the first arg */
    lua_pcall(L, 1, 1, 0); /* call it, the returned table is left on the
stack */
    c_foo->id = luaL_ref(L, LUA_REGISTRYINDEX);

Where the lua definition of foo.new is:

    function foo.new()
      local lfoo = {}
      lfoo.table = {}

      -- other methods and attributes

      return lfoo
    end

When I now open the lua shell and type

    foo_var = cfoo.new()              -- new c foo class inherited from lua
    print(foo_var.table)              -- read access is possible
    foo_var.table["key"] = <anything> -- crashes the lua interpreter

Do you have any ideas why it shows this behavior? Could wrong garbage
handling in my c code be the reason?

Thanks in advance, Benjamin