lua-users home
lua-l archive

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


Hello Brian,
I wrote the SWIG bindings for lua, so I can probably give some help for you.
I don't use the co-routines, so I am not sure how best to use them.

The SWIG bindings made the assumption that there could be more than one interpreter running at once, therefor it does not store the lua_State* anywhere.

If you need the lua_State* in your code, I can think of a couple of ideas.
You could use the native function method, this allows you to add your own methods directly.

%native(my_function) int my_function(lua_State*L);

States that the following function will be added into the modules function table, but will not be wrappered.

Another method would be to pass the lua_State* into a function. There isn't a neat way to do this right now, but I think that adding this:

%typemap(in, numinputs=0) lua_State* 
%{ $1 = L; %}

To your input file, would allow you to have functions which pass the lua_State* as a parameter in.

void some_function(int a, float f,lua_State* s)
{
..
}

Hope this helps,
Mark

> Hello all,
> 
> I'd like to tap the collective brainpower of this mailing list to try
> and resolve a problem I'm having...
> 
> Today, I have a C function that I've registered with Lua whose purpose
> is to block the invoking script on a specified event using lua_yield().
> When that event occurs, lua_resume() is used to wake up the script.
> Simple enough.
> 
> I'd like to leverage SWIG in my project, so that I can easily expose
> other functions and structures of my application to Lua.  In looking at
> the conversion of the few functions I've already got, there would seem
> to be a problem with the block function described above.
> 
> The function uses the Lua state of the script as a context to associate
> the event subscription with, but as far as I can tell the Lua state is
> not available to functions wrapped by SWIG.  It seems like the script
> will have to pass its state as an explicit argument.  Is this correct,
> or is there a way for the function to determine this?
> 
> Something along the lines of pthread_self() for Lua, but called from
> within a function rather than the script.  BTW, is there a means for a
> script to get a handle to its own state for passing to a function if
> that's the route I have to go?
> 
> Thanks,
> Brian