[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: [Suggestion] List Data Type?
- From: "Patrick Donnelly" <batrick.donnelly@...>
- Date: Tue, 20 Nov 2007 18:36:18 -0700
I was thinking about a problem that seemed to be just a lacking
feature of Lua. If you have a function that returns a variable number
of arguments, the only way to process those arguments is to pass them
as arguments to a vararg function, or create a new table. I was
thinking of something like a list data structure that could be added
to Lua to contain these arguments and keep them on the stack. I
envision it working as such:
list a = somevariablesfunc()
Perhaps my understanding of the Lua stack is limited but I would see
it working as list being a local variable that refers to the stack
location where somevariablesfunc()'s return values are placed. The
local would refer specifically to the "top" of the return values, the
number of the return values. Basically what's put on the stack is
This leaves a couple questions that I've been thinking about:
1) Should the list be passed as a list to other functions or be
"unpacked" before calling the function.
2) What happens with lists and closures?
I think that the list should always be unpacked when being referred to
as in callnewfuncwithlist(a), i.e. the list itself is not passed, but
If a new closure is made inside the function referencing the list,
then it should be dealt with the same as with all locals and put on
My last comment is that because a local value will reference the list
location on the stack, it can be properly destroyed when the function
Mainly I'm wondering what you guys think. I feel that Lua has so much
potential with variable arguments being passed around, but tables or
making specific functions for processing variable arguments seems
incredibly awkward, tables being expensive if done constantly, and
functions being expensive because of multiple calls to select(). A
list on the stack seems like the most logical and efficient solution.
"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."