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

  • Lua Quick Start Guide
  • Gabor Szauer
  • 131字
  • 2021-08-05 10:30:40

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)
主站蜘蛛池模板: 邯郸市| 岱山县| 林西县| 永济市| 寻乌县| 原阳县| 福清市| 平阳县| 六安市| 泗阳县| 板桥市| 奇台县| 赫章县| 宁都县| 巴林右旗| 定西市| 大渡口区| 琼中| 丘北县| 长垣县| 云龙县| 新密市| 玉田县| 安顺市| 泰州市| 大冶市| 沧州市| 建水县| 静海县| 耒阳市| 广河县| 本溪市| 南汇区| 安化县| 玉树县| 北辰区| 北京市| 卢龙县| 基隆市| 昌邑市| 成都市|