lua-users home
lua-l archive

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


Hi,

Must you always return 1? wxLua doesn't use the
luaL_openlib(L, "ran2", ran2_func, 1) method of creating
the lib since it's a little more complicated and we have
to worry about setting up metatables for tracking objects.
I suppose that I could just push the global "wx" table we
create onto the stack after wxLua does it's thing and
nobody would be any the wiser right?

You can still setup a bunch of stuff before (or after)
calling luaL_openlib. Unless you have a good reason not to
use it, I would suggest you do. Makes your code easier for
people to understand later. And saves you the trouble of
writing the loop yourself. :) But yes, you are free not to
use it, create your own namespace table and return it.

About the return, users will want to write a line like this:

    local wx = require"wx"

The call to require() returns what or your function returns,
what it finds in package.loaded["wx"] (if your function
returns something, require will store it in package.loaded
too), or it returns true otherwise.

Both luaL_openlib and module create a namespace and store it
in package.loaded. So you don't actually have to return
anything if you use them. But since the table was there, I decided to return it.

Just to be sure, if I understand the code in
lua/src/loadlib.c, Lua's require takes "require"XXX"" and
looks for the C function "luaopen_XXX" in the library and
runs it. You have to name the "-shared" library XXX.so for
lua to find and you also need "-fpic" for the
position-independent code in the library. This last bit
would have certainly caused me a headache as I wouldn't
have thought to do that.

It's in the Wiki. Instructions to build libraries in pretty
much every type of machine.

Thanks again, I'll give it a shot later this week, when
the SourceForge CVS is back up :(

It will be great to start using it.

[]s,
Diego.