aboutsummaryrefslogtreecommitdiff
path: root/builtin/misc_helpers.lua
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/misc_helpers.lua')
-rw-r--r--builtin/misc_helpers.lua36
1 files changed, 34 insertions, 2 deletions
diff --git a/builtin/misc_helpers.lua b/builtin/misc_helpers.lua
index 41d0e7c2f..3a325e0d3 100644
--- a/builtin/misc_helpers.lua
+++ b/builtin/misc_helpers.lua
@@ -86,14 +86,23 @@ function string:split(sep)
end
--------------------------------------------------------------------------------
+function file_exists(filename)
+ local f = io.open(filename, "r")
+ if f==nil then
+ return false
+ else
+ f:close()
+ return true
+ end
+end
+
+--------------------------------------------------------------------------------
function string:trim()
return (self:gsub("^%s*(.-)%s*$", "%1"))
end
assert(string.trim("\n \t\tfoo bar\t ") == "foo bar")
-
-
--------------------------------------------------------------------------------
function math.hypot(x, y)
local t
@@ -209,6 +218,29 @@ if engine ~= nil then
return nil
end
+
+ function fgettext(text, ...)
+ text = engine.gettext(text)
+ local arg = {n=select('#', ...), ...}
+ 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
end
--------------------------------------------------------------------------------
-- core only fct