[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Opposite of unpack?
- From: "Javier Guerra" <javier@...>
- Date: Thu, 17 Jul 2008 11:43:49 -0500
On Thu, Jul 17, 2008 at 11:39 AM, Eduardo Ochs <eduardoochs@gmail.com> wrote:
> A question, then:
>
> Will there still be some way to write a function f, in pure Lua, that
> distinguishes if it was called as f(1, 2, nil) or as f(1, 2), after
> "arg" has been deprecated?
function f(...)
print (select("#",...))
end
f(1,2)
=> 2
f(1,2,nil)
=> 3
>
> On Thu, Jul 17, 2008 at 12:30 PM, Eike Decker <eike@cube3d.de> wrote:
>> As far as I know, this is deprecation and depends on how the lua interpreter was
>> compiled.
>>
>> Eike
>>
>>> Hi Michael,
>>>
>>> pack = function (...) return arg end
>>>
>>> Cheers,
>>> Eduardo Ochs
>>> http://angg.twu.net/
>>>
>>> On Thu, Jul 17, 2008 at 12:06 PM, Michael Gerbracht <smartmails@arcor.de>
>>> wrote:
>>> > Sorry for this really simple question but at the moment I can not find the
>>> > answer by myself although I think it's really simple. If I have a function
>>> > that returns more than one value - how do I get them into a table? I need
>>> > something like this:
>>> >
>>> > function test()
>>> > result = some table of results
>>> > return unpack(result)
>>> > end
>>> >
>>> > local t = {}
>>> > t = pack(test())
>>> > print(t[2])
>>> >
>>> > Unfortunately there is no pack command, but I am sure it can be done
>>> > somehow. Please assume that I can't change the function itself, otherwise
>>> > the best solution would be to change the function to "return result" of
>>> > course ;-)
>>> >
>>> > Thanks,
>>> > Michael
>>> >
>>> > --
>>> > ...using RiscLua 4.14, built from Lua 5.1.3
>>> >
>>>
>>
>>
>>
>>
>
--
Javier