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

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)
主站蜘蛛池模板: 虞城县| 紫阳县| 上虞市| 浦东新区| 大荔县| 扬州市| 雷州市| 嘉义市| 浙江省| 双流县| 申扎县| 花莲县| 南开区| 北辰区| 麦盖提县| 莎车县| 沙洋县| 平南县| 北海市| 鹿邑县| 枣庄市| 于都县| 裕民县| 景泰县| 赞皇县| 开阳县| 上林县| 安龙县| 罗定市| 阿荣旗| 视频| 洪泽县| 铁岭市| 盈江县| 项城市| 商南县| 长泰县| 松桃| 怀化市| 娱乐| 舒城县|