首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 互联网 >

Lua基础 函数(1)

2013-03-10 
Lua基础 函数(一)在Lua中,函数是对语句和表达式进行抽象的主要方法。既可以用来处理一些特殊的工作,也可以

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



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




热点排行