Skip to content

Instantly share code, notes, and snippets.

@whitemuu
Last active March 23, 2020 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whitemuu/695e7fd7bb69189e57e22be3046b58e4 to your computer and use it in GitHub Desktop.
Save whitemuu/695e7fd7bb69189e57e22be3046b58e4 to your computer and use it in GitHub Desktop.

不是不可以提前声明,而是不需要,你看是不是?

以下代码并不会报错

function main()
  aaa()
end

function aaa()
  return 2;
end

main()

那么为什么你的需求是不合理的呢? lua里函数和变量一样是一等公民,你会希望下面的代码打印出10来吗? 顺序是重要的语义。

i = nil
print(i)
i = 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment