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

  • Lua Quick Start Guide
  • Gabor Szauer
  • 159字
  • 2021-08-05 10:30:39

Defining a function

A function declaration starts with the function keyword. After the function keyword, you provide the function name. The name of the function follows the same naming rules as the name of a variable.  

After the name of your function, you have to provide a list of parameters. Parameters are variable names enclosed in parentheses (). The list of parameters may be empty if a function needs no parameters, in which case only opening and closing parentheses are given—().

Once you have declared the list of parameters, you may write the body of the function. The function body is a chunk of code, so like other chunks you need to close the body with the end keyword. The following code demonstrates a simple function:

function PrintSomething()
text1 = "hello"
text2 = "world"
print (text1 .. ", " .. text2)
end

This function definition can be broken down into the following parts:

主站蜘蛛池模板: 阿巴嘎旗| 邵阳县| 黑山县| 泉州市| 武川县| 台东市| 班戈县| 曲阜市| 利津县| 肃北| 湖口县| 黑河市| 资兴市| 游戏| 樟树市| 修水县| 天台县| 濮阳县| 易门县| 新宾| 大安市| 浦城县| 莱阳市| 许昌县| 遂川县| 茌平县| 常德市| 德江县| 勃利县| 饶阳县| 岱山县| 华亭县| 桃江县| 故城县| 崇仁县| 随州市| 保山市| 定西市| 兖州市| 碌曲县| 临沂市|