local table = require "table"
local nixio = require "nixio"
-local getmetatable, assert, pairs, type = getmetatable, assert, pairs, type
+local getmetatable, assert, pairs, type, tostring =
+ getmetatable, assert, pairs, type, tostring
module "nixio.util"
meta.recvall = meta.readall
function meta.writeall(self, data)
+ data = tostring(data)
local sent, code, msg = self:write(data)
if not sent then
-- @param ... Format parameters
-- @return Translated and formatted string
function translatef(key, default, ...)
- return translate(key, default):format(...)
+ return tostring(translate(key, default)):format(...)
+end
+
+--- Return the translated value for a specific translation key
+-- and ensure that the returned value is a Lua string value.
+-- This is the same as calling <code>tostring(translate(...))</code>
+-- @param key Translation key
+-- @param default Default translation
+-- @return Translated string
+function string(key, default)
+ return tostring(translate(key, default))
+end
+
+--- Return the translated value for a specific translation key and use it as sprintf pattern.
+-- Ensure that the returned value is a Lua string value.
+-- This is the same as calling <code>tostring(translatef(...))</code>
+-- @param key Translation key
+-- @param default Default translation
+-- @param ... Format parameters
+-- @return Translated and formatted string
+function stringf(key, default, ...)
+ return tostring(translate(key, default)):format(...)
end
parser.flags = 0;
parser.bufsize = 0;
parser.state = T_STATE_TEXT_NEXT;
-
- if( !(lua_status = lua_load(L, template_reader, &parser, file)) )
+
+ lua_status = lua_load(L, template_reader, &parser, file);
+
+ (void) close(parser.fd);
+
+
+ if( lua_status == 0 )
{
return 1;
}
return NULL;
}
-/*
- * Inspect current read buffer and find the number of "vague" characters at the end
+/*
+ * Inspect current read buffer and find the number of "vague" characters at the end
* which could indicate an opening token. Returns the number of "vague" chars.
* The last continuous sequence of whitespace, optionally followed by a "<" is
* treated as "vague" because whitespace may be discarded if the upcoming opening
- * token indicates pre-whitespace-removal ("<%-"). A single remaining "<" char
+ * token indicates pre-whitespace-removal ("<%-"). A single remaining "<" char
* can't be differentiated from an opening token ("<%"), so it's kept to be processed
* in the next cycle.
*/
}
}
- /* Found whitespace in i18n expression, raise flag */
- else if( isspace(data->out[i]) && (data->type == T_TYPE_I18N) )
+ /* Found first whitespace in i18n expression, raise flag */
+ else if( isspace(data->out[i]) && (data->type == T_TYPE_I18N) && (i18n_hasdef == 0) )
{
i18n_hasdef = 1;
}
string.format("%.2f MB (%.0f%% %s, %.0f%% %s, %.0f%% %s)",
tonumber(memtotal) / 1024,
100 * memcached / memtotal,
- translate("mem_cached") or "",
+ tostring(translate("mem_cached", "")),
100 * membuffers / memtotal,
- translate("mem_buffered") or "",
+ tostring(translate("mem_buffered", "")),
100 * memfree / memtotal,
- translate("mem_free") or "")
+ tostring(translate("mem_free", ""))
s:option(DummyValue, "_systime", translate("m_i_systemtime")).value =
os.date("%c")
string.format("%.2f MB (%.0f%% %s, %.0f%% %s, %.0f%% %s)",
tonumber(memtotal) / 1024,
100 * memcached / memtotal,
- translate("mem_cached") or "",
+ tostring(translate("mem_cached", "")),
100 * membuffers / memtotal,
- translate("mem_buffered") or "",
+ tostring(translate("mem_buffered", "")),
100 * memfree / memtotal,
- translate("mem_free") or "")
+ tostring(translate("mem_free", ""))
s:option(DummyValue, "_systime", translate("m_i_systemtime")).value =
os.date("%c")
string.format("%.2f MB (%.0f%% %s, %.0f%% %s, %.0f%% %s)",
tonumber(memtotal) / 1024,
100 * memcached / memtotal,
- translate("mem_cached") or "",
+ tostring(translate("mem_cached"), "")),
100 * membuffers / memtotal,
- translate("mem_buffered") or "",
+ tostring(translate("mem_buffered", "")),
100 * memfree / memtotal,
- translate("mem_free") or "")
+ tostring(translate("mem_free", ""))
f:field(DummyValue, "_systime", translate("m_i_systemtime")).value =
os.date("%c")