lua-users home
lua-l archive

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


Try ipairs({...}) instead of ipairs(arg).  You access the vararg list
as ... instead of arg since Lua 5.1 and it is a list, not a table so
you need to pack it inside one if you're going to feed it to ipairs.
If using Lua 5.2 you can also do table.pack(...) instead.

Dimitris

On Mon, Jun 4, 2012 at 3:50 PM, Hamed Rafi <Hamed.Rafi@axellwireless.com> wrote:
> Hi,
>
>
>
> Consider the code:
>
>
> function p(...)
>
> print(...)
>
> str=""
>
> for a,b in ipairs(arg)do
>
> str=str..b.." "
>
> print(a)
>
> end
>
> print(str)
>
> end
>
>
>
> and then calling:
>
> p(1,2,3,4)
>
>
>
> will print the following as expected from call to print in first line
>
>   1 2 3 4
>
>
>
>
>
> And then returns with the following error
>
> stdin:1: bad argument #1 to 'ipairs' (table expected, got nil)
>
> stack traceback:
>
> [C]: in function 'ipairs'
>
> stdin:1: in function 'p'
>
> stdin:1: in main chunk
>
> [C]: ?
>
>
>
> This function works fine if I remove the print(…) in the first line.
>
> I am using lua 1.4 and tested this in Ubuntu-64 11.10 and Windows 7 64-bit
>
>
>
> Can anyone help me on this  issue please?
>
>
>
> Regards,
>
> Hamed Rafi
>
>
>
> CONFIDENTIALITY NOTICE: This message (including any attached files) is
> intended only for the designated recipient(s). It may contain confidential
> and/or proprietary information and should be deemed as being subject to
> applicable confidentiality protections. If you are not a designated
> recipient, you may not review, use, copy or distribute this message. If you
> receive this message in error, please notify the sender by reply e-mail and
> then delete this message. Thank you.