- 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)
推薦閱讀
- 軟件安全技術
- .NET之美:.NET關鍵技術深入解析
- 軟件項目估算
- 新手學Visual C# 2008程序設計
- YARN Essentials
- MySQL數據庫管理與開發實踐教程 (清華電腦學堂)
- Hands-On Reinforcement Learning with Python
- Learning JavaScript Data Structures and Algorithms
- ASP.NET程序開發范例寶典
- Clojure for Java Developers
- Learning JavaScript Data Structures and Algorithms(Second Edition)
- 跟戴銘學iOS編程:理順核心知識點
- Exploring SE for Android
- Instant GLEW
- Building Clouds with Windows Azure Pack