Lua脚本语言入门代码

710 词

近来游戏基本做的差不多了,大约5月底左右可以内测?现在正在快马加鞭增强其脚本功能.考虑到效率和库大小,功能等原因,暂决定使用<魔兽世界>采用的Lua语言进行嵌入支持.5555,我可爱的Python和Ruby没被采用,怨念啊…下面是学习的一些代码,均在LuaEdit5.0上运行通过.

--> 实验类型

print( type("HelloWorld") );
print( type(10.4 * 3) );
print( type(print) );
print( type(type) );
print( type(true) );
print( type(nil) );
print( type(type(x)) );

print("-------------------------------")
--> 实现同一变量对应多种类型

print( type(a) )
a = 10
print( type(a) )
a = "a string!!"
print( type(a) )
a = print
a( type(a) )

print("-------------------------------")
--> 实现字符串部分替代保存和部分特殊转义符

a = "My game is n"'sobso good" ;
b = string.gsub( a, "ga", "ha" );
print( a );
print( b );

print("-------------------------------")
--> 实现Asc码和字符之间的替换表示

print("