1.指定参数的名字
--表构造器,()可有可无.
rename{old="temp.lua",new="temp1.lua"}
如果需要指定参数的名字,可以通过传入表的方式进行传参。
function rename(arg)
return os.rename(arg.old,arg.new)
end
另外一个例子:
x = Window{x=0,y=0,width=30,height=200,title="Lua",background="blue",border=true}
function Window(options)
--check mandatory options
if type(options.title) ~= "string" then
error("no title")
elseif type(options.width) ~="number" then error("no width")
elseif type(options.height)~= "number" then error("no height")
end
---everything else is optional
_Window(options.title,
options.x or 0 ---default value
options.y or 0 ---default value
options.width, options.height,
options.background or "white", --default
options.border --default is false(nil)
)
end