lua-users home
lua-l archive

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


On Thu, Dec 8, 2011 at 20:25, Xavier Wang <weasley.wx@gmail.com> wrote:
> Maybe you can do something like this:
>
> function Test(s, a, ...)
>  -- do something to calculate the first field
>  local ret = --....
>  return ret, Test(s, ...)
> end
>
>
> ---------- Forwarded message ----------
> From: PROXiCiDE <saiyuk7@gmail.com>
> Date: 2011/12/9
> Subject: Returning a ellipses
> To: lua-l@lists.lua.org
>
>
> I want to pass a function that supports
> ellipses "..." and return several of
> them into different variables..
>
> example
>
> function Test(...)
> end
>
> a,b,c,d,e = Test(1,2,3,4,5)
>
> Reason for this being, i want to be able to
> read a structured data into variables...
>
> example reason
>
> magic,version, headersize,directorycount,directorylocation =
> ReadDirectory(f,"s",16,32,32,32)
>
> S = obviously a String
> 16 = Int16
> 32 = Int32
>
> I would actually parse the the ellipses using the
> "var = select(i,...)" from a "for" statement
>
> But what i cant understand is how do i seperate
> these into different variables
> that are returned
>

It sounds like you want to do something like:
local args = {n=select('#', ...), ...)
--do things with args[]
return unpack(args, 1, args.n)

-- 
Sent from my toaster.