Lua编程遇到的错误1

来源:互联网 发布:博微设计软件 编辑:程序博客网 时间:2024/06/04 18:58

Lua入门错误

--example1@luaw= Windows{    x=0, y=0, width=300, height=200,     title = "lua",background="blue",     border= true}function  Windows( 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")    else        print("输入无错")    endend

运行后,cmd提示attempt to call golbal 'Windows'(a nil value)
隐约觉得是不是和函数定义有关,函数定义先于使用
换为如下代码,程序正常运行

--example1function  Windows( 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")    else        print("输入无错")    endendw= Windows{    x=0, y=0, width=300, height=200,     title = "lua",background="blue",     border= true}

但是,定义也未必先于使用

定义一个不带参数的函数,是可以不用放在调用该函数语气的前面的,带参数就不行了

原创粉丝点击