Modulo:String/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Moroboshi (discussione | contributi)
fix arraytostring
Moroboshi (discussione | contributi)
test modifiche sostituzione funzione mw.message.newRawMessage
Riga 471:
 
-- =================================================================
-- Classe per gestire i messaggiomessaggi
-- =================================================================
local Message = {}
Riga 480:
msg = mw.ustring.gsub(msg, '\\{', '{')
msg = mw.ustring.gsub(msg, '\\}', '}')
 
-- break msg in msg_table, odd position are fixed string, even position are a parameter number to be substitued
local msg_table = {}
local last_position = 1
while true do
sep_start, sep_end, par_number = mw.ustring.find(msg, '$(\d+)', last_position) -- find the next '$n' in the string
if sep_start~=nil then -- separator found
if sep_start == 1 then
table.insert(msg_table, '') -- il $n è subito a inizio stringa, salvo la string vuota al primo posto
else
table.insert(msg_table, mw.ustring.sub(msg, last_position, sep_start-1))
end
table.insert(msg_table, tonumber(par_number))
last_position=sep_end + 1 -- save next position to start
else
table.insert(msg_table, mw.ustring.sub(msg, last_position) or '') -- Save what's left in msg_tabele
break
end
end
return setmetatable({
msgmsg_table = msgmsg_table,
values = {},
}, Message)
Line 495 ⟶ 514:
 
function Message:text()
local raw_messaget = mw.message.newRawMessage(self.msg, self.values){}
returnfor raw_message:text()i = 1, #self.msg_table, 2 do
table.insert(t, self.msg_table[i])
table.insert(t, self.values[self.msg_table[i]] or '')
end
local msg = table.join(t)
return frame:preprocess(msg)
end
 
Line 519 ⟶ 543:
end
--carico il messaggio
local msg = base_args.msg or '$1'
if msg == '' then return str._error('Manca il messaggio da riprodurre.') end
local message = Message(msg)
elements = {}