- 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)
推薦閱讀
- Design Principles for Process:driven Architectures Using Oracle BPM and SOA Suite 12c
- Learning Real-time Processing with Spark Streaming
- C語言程序設計(第2 版)
- Java高手真經(高級編程卷):Java Web高級開發技術
- Java應用開發與實踐
- HBase從入門到實戰
- 分布式數據庫原理、架構與實踐
- Emotional Intelligence for IT Professionals
- Hands-On Robotics Programming with C++
- Software-Defined Networking with OpenFlow(Second Edition)
- RESTful Web API Design with Node.js
- The Applied Data Science Workshop
- Visual FoxPro程序設計實驗教程
- Instant AppFog
- Mathematica Data Visualization