lua-users home
lua-l archive

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


Conceptually I can follow what you are describing but as a noob, I haven't had the opportunity (yet ;-) to write a Lua 'C' module.  It would appear that you're telling me I'd have to do this in order to provide the necessary 'C' function for the on_state_create callback function. Your expertise exceeds mine here so at this point it's not clear exactly what the function would do or look like. I suspect it's a more straightforward exercise in your eyes. I was hoping Mike Pall might chime in here and offer a suggestion.

I did re-try my code segment as follows:

local lanes = require("lanes")
lanes.configure({with_timers=false})

This time it ran without errors. I haven't tried, however, to create a lane yet. I thought it might provide you with more information on what's going on in the code.

Thanks for your continued help. I really appreciate it.


On Tue, Apr 24, 2012 at 12:15 PM, Benoit Germain <bnt.germain@gmail.com> wrote:
2012/4/24 Glenn Schmottlach <gschmottlach@gmail.com>:
> Just to be clear, a program as simple as:
>
> local lanes = require("lanes")
> lanes.configure()
>
> Fails with the error I mentioned earlier. Are you suggesting that this code
> (instead) should look like the following?
>
> local lanes = require("lanes")
>
> lanes.gen( {required = {"bit", "ffi"}}, func_body)
> lanes.configure()
>
> This wouldn't (seem) to work since I can't even "configure" lanes. Your
> suggestion seems to only come into play when I'm trying to generate/create a
> lane associated with the function body.

What happens is that the lanes.configure() call attempts to create a
lane for the timer support feature by default. This triggers the
creation of the keeper states, which are populated with the contents
of all base libraries (because everything copied from one lane to
another transits through the keeper states).
Whenever a state is created (keepers included), I also copy over in the
newly created state the contents of package.path, package.cpath,
package.loaders and package.preload found in the main state (or
whatever is provided in the generator options table) so that the
hooked require finds packages in the same locations than when called
from the main Lua state (see lanes.c line
1594).

I suppose that when the LuaJIT interpreter creates the main Lua state
it manually populates package.preload.ffi with some C function. Because of this
I need it to exist in the newly created lane's Lua state, which isn't
the case because it is a plain Lua state that LuaJIT didn't get its
hands on.

So either LuaJIT's lua_newstate should always populate
package.preload.ffi (which might not be the best of ideas), or you
have to provide a C on_state_create function to lanes.configure that
will do it for you.
A third option is to call lanes.configure{ with_timers = false}. But
this will only postpone the problem to your first lanes.gen() call I
suppose...

In any event I need to investigate a bit more. But maybe Mike has an
idea how I should handle this particular problem?



--
Benoit.