getting table indexes & values

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

getting table indexes & values

Dave Bollinger
Pablo Saldo wrote:
 >> My Experiences prove it can't get the next table's index.

   Try changing this:

 >> lua_callfunction(lua_getglobal('next'));

   to this:

 >> lua_callfunction(lua_getglobal('next'+char(0)));

   Delphi will type convert string types to pchars but it won't add a
terminator for you.  (this can lead to obscure access violations depending
on how the caller uses the string!)  I'm guessing that this is preventing
Lua from finding a symbol match.  Also, you might try splitting up those
two calls and check the tag returned by lua_getglobal in the debugger.

   Cheers,

   Dave

Reply | Threaded
Open this post in threaded view
|

Re: getting table indexes & values

Pablo Saldo
At 10:28 27/07/99 -0300, you wrote:

> >> My Experiences prove it can't get the next table's index.
>   Try changing this:
> >> lua_callfunction(lua_getglobal('next'));
>   to this:
> >> lua_callfunction(lua_getglobal('next'+char(0)));
>   Delphi will type convert string types to pchars but it won't add a
>terminator for you.  (this can lead to obscure access violations depending
>on how the caller uses the string!)  I'm guessing that this is preventing
>Lua from finding a symbol match.  Also, you might try splitting up those
>two calls and check the tag returned by lua_getglobal in the debugger.

I don't it woul resolve my problem, 'cause I can get the first index
(calling next(VarName, nil)) outside the loop, but inside this,
next(VarName, IndexName) still give me the same index, looping forever.

  (o,o)  Pablo Saldo  -  [hidden email]
  {`"'}  FUNDACAO UNIVERSIDADE FEDERAL DO RIO GRANDE
  -"-"-  ENGENHARIA DE COMPUTACAO

Reply | Threaded
Open this post in threaded view
|

Re: getting table indexes & values

Dave Bollinger
In reply to this post by Dave Bollinger
   I have another idea for you.  I've since compiled your code, and I don't
know if this is related, or a side-effect or what, but...

 >> next(VarName, IndexName) still give me the same index, looping forever.

   It didn't loop forever for me, but I did get an access violation on this
line:

 >> while (Varindex <> (#0))   

   which seems to be the result of "(#0)".  Typecasting it to pchar (as you
do on an earlier line), or testing directly against Nil, or using the
Assigned() function all seemed to work.  I was just dumping your Var*'s to
a memo and it correctly reported all that I had defined.  Then stopped.  ;)

   Cheers,

   Dave

Reply | Threaded
Open this post in threaded view
|

Re: getting table indexes & values

David Jeske-3
In reply to this post by Pablo Saldo
On Thu, Jul 29, 1999 at 01:21:43AM -0300, Pablo Saldo wrote:
> I don't it woul resolve my problem, 'cause I can get the first index
> (calling next(VarName, nil)) outside the loop, but inside this,
> next(VarName, IndexName) still give me the same index, looping forever.

I've run into some problems like this before when I was doing lots of
stuff inthe middle. Remember that the lua2C stack gets blown during
certain operations. I've found that almost everyplace I use "next"
from C, I end up making a lua_ref, doing some work, and then
dereferencing the lua_ref. Here is some psudo-code:

this_index = next(varname,nil);
this_index_ref = lua_ref(this_index);
while (there_are_more_values) {
  /* do some stuff with this_index */


  /* get next */
  this_index = next(varname,lua_getref(this_index_ref))
  this_index_ref = lua_ref(this_index)
}




-- 
David Jeske (N9LCA) + http://www.chat.net/~jeske/ + [hidden email]