Skip to content

Instantly share code, notes, and snippets.

@kahrl
Created August 17, 2013 13:29
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/6256856 to your computer and use it in GitHub Desktop.
Save kahrl/6256856 to your computer and use it in GitHub Desktop.
function fgettext(text, ...)
text = engine.gettext(text)
if arg.n >= 1 then
-- Insert positional parameters ($1, $2, ...)
result = ''
pos = 1
while pos <= text:len() do
newpos = text:find('[$]', pos)
if newpos == nil then
result = result .. text:sub(pos)
pos = text:len() + 1
else
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