2 ----------------------------------------------------------------------
3 ----------------------------------------------------------------------
5 -- String module extension
7 ----------------------------------------------------------------------
8 ----------------------------------------------------------------------
10 -- Courtesy of lua-users.org
11 function string.split(str, pat)
13 local fpat = "(.-)" .. pat
15 local s, e, cap = string.find(str, fpat, 1)
17 if s ~= 1 or cap ~= "" then
21 s, e, cap = string.find(str, fpat, last_end)
23 if last_end <= string.len(str) then
24 cap = string.sub(str, last_end)
30 -- "match" is regularly used as a keyword for pattern matching,
31 -- so here is an always available substitute.
32 string.strmatch = string["match"]
34 -- change a compiled string into a function
35 function string.undump(str)
36 if str:strmatch '^\027LuaQ' or str:strmatch '^#![^\n]+\n\027LuaQ' then
37 local f = (lua_loadstring or loadstring)(str)
40 error "Not a chunk dump"