大幅度提高编写npc界面效率
function fmt(str, tab)
local fmt_str = str:gsub("{(.-)}", function(key)
return tab[key] or "nil"
end)
return fmt_str
end
-- 示例
local 字符串 = [[
你好:{Name}
等级:{Level}
经验:{Exp}/{MaxExp}
金币:{Gold}
元宝:{元宝数量}
]]
local 替换表 = {
Name = "阿萨德",
Level = 105,
Exp = 1250,
MaxExp = 1000000,
Gold = 500000,
元宝数量 = 3000000,
}
local str = fmt(字符串, 替换表)
print(str)
|