官术网_书友最值得收藏!

Function arguments

Functions can take arguments. An argument is some data that will be passed into the function. You have passed arguments to the print function before; it takes a single string argument. Calling print with an argument looks like this: print ('hello, world').

When you declare a function, you can place one or more variable names inside the parentheses that are used during the function declaration. These variables are the function arguments; they have a scope local to the function.

The following function takes in two numbers and adds them together:

-- Declare the function, takes two arguments
function AddAndPrint(x, y)
local result = x + y;
print (x .. "+" .. y .. "=" .. result)
end

-- Call the function a few times
AddAndPrint(2, 3)
AddAndPrint(4, 5)
AddAndPrint(6, 7)
主站蜘蛛池模板: 菏泽市| 太仆寺旗| 辛集市| 沙湾县| 陆川县| 台北市| 秦皇岛市| 长海县| 莫力| 夹江县| 呼玛县| 临漳县| 洞口县| 库车县| 汨罗市| 巴里| 贺兰县| 桃源县| 博乐市| 富平县| 克山县| 新蔡县| 木里| 金华市| 文登市| 马关县| 新乐市| 林芝县| 公主岭市| 双牌县| 丹寨县| 宜丰县| 江西省| 曲水县| 鸡西市| 碌曲县| 错那县| 安徽省| 四川省| 通山县| 平原县|