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 <spied@yandex.ru> 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);

See: http://hdiedrich.github.com/darc/README.html

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: ... */
   if(XLUA_IS_STRING(variable))

       /* 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: http://hdiedrich.github.com/darc/doc/sample.html

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

Benchmarks for table traversal: http://hdiedrich.github.com/darc/doc/BENCHMARKS.html

Henning