标签:
1 function concatenate (...) 2 local s = "" 3 for i, v in ipairs{...} do 4 s = s .. v 5 end 6 return s 7 end
1 -- print all elements in array 2 function print_array (array) 3 for key, value in pairs(array) do 4 print("key: " .. key .. " --> value: " .. value) 5 end 6 end 7 8 arr = {name = "alice", age = 18} 9 print_array(arr) 10 11 -- if the function has one single argument and that argument is 12 -- either a literal string or a table constructor, then the parentheses 13 -- is optional. 14 print_array{name = "tom", age = 20}
1 -- receive an arbitrary number of values and 2 -- return all of them, except the frist one 3 function remove_first(first, ...) 4 return ... 5 end 6 7 // test 8 print(remove_first("abc", "def", "hij"))
标签:
原文地址:http://www.cnblogs.com/90programmer/p/5624973.html