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

  • 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)
主站蜘蛛池模板: 镇赉县| 图片| 肇东市| 忻城县| 巴青县| 拜泉县| 开化县| 嘉义县| 吴旗县| 巴彦县| 若尔盖县| 秭归县| 无锡市| 元谋县| 缙云县| 吉水县| 仙游县| 房产| 泾阳县| 镇雄县| 云南省| 瓮安县| 来安县| 屯门区| 项城市| 延吉市| 二手房| 基隆市| 盘锦市| 江都市| 仲巴县| 从化市| 双柏县| 祁连县| 浙江省| 临洮县| 龙江县| 门源| 江永县| 平定县| 余姚市|