A
local file = gg.EXT_STORAGE..'/xxml.txt'
local links = {}
if io.open(file,"r") then
for line in io.lines(file) do
_, links[#links+1], _ = line:match("(<Key>)(.-)(</Key>)")
end
end
print(links)
Size: a a a
A
local file = gg.EXT_STORAGE..'/xxml.txt'
local links = {}
if io.open(file,"r") then
for line in io.lines(file) do
_, links[#links+1], _ = line:match("(<Key>)(.-)(</Key>)")
end
end
A
A
S
(<Key>)(.*?)(<\/Key>)
<Key>(.-)</Key>
Можно использовать и в match и в gmatch.S
S
html = [[
<html>
<div>
<div>
</div>
<span/>
</div>
</html>
]]
=string_findBalanced(html, "<div>", "</div>")
><div>
<div>
</div>
<span/>
</div>
S
local huge, min = math.huge, math.minТупой подсчёт вхождений, но фичеватость присутствует. Можно ещё оптимизировать на пару курсоров, чтобы не переискивало каждый раз начало и конец, но пока впадлу.
local function string_bfind(str, head, tail, offset, ex_bounds, plain)
local header_start, header_end = str:find(head, offset or 1, plain)
if not header_start then return nil end
local cursor = header_end
local last_tail_start = 0
local counter = 1
while counter > 0 do
local ha, hb = str:find(head, cursor + 1, plain)
if not ha then ha, hb = huge, huge end
local ta, tb = str:find(tail, cursor + 1, plain)
if not ta then return nil end
counter = counter + (ha < ta and 1 or -1)
cursor = min(hb, tb)
last_tail_start = ta
end
if ex_bounds then
local a, b = header_end + 1, last_tail_start - 1
return str:sub(a, b), a, b
end
return str:sub(header_start, cursor), header_start, cursor
end
local str = "<html><div><div></div><span/></div></html>"
print(string_bfind(str, "<div>", "</div>") )
H
S
H
S
require"forms"
H
H
require"forms"
H
S
H
S
S
package.path
, работает примерно как переменная PATH
.H
> require "foo"
stdin:1: module 'foo' not found:
no field package.preload['foo']
no file '/usr/local/share/lua/5.3/foo.lua'
no file '/usr/local/share/lua/5.3/foo/init.lua'
no file '/usr/local/lib/lua/5.3/foo.lua'
no file '/usr/local/lib/lua/5.3/foo/init.lua'
no file '/usr/share/lua/5.3/foo.lua'
no file '/usr/share/lua/5.3/foo/init.lua'
no file './foo.lua'
no file './foo/init.lua'
no file '/usr/local/lib/lua/5.3/foo.so'
no file '/usr/lib/x86_64-linux-gnu/lua/5.3/foo.so'
no file '/usr/lib/lua/5.3/foo.so'
no file '/usr/local/lib/lua/5.3/loadall.so'
no file './foo.so'
stack traceback:
[C]: in function 'require'
stdin:1: in main chunk
[C]: in ?
S