Lua is not like many other "all-inclusive" languages, including many functions, such as network communications, graphical interfaces, and so on. But Lua can easily be extended by hosting languages (usually C or C + +), which Lua can use as if it were built in. LUA consists only of a streamlined core and most basic library. This allows LUA to be small and fast to be embedded in other programs. As a result, there are no more system functions in LUA than in other languages. Accustomed to the string-splitting function of other languages, and is written on its own, recorded here, ready to use.
Below is a brief introduction to LUA:
Lua is a compact scripting language. The author is Brazilian. The language is designed to embed applications, providing flexible extensions and customization capabilities for applications.
The Lua script can be easily invoked by C + + code, or it can call C + + functions in turn, allowing Lua to be widely used in applications. Not only as an extension script, but also as a normal configuration file, instead of Xml,ini and other file formats, and easier to understand and maintain.
LUA is written by standard C and is simple and graceful, and can be compiled and run almost on all operating systems and platforms.
A complete LUA interpreter but 200k, Lua is the fastest in all of the current scripting engines. All of this determines that LUA is the best choice for embedded scripting.
Copy Code code as follows:
function Split (str, Delim, MAXNB)
--Eliminate bad cases ...
If String.find (str, delim) = = Nil Then
return {str}
End
if maxnb = = Nil or maxnb < 1 Then
MAXNB = 0--No limit
End
Local result = {}
Local Pat = "(.-)". Delim.. "()"
Local NB = 0
Local Lastpos
For part, Pos. String.gfind (STR, PAT) do
NB = NB + 1
RESULT[NB] = part
Lastpos = pos
If NB = = Maxnb then break end
End
--Handle the last field
If NB ~= MAXNB then
RESULT[NB + 1] = string.sub (str, lastpos)
End
return result
End