lua-users home
lua-l archive

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

On Wed, May 20, 2009 at 4:28 PM, drake <> wrote:
> How do I implement something with the lua C api to handle calls on it by
> lua_next?

the easiest way is to replace the next() function with your own, that
honours some '__next' field on your metatable, and call the original
next() if there's none.

something like this (untested):

local oldnext=next
function next(t)
    local mt = getmetatable(t)
    nx = mt and mt.__next or oldnext
    return nx(t)

> One other point.  As I'm passing references to Lua objects off into the
> world of C++ (kroll), how do I (in C) increment/decrement the Lua reference
> count so that the Lua gc doesn't try to discard it and cause my code to go
> pop?

store them in the registry