[PATCH v2 2/6] Add functions to ease using Lua iterators from C

Vladimir Davydov vdavydov.dev at gmail.com
Wed Jan 16 11:18:02 MSK 2019


On Wed, Jan 16, 2019 at 02:26:23AM +0300, Alexander Turenko wrote:
> > > diff --git a/src/lua/utils.h b/src/lua/utils.h
> > > index bd302d8e9..6ba2e4767 100644
> > > --- a/src/lua/utils.h
> > > +++ b/src/lua/utils.h
> > > @@ -525,6 +525,34 @@ luaL_checkfinite(struct lua_State *L, struct luaL_serializer *cfg,
> > >  		luaL_error(L, "number must not be NaN or Inf");
> > >  }
> > >  
> > > +/* {{{ Helper functions to interact with a Lua iterator from C */
> > > +
> > > +/**
> > > + * Holds iterator state (references to Lua objects).
> > > + */
> > > +struct luaL_iterator;
> > 
> > I'd make luaL_iterator struct transparent so that one could define it
> > on stack.
> > 
> 
> But luaL_iterator_new() do malloc and return a pointer. So we need to
> change the function or add another one to initialize a structure
> allocated outsize of the module.

OK, I see it now. Didn't think about it when first looked at the patch.

> 
> Can you please suggest me how the API should look if we'll make the
> structure transparent?
> 
> I left it unchanged until we'll discuss this aspect.
> 
> > > +
> > > +/**
> > > + * Create a Lua iterator from {gen, param, state}.
> > 
> > May be, we could pass idx == 0 to create an iterator from
> > gen, param, state (without a table)? Would it be worthwhile?
> > 
> 
> I think it is good idea, because cases could be different. My thought
> was that we'll add another function for this case (if we'll need), but
> using idx == 0 is better. I created the similar API before for
> luaT_newtuple().
> 
> And I think the new merger API will require it.

The patch looks good to me now, but I'm still not sure the new merger
implementation will need to deal with Lua iterators in C at all, as one
can easily write a wrapper function in Lua turning an iterator to a
'fetch' closure, which then can be passed to a source constructor.



More information about the Tarantool-patches mailing list