2.types and values
lua是动态类型语言,变量不要类型定义.lua中有8个基本类型:nil, boolean, number, string, userdata, function, thread, and table. 【程序编程相关:J2MEGame开发笔记-尝试IO优化】 【推荐阅读:遊戲開發心得(2)】 print(type("hello world")) --> string 【扩展信息:J2MEGame开发笔记-压缩还是不压缩】 print(type(10.4*3)) --> number print(type(print)) --> function print(type(type)) --> function print(type(true)) --> boolean print(type(nil)) --> nil print(type(type(x))) --> string 变量没有预定义的类型,每一个变量都可能包含任一种类型的值. print(type(a)) --> nil (`a is not initialized) a = 10 print(type(a)) --> number a = "a string!!" print(type(a)) --> string a = print -- yes, this is valid! a(type(a)) --> function 注意上面最后两行,我们可以使用function像使用其他值一样使用.一般情况下同一变量代表不同类型的值会造成混乱,最好不要用,特殊情况下可以带来便利,比如nil. 2.1 nil:lua中特殊的类型,给全局变量负nil可以删除该变量. ... 下一页