Skip to content

Instantly share code, notes, and snippets.

@kahrl
Created August 17, 2013 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kahrl/6256947 to your computer and use it in GitHub Desktop.
Save kahrl/6256947 to your computer and use it in GitHub Desktop.
function fgettext(text, ...)
local arg = {n=select('#',...),...}
local text = engine.gettext(text)
if arg.n >= 1 then
-- Insert positional parameters ($1, $2, ...)
local result = ''
local pos = 1
while pos <= text:len() do
local newpos = text:find('[$]', pos)
if newpos == nil then
result = result .. text:sub(pos)
pos = text:len() + 1
else
local paramindex = tonumber(text:sub(newpos+1, newpos+1))
result = result .. text:sub(pos, newpos-1) .. tostring(arg[paramindex])
pos = newpos + 2
end
end
text = result
end
return engine.formspec_escape(text)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment