Can`t move values from local arg table to other one.

Post Reply
User avatar
Andrey01
Member
Posts: 2577
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Can`t move values from local arg table to other one.

by Andrey01 » Post

Why can i not move values from local "arg" table that takes alll values are hiden in (...) from parameters function to other table?
For example:

Code: Select all

function func(...)
args_list = arg 
for i, v in pairs(args_list) do -- Here args_list gets nil somewhy
--some code
And i get bad arguement #1 to 'pairs' (table expected, got nil) when the loop is trying to run "args_list" table.

User avatar
AspireMint
Member
Posts: 415
Joined: Mon Jul 09, 2012 12:59
GitHub: AspireMint
IRC: AspireMint
In-game: AspireMint
Location: Stuck at spawn

Re: Can`t move values from local arg table to other one.

by AspireMint » Post

Try args_list = {...}

User avatar
Andrey01
Member
Posts: 2577
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Re: Can`t move values from local arg table to other one.

by Andrey01 » Post

AspireMint wrote:Try args_list = {...}
I`ve already tried, but it doesn`t work, either :/

User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Can`t move values from local arg table to other one.

by rubenwardy » Post

Code: Select all

local args_list = table.pack(...)
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
AspireMint
Member
Posts: 415
Joined: Mon Jul 09, 2012 12:59
GitHub: AspireMint
IRC: AspireMint
In-game: AspireMint
Location: Stuck at spawn

Re: Can`t move values from local arg table to other one.

by AspireMint » Post

https://www.lua.org/cgi-bin/demo

Code: Select all

function fun(...)
   local args_list = table.pack(...)
   for k,v in pairs(args_list) do
      print(v)
   end
end
fun(1,2,3)
output: 1,2,3,3
last number must be size, correct me if im wrong

Code: Select all

function fun(...)
   local args_list = {...}
   for k,v in pairs(args_list) do
      print(v)
   end
end
fun(1,2,3)
output: 1,2,3
Last edited by AspireMint on Mon Jun 18, 2018 20:04, edited 1 time in total.

User avatar
Andrey01
Member
Posts: 2577
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Re: Can`t move values from local arg table to other one.

by Andrey01 » Post

Thanks everyone!

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests