lua-users home
lua-l archive

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


On Tue, Nov 20, 2012 at 02:23:39PM +0000, Jerome Vuarand wrote:
> 2012/11/20 Richard W.M. Jones <rjones@redhat.com>:
> >> And as for the "single change", it has a big impact. Whether you pass
> >> a valid string or NULL, luaL_register will create a new table on the
> >> stack or not.
> >
> > I think what I don't understand is do I need to add this string
> > parameter?  The code seems to work fine at the moment (using NULL), so
> > I'm inclined to just leave it alone.
> 
> You don't "need" to, but the luaL_register call does two very
> different things whether you pass a string or not. Both are
> acceptable, depending on your intent. But I don't know your intent
> there. A simple luaopen_ function creates a Lua table, put some stuff
> in that table, and somehow pass it back to require. That table is then
> called a "module". Your luaopen_ function does something completely
> different. It is perfectly valid, provided you understand what you are
> doing.
> 
> To sum it up, what do you intend to do with that call to luaL_register?

I think to a first approximation I have no idea what I'm doing.

What I'm *trying* to do is to let people call:

  g = Guestfs.create ()

in order to create a libguestfs handle which then has methods like
g:set_verbose(true) etc., plus a few "global" variables like
Guestfs.event_all.

All the above works fine with the code I've written.

But from what you say it sounds like what I'm doing is completely wrong.

Is there an example of a luaopen_* function which does this right?
Or can you tell me what specifically I'm doing wrong?

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
New in Fedora 11: Fedora Windows cross-compiler. Compile Windows
programs, test, and build Windows installers. Over 70 libraries supprt'd
http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw