lua-users home
lua-l archive

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


On 5/9/06, Diego Nehab <diego@tecgraf.puc-rio.br> wrote:
> Is there a *simple* C library that shows an implementaion of the C
> side of this. I've looked at some of the ones on LuaForge, but they
> use a compat51 script which I'd rather avoid and just do it the 5.1
> way. Of course maybe I'm not understanding what compat51 is really
> doing...

I am setting one up for you just now.
     http://www.cs.princeton.edu/~diego/ran2.tar.gz

Let me know when you get it and I will remove the file.

Thanks alot, that is a very nice example! I thought it was really that
simple, but I wasn't sure.

All you need is this single function right?

int luaopen_ran2(lua_State *L) {
  do whatever you want here
  return 1;
}

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?

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.

Don't worry about compat-5.1. This is what Lua 5.0 people
have to use to have access to the Lua 5.1 package system.
The interface is exactly what you would find in Lua 5.1. Of
course, if you are using Lua 5.1, you already have that.

I wasn't really sure if it was that the C code was written for 5.1 and
compat51 tricked lua50 to work properly or if it was the other way
around.

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