读书人

Lua基础 函数(1)

发布时间: 2013-03-10 09:38:39 作者: rapoo

Lua基础 函数(一)

在Lua中,函数是对语句和表达式进行抽象的主要方法。既可以用来处理一些特殊的工作,也可以用来计算一些值。下面有3个例子,分别将函数当作一条语句;当作表达式(后面两个是一类)。

function Window (options)-- check mandatory optionsif type(options.title) ~= "string" thenerror("no title")elseif type(options.width) ~= "number" thenerror("no width")elseif type(options.height) ~= "number" thenerror("no height")end-- everything else is optional_Window(options.title,options.x or 0,                     -- default valueoptions.y or 0,                     -- default valueoptions.width, options.height,options.background or "white",      -- defaultoptions.border                      -- default is false (nil))end



水平有限,如果有朋友发现错误,欢迎留言交流。




读书人网 >互联网

热点推荐