Lua file Refresh
function require_ex (_mname) if "" then return End if package.loaded[_mname] Then end = nil require ( _mname) End
Lua String Segmentation
function Split (szfullstring, szseparator) local Nfindstartindex=1Local Nsplitindex=1Local Nsplitarray= {} while true DoLocal Nfindlastindex=string. Find (Szfullstring, Szseparator, Nfindstartindex)ifNot Nfindlastindex then Nsplitarray[nsplitindex]=string. Sub (szfullstring, Nfindstartindex,string. Len (szfullstring)) BreakEnd Nsplitarray[nsplitindex]=string. Sub (szfullstring, Nfindstartindex, Nfindlastindex-1) Nfindstartindex= Nfindlastindex +string. Len (szseparator) Nsplitindex= Nsplitindex +1EndreturnNsplitarray End
Traversing LUA arrays
method One, you can use for to traverse: [CPP] View plaincopy on code to see the snippet derived from my Code slice DoTable_week= { "W", "e", "R", "T", "y", "u", "I", } fori =1, #table_week Do Print(Table_week[i])End End#followed by an array or tabe to traverse it, I is the starting subscript of the table or array. Method 2:[cpp] View plaincopy on code to see a snippet derived from my Code slice DoTable_week= { "W", "e", "R", "T", "y", "u", "I", } forI, Vinch Pairs(Table_week) Do Print(i)End EndThis is traversed in the way of iterators, I is subscript, V is the value of table or array. Way 3:[cpp] View plaincopy on code to see a snippet derived from my Code slice DoTable_week= { "W", "e", "R", "T", "y", "u", "I", } forIinch Pairs(Table_week) Do Print(i); End EndI is the subscript for table or array. Way 4:[cpp] View plaincopy on code to see a snippet derived from my Code slice DoTable_view= { "W", "e", "R", Color1="Red", Color2="Blue", {"A1","A2","A3"}, {"B1","B2","B3"}, {"C1","C2","C3"}, } forI, Vinch Pairs(Table_view) Do if type(v) = ="Table" Then forNew_table_index, New_table_valueinch Pairs(v) Do Print(New_table_value)End Else Print(v)End End EndNote:type(v) Function: Returns the type name of the parameter ("Nil"," Number","string","Boolean","Table","function","Thread","UserData")
Lua Part Tips