lua_getref problem

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

lua_getref problem

Juergen Fuhrmann

Dear men(&women) on the moon,

We are successfully using now lua as an extension language for several
numerics packages (I confess I still  have to post  this info onto the
list of projects using lua), and  with things becoming more complex we
are stuck now with the following problem: 

I have written a package olua which manages proxies of C structs using
lua tables. The  central data type of  this  is oluaObject which is  a
struct holding a  _reference_ to an lua object  created by lua_ref  --
after  running into  trouble  by  using luaObjects  directly due  some
possibly rather common misunderstanding of luaObjects. 

Everytime I want  to access the luaObject behind  the oluaObject I now
have to call lua_getref.  These calls to lua_getref increase the C2lua
stack by calling put_luaObject. The result is that, when doing this in
a complex environment, I get the "Lua2C - C2Lua overflow" message just
by  accessing these references  a  lot  of times.   Of course I  could
increase  the stack limit  in my source to  fit our needs for the time
being, but I consider this as rather unnatural... 

Is this a bug, a feature or a mis-understanding from my side ?

Still in honeyemoon with lua - 
Juergen Fuhrmann


                             Numerical Mathematics & Scientific Computing
               Weierstrass Institute for Applied Analysis and Stochastics
   Mohrenstr. 39 10117 Berlin    fon:+49 30 20372560   fax:+49 30 2044975
http://www.wias-berlin.de/~fuhrmann        [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: lua_getref problem

Juergen Fuhrmann
>  Wed, 19 May 1999 09:02:11 -0300 (EST)
>  Juergen Fuhrmann <[hidden email]> wrote:
>
>  
>  
>  Dear men(&women) on the moon,
>  
>  We are successfully using now lua as an extension language for several
>  numerics packages (I confess I still  have to post  this info onto the
>  list of projects using lua), and  with things becoming more complex we
>  are stuck now with the following problem: 
>  
>  I have written a package olua which manages proxies of C structs using
>  lua tables. The  central data type of  this  is oluaObject which is  a
>  struct holding a  _reference_ to an lua object  created by lua_ref  --
>  after  running into  trouble  by  using luaObjects  directly due  some
>  possibly rather common misunderstanding of luaObjects. 
>  
>  Everytime I want  to access the luaObject behind  the oluaObject I now
>  have to call lua_getref.  These calls to lua_getref increase the C2lua
>  stack by calling put_luaObject. The result is that, when doing this in
>  a complex environment, I get the "Lua2C - C2Lua overflow" message just
>  by  accessing these references  a  lot  of times.   Of course I  could
>  increase  the stack limit  in my source to  fit our needs for the time
>  being, but I consider this as rather unnatural... 
>  
>  Is this a bug, a feature or a mis-understanding from my side ?
>  

It is the later ;-}

<RTFM>
When C code calls Lua repeatedly, as in a loop, objects returned by these calls can accumulate, and may cause a stack overflow.
To avoid this, nested blocks can be defined with the functions: 

void           lua_beginblock           (void);
void           lua_endblock             (void);

After the end of the block, all lua_Object's created inside it are released. The use of explicit nested blocks is strongly
encouraged. 
</RTFM>

So I  inserted this stuff in  the appropriate places, and all problems
have gone in a magic fashion... 

Sorry for any inconvenience.

Juergen

Juergen Fuhrmann             Numerical Mathematics & Scientific Computing
               Weierstrass Institute for Applied Analysis and Stochastics
   Mohrenstr. 39 10117 Berlin    fon:+49 30 20372560   fax:+49 30 2044975
http://www.wias-berlin.de/~fuhrmann        [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: lua_getref problem

Vincent PENQUERC'H
In reply to this post by Juergen Fuhrmann
  Hi,

> stack by calling put_luaObject. The result is that, when doing this in
> a complex environment, I get the "Lua2C - C2Lua overflow" message just
> by  accessing these references  a  lot  of times.   Of course I  could

I ran into overflow problems too, and solved them by calling often the
pair lua_beginblock/lua_endblock, that clean communication stack. You
might have to call these more often than you do.

Vincent Penquerc'h