我第一次涉足lua,这只是行不通.它说我试图调用全局exiter(零值).我只是在做一个简单的程序来尝试让函数工作. print("hello world")io.read()y = 0while y 10 do local x = "" print("hello world") x = io.read()
print("hello world") io.read() y = 0 while y < 10 do local x = "" print("hello world") x = io.read() if x == "y" then y = exiter(1) print(y) end end function exiter(param) local q = 0 print ("hello again") q = param * 10 return q; endLua程序从上到下逐个语句执行.因此,当你进入while循环时,函数exiter还没有出现.在进入循环之前定义它:
function exiter(param) local q = 0 print ("hello again") q = param * 10 return q; end while y < 10 do local x = "" print("hello world") x = io.read() if x == "y" then y = exiter(1) print(y) end end