functionlua_union (union_source,union_target)if type(Union_source) ~='Table' or type(Union_target) ~='Table' Then return {}; End; if# (Union_source) = =0 and# (Union_target) = =0 Then return {}; End; forI=1, # (Union_target) Do Localflag=true; forj=1, # (Union_source) Do ifUNION_TARGET[I]==UNION_SOURCE[J] ThenFlag=false; Break; End; End; ifflag==true Then Table.insert(Union_source,union_target[i])End; End; returnUnion_source;End;functionLua_diff (diff_source,diff_target)if type(Diff_source) ~='Table' or type(Diff_target) ~='Table' Then return {}; End; if# (Diff_source) = =0 and# (Diff_target) = =0 Then return {}; End; fori=# (Diff_source),1,-1 Do forj=1, # (Diff_target) Do ifDIFF_SOURCE[I]==DIFF_TARGET[J] Then Table.remove(Diff_source,i); End; End; End; returnDiff_source;End;functionlua_distinct (Distinct_source)if type(Distinct_source) ~='Table' Then return {}; End; forI=1, # (Distinct_source) Do forj=# (Distinct_source), i+1,-1 Do ifDISTINCT_SOURCE[I]==DISTINCT_SOURCE[J] Then Table.remove(DISTINCT_SOURCE,J); End; End; End; returnDistinct_source;End;functionLua_inter (inter_source,inter_target)if type(Inter_source) ~='Table' or type(Inter_target) ~='Table' Then return {}; End; fori=# (Inter_source),1,-1 Do forj=1, # (Inter_target) Do ifINTER_SOURCE[I]==INTER_TARGET[J] Then Table.remove(Inter_source,i); End; End; End; returnInter_source;End;LocalResult1=lua_union ({},{3,3});LocalResult2=lua_diff ({1,2,3,4,5},{2,3});LocalResult3=lua_distinct ({1,1,2,1}) ;LocalResult4=lua_inter ({1,2,3,4,5},{1,2});
Implementation of Union,diff,inter,distinct method for the int array in LUA