lua-users home
lua-l archive

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


> The way I've always handled this is to create a tag number just for
> "dead" variables, and change the lua Object to the dead tag number
> using lua_settag().  That way, you can know its not valid anymore
> and not use it, even if it is still in scope under Lua.

We use this same approach for files, in the I/O library. When a file is
closed, we change its tag, so any future operation on it can detect the
error:

> t = readfrom("lua.c")
> readfrom()      -- close t
> read(t)
lua: cannot access a closed file
Active Stack:
        function read [in chunk (C)]
        main of (dostring) >> "read(t)"

-- Roberto