lua-users home
lua-l archive

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


Hi Greg,
 
thanks for the reply =)
 
I am using Lua 5.1, and I am compiling it using MSVS 8, C++
 
I am running this test code right after i call lua_open, to avoid any other factors.
 
I am stepping through the code using the debugger, and getting the reference values
I described.
 
i stepped into the luaL_ref and related functions but I am not very 'up' on the concepts of how it is supposed to work, from what I see it seems that when a ref is created it is put into a table and that index is returned, when somthing is un-refed the index it occupied is put into a 'free list' which the ref checks first to reuse old ref id's, given the functionality it seems to do that for two iterations (returns 1 then returns 1 again) but after that it simply starts to accumulate.
 
do you think this could be some weird compiler specific problem?
 
-Raymond

 
On 4/14/06, Greg Falcon <veloso@verylowsodium.com> wrote:
On 4/13/06, Raymond Jacobs <raymondj@gmail.com> wrote:
> Greetings all,
>
>  in my test code:
>
>  while(1)
>  {
>          lua_pushstring(state,"woot!");
>          int ref=lua_ref(state,1);
>          lua_unref(state,ref);
>          lua_gc(state,LUA_GCCOLLECT,0);
>  }
>
>  I observe ref is returned like this
>
>  iteration 1  ref is 1
>  iteration 2  ref is 1
>  iteration 3  ref is 2
>  further iterations increase ref by 1

I tried to reproduce your problem in Lua 5.1, but could not do so.  I
also looked at the Lua code in question and couldn't figure out what
could cause this.

What version of Lua are you using?  More importantly, how are you
inspecting the return values of lua_ref()?  Are you stepping through
this code in a debugger, or is there more to your program than you
pasted here?

Note that the lua_ref compatibility macro simply calls luaL_ref, using
the registry as the reference table.  If you use integer keys in the
registry for your own purposes, this will conflict with lua_ref().

Greg F