T
Size: a a a
T
S
table.remove.S
T
S
ШТ
-- str = "Hello %item%!"
-- tfill(str, {item = "world"})
function tfill(tmpl, tbl)
local function replace(c)
return tbl[c] or '%' .. c .. '%'
end
return tmpl:gsub('%%(.-)%%', replace)
end
local templates = {}
templates.button = [[
<div style="position:absolute; top:%y%; left:%x%vw; width:%w%vw; height: %h%vh">%text%</div>]]
local buttons = {}
function createButton(info)
info.html = tfill(templates.button, info)
table.insert(buttons, info)
end
createButton{x=10, y=20, w=100, h=200, text="Yo" }%%экранирование спецсимвола? А
%выбран для шаблона чисто с потолка?
S
Привет, %username%", с типичных форумов, при ошибке заполнения поля. Считай что это пыховые шаблончики.ШТ
|, но ее иногда проблемно набирать(
S
S
$width.S
local layout = {
btn1 = tfill(btn, {...})
btn2 = tfill(btn, {...})
}
local page = [[
<html>
<body>
%btn1%
%btn2%
</body>
</html>]]
page = tfill(page, layout)M
table.remove.S
function table_clear(tbl, v)
local p = 1
for i = 1, #tbl do
tbl[p] = tbl[i]
if tbl[i] ~= v then
p = p + 1
end
end
for i = p, #tbl do
tbl[i] = nil
end
return tbl
end
local t = {'a', 0, 'c', 0, 0, 'd', 'e', 0, 'g', 0, 'f'}
print('Clear', render( table_clear(t, 0) ))
--> Clear { "a", "c", "d", "e", "g", "f" }M
function table_clear(tbl, v)
local p = 1
for i = 1, #tbl do
tbl[p] = tbl[i]
if tbl[i] ~= v then
p = p + 1
end
end
for i = p, #tbl do
tbl[i] = nil
end
return tbl
end
local t = {'a', 0, 'c', 0, 0, 'd', 'e', 0, 'g', 0, 'f'}
print('Clear', render( table_clear(t, 0) ))
--> Clear { "a", "c", "d", "e", "g", "f" }S
M
S
M