- 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)
推薦閱讀
- Vue 3移動Web開發與性能調優實戰
- Arduino by Example
- Mastering Entity Framework
- Scratch 3.0少兒編程與邏輯思維訓練
- Quarkus實踐指南:構建新一代的Kubernetes原生Java微服務
- JavaScript動態網頁開發詳解
- Scala編程實戰(原書第2版)
- Unity UI Cookbook
- Android Wear Projects
- Vue.js 2 Web Development Projects
- 大話Java:程序設計從入門到精通
- JavaScript腳本特效編程給力起飛
- C語言程序設計與應用(第2版)
- 自學Python:編程基礎、科學計算及數據分析(第2版)
- 原型設計:打造成功產品的實用方法及實踐