lua-users home
lua-l archive

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

Hi Ed & Steve,

steve donovan schrieb:
On Wed, May 11, 2011 at 10:16 AM, Ed <> wrote:
char *s = XLUA_STRING(variable);
IMHO a more detailed example would be useful.
For instance, what exactly is 'variable' here?
A TValue pointer. That is the universal, internal variable value holding structure.

You get it by:

TValue *o = XLUA_INDEX_TO_ADDRESS(L, index);


An example of table traversal would be interesting here, since it's a
common C API task.

int word_filter(TValue *variable, void *state)
    /* if a string: ... */

       /* screen it */
       return inspect(XLUA_STRING(variable));

   /* if a table: ... */
   else if(XLUA_IS_TABLE(variable))

/* traverse table, using this function as callback, for each element */
       return darc_traverse(XLUA_TABLE(variable), word_filter, state);

   return 1;

Full sample file, with comments and biolerplate, ready to compile:

To see it run: clone the project and build the sample by doign make <PLATFORM>.

Benchmarks for table traversal: