AAuto的table用法测试
//打开控制台
io.open()
t={};
//table插入元素
table.insert(t,"windows");
table.insert(t,"linux");
table.insert(t,"unix");
for(k,v in t){
io.print(v);
}
t1={};
t1[1]=11;
t1[2]=22;
t1[3]=33;
//范型输出table元素
for(k,v in t1){
io.print(v);
}
t2={};
t2["windows"]=100;
t2["linux"]="字符串200";
io.print(t2["windows"]);
io.print(t2["linux"]);
t2.windows="字符串100";
io.print(t2.windows);
//删除一键值对
t2.windows=nil;
io.print(t2.windows);
//table定义时赋初值
t3={13;55;"windows";66;"blue8";77};
for(k,v in t3){
io.print(k,v);
}
//取table的范围
min,max=table.range(t3);
io.print("min=",min);
io.print("max=",max);
//插入元素
table.insert(t3,"猪悟能",2);
for(k,v in t3){
io.print(k,v);
}
//table实现堆栈操作
t4={};
table.push(t4,11);
table.push(t4,22);
table.push(t4,33);
//table.push(t4,11,22,33);
min,max=table.range(t4);
for(i=1;max;1){
io.print(table.pop(t4,1));
}
//遍历数组
t5={"C语言";"E语言";"Delphi语言";"AAuto语言"};
/*for i=1;#t5;1{
io.print(t5[i]);
}*/
for(i=1;#t5;1){
io.print(t5[i]);
}
//上面注释的for也是正确的写法
io.print("");
//范型循环处理稀疏数组
t6={"猪悟能";"哆啦A梦";500;501;502;0x55;blue8=333};
t6[1000]=555;
for(k,v in t6){
if(type(v)==type.number)
{
io.print(k,v);
}
}
//数组排序
t7={22;55;81;7;99;51;72;9};
//排序前
io.print("");
for(k,v in t7){
io.print(k,v);
}
//排序后
io.print("");
table.sort(t7);
for(k,v in t7){
io.print(k,v);
}
io.print("");
//字典的处理
t8={aa=11;bb=22;cc=33};
t8["dd"]=44; //添加一个键值对
for(k,v in t8){
io.print(k,v);
}
io.print("");
t8.猪悟能=55; //添加键值对
for(k,v in t8){
io.print(k,v);
}
// 将table对象序列化为代码字符串
str=table.tostring(t8);
io.print(str);
io.print("");
//io.print(t[1]);
io.stdin.read();
io.close();