function split(s, delim) then return end local t = {} while true do local pos = string.find (s, delim, start, true) -- plain find if not pos then break end )) start = pos + string.len (delim) end table.insert (t, string.sub (s, start)) return t end
function count( ... ) return function( ... ) i = i+ return i end end local func = count(...) print(func()) print(func()) print(func()) 结果如下: [Finished .1s] lua 闭合函数:一个函数加上该函数所需访问的所有“非局部变量”. 如上所示:count()函数返回了另一个函数,而这个函数使用了count()函数中的局部变量.当该函数被调用时,coun
一个是分割,一个是连接. 惯例,先看内部帮助文档 Help on method_descriptor: join(...) S.join(iterable) -> string Return a string which is the concatenation of the strings in the iterable. The separator between elements is S. (END) 将可迭代对象(包含的应该是str类型的,不然会报错)连接起来, 返回值是str,用法如