[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [PoC] Tables aren't Lua's only data structure.
- From: Dirk Laurie <dirk.laurie@...>
- Date: Fri, 17 Apr 2015 10:54:05 +0200
2015-04-17 6:17 GMT+02:00 Soni L. <fakedme@gmail.com>:
> I present you Lua's second data structure: The stack.
I tried something of the kind in the 'tuple' sublibrary of the 'xtable'
library that John Hind and I developed at a stage when there was
some unhappiness about the table library. In the meantime that
library has been substantially improved.
https://github.com/dlaurie/xtable
We used a mixture of C and Lua.
>From the documentation:
The tuple sublibrary
This library provides basic functions for manipulating tuples, i.e.
immutable lists of values on the runtime stack. The functions are
supplied in the table xtable.tuple.
Since no table accesses are involved, and the return values are in the
same stack as the vararg list, often in the same positions, tuple
functions are fast.
Tuples in Lua live an ephemeral life as vararg lists or multiple return
values, and need to be passed to coroutines or packed into tables to
achieve permanence. The functions cache and iter, written in Lua, serve
as sample applications.
xtable.tuple.cache(...)
Returns a function that, when called, will return the given values.
xtable.tuple.iter(...)
Returns an iterator function that, in a generic for loop, will return
the given values one by one.
xtable.tuple.keep(count,...)
Returns count arguments, starting at the first extra argument. As in
the case of select, a negative number indexes from the end (-1 is the
last argument).
xtable.tuple.map(ft,...)
Each return value is the result of ft applied to the corresponding
value in the tuple.
"Applying" means indexing if ft is a table and calling if ft is a
function, which is assumed to be unary with one return value.
xtable.tuple.collect(...)
Concatenates all its arguments, respecting metamethods.