高速体験、学習lua(c++,c#,android,object-cなどを埋め込み、ホット更新をサポートするスクリプト)のエントリーデバッグシリーズ(1)

27405 ワード

--     
--[[
    :lua    ,  ,    
    :2020-6-12
   :pcw
--]]
--【       】
print("--------------------------------");
print("configlab")
print(b);--  :nil
print(type(b));--  :nil
print((type(b)=="nil")) --  :true
b=23.5
print(b);
print(type(b));--  :number
print("--------------------------------");
print([[
    
  lua        ,         
]]);--        
print("config   ="..#"config");
print("--------------------------------");
--【  】
p1=2;--   
local p2=2;--    
function testparam()
    p3=2;
    local p4=3;
end
testparam();
print(p1,p2,p3,p4);--     
if(true) then
   local p1=3;--
   p2=3;--    
end
print(p1,p2);
print("--------------------------------");
--【  】
pr1,pr2=20,"abc"; --
print(pr1,pr2);
print(type(pr1),type(pr2));
print("--------------------------------");
--【    】
if(0) then
   print("if 0  true");
end
if(nil) then
   print("if nil  true");
else
   print("if nil  false");
end
print("--------------------------------");
--【table 】
table1={username="user798",group="2  "}
print(type(table1));
for k1,v1 in pairs(table1)  do
  print(k1.."-"..v1);
 end;
 print("--------------------------------");
--【local   table】
local table2={};
table2["k2"]="v2";
k3=10;
table2[k3]=20;
table2[k3]=table2[k3]+20;
for k2,v2 in pairs(table2) do
   print (k2.."-"..v2);
end;
print("--------------------------------");
--【local        table 】 (lua      1  ,    0  )
local table3={"  ","  ","  "};
for k3,v3 in pairs(table3) do
  print (k3.."-"..v3);
end;
print("--------------------------------");
--【  】
function  getSqure(n,IsSorV)
   if(IsSorV==true) then
      return n*n;
   else
       return n*n*n
   end
end;
print("s="..getSqure(3,true));
print("v="..getSqure(3,false));
print("--------------------------------");
--【    】(          ,       return  ,     )
function dynamicProcess(n,IsSorV,inputFun)
    return inputFun(n,IsSorV)
end

print("      s="..dynamicProcess(4,true,
function(n,IsSorV)
  if(IsSorV==true) then
      return n*n;
   else
       return n*n*n
   end
end
));--  :      s=16
print("--------------------------------");
--【       】
print("           ");
s_begin,s_end=string.find("http://www.cnblogs.com/taohuadaozhu",":");
print(s_begin,s_end);
s_begin,s_end=string.find("http://www.cnblogs.com/taohuadaozhu","taohuadaozhu");
print(s_begin,s_end);
print("--------------------------------");
--【    】
function average(...)
  local args={...};
  local result=0;
  for i,v in ipairs(args) do
     result=result+v;
   end
   return result/#args;--#args          
end


print("    average(1,2,3)="..average(1,2,3));
print("--------------------------------");
--【for  】

function fortest(...)
   for iIndex3=1,select("#",...) do   --       1  ,      
      local arg=select(iIndex3,...);
      print("for  test="..arg);
   end
end

fortest(3,6,9,12);
print("--------------------------------");
--【   】
if(1~=2) then
  print("1!=2     1~=2");
end

print("--------------------------------");
--【    】
bool1=true;
bool2=false;
if(bool1 or bool2) then
    print("bool1 or bool2    if ");
end
if(bool1 and bool2) then
    print("bool1 and bool2    if ");
    else
      print("bool1 and bool2      if ");
    end


if(not bool2) then
    print("not bool2     if ");
end

print("--------------------------------");
--【while  】
i1=0;
while(i1<5) do
  print(" "..i1.."   ");
  i1=i1+1;--   i1++    .
end;
print("--------------------------------");
--【     continue,      】(repeat  until true,           ).
i2=0;
while(i2<3) do
  print("  i2="..i2..",loop.begin");
  repeat
     if i2%2==0 then
         print("  i2="..i2..",  4        ,  continue   ");
         i2=i2+1;--   i2++    
         break
     else
       print("  i2="..i2..",loop.end");
        i2=i2+1;--   i2++    
     end

  until true
end
print("--------------------------------");
--[[   continue   :
  i2=0,loop.begin
  i2=0,  4        ,  continue   
  i2=1,loop.begin
  i2=1,loop.end
  i2=2,loop.begin
  i2=2,  4        ,  continue   
]]
print("--------------------------------");
--【    】
date = 2; month = 1; year = 2020
print(string.format("      %02d/%02d/%03d", date, month, year))
--  (thread)         ,  (coroutine)            ,      
--userdata(     ):     c,c++               userdata



 
次は結果です.
configlab
nil
nil
true
23.5
number
--------------------------------
こんにちは
luaは不思議なもので、多くの言語に埋め込むことができます.
 
configの長さ=6
--------------------------------
222nil
23
--------------------------------
20abc
numberstring
--------------------------------
if中0はtrueを表す
ifのnilはfalseを表します
--------------------------------
table
username-user798
group-2年生
--------------------------------
10-40
k2-v2
--------------------------------
1-中国
2-米国
3-ドイツ
--------------------------------
s=9
v=27
--------------------------------
匿名関数計算s=16
--------------------------------
体験関数を開始して複数の値を返す
55
2435
--------------------------------
可変パラメータaverage(1,2,3)=2
--------------------------------
forループtest=3
forループtest=6
forループtest=9
forループtest=12
--------------------------------
1!=2の式は1~=2
--------------------------------
bool 1 or bool 2はifに該当します
bool 1 and bool 2がifに合致しない
not bool 2はifの
--------------------------------
0回目の出力
第1回出力
2回目の出力
3回目の出力
4回目の出力
--------------------------------
現在i 2=0,loop.begin
現在のi 2=0は、4の倍数に遭遇しても下に行かないcontinueのような効果があります.
現在のi 2=1,loop.begin
現在のi 2=1,loop.end
現在i 2=2,loop.begin
現在のi 2=2は、4の倍数に遭遇しても下に行かず、continueのような効果があります.
--------------------------------
--------------------------------
日付フォーマット02/01/2020