From: Jo-Philipp Wich Date: Sun, 26 Jul 2009 23:59:58 +0000 (+0000) Subject: luci-0.9: merge r5145-r5153 X-Git-Tag: 0.9.0~149 X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=0764c67993aa99c9e812babd6277275c9f362fa5;p=project%2Fluci.git luci-0.9: merge r5145-r5153 --- diff --git a/libs/nixio/lua/nixio/util.lua b/libs/nixio/lua/nixio/util.lua index ecefb4c97f..401ec615eb 100644 --- a/libs/nixio/lua/nixio/util.lua +++ b/libs/nixio/lua/nixio/util.lua @@ -14,7 +14,8 @@ $Id$ 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" @@ -79,6 +80,7 @@ end meta.recvall = meta.readall function meta.writeall(self, data) + data = tostring(data) local sent, code, msg = self:write(data) if not sent then diff --git a/libs/web/luasrc/i18n.lua b/libs/web/luasrc/i18n.lua index dcca13ec64..9a11a9dc8f 100644 --- a/libs/web/luasrc/i18n.lua +++ b/libs/web/luasrc/i18n.lua @@ -109,5 +109,26 @@ end -- @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 tostring(translate(...)) +-- @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 tostring(translatef(...)) +-- @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 diff --git a/libs/web/src/template_lualib.c b/libs/web/src/template_lualib.c index 685613fbdc..f91b19ceb8 100644 --- a/libs/web/src/template_lualib.c +++ b/libs/web/src/template_lualib.c @@ -29,8 +29,13 @@ int template_L_parse(lua_State *L) 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; } diff --git a/libs/web/src/template_parser.c b/libs/web/src/template_parser.c index 58de5bb774..9618919b30 100644 --- a/libs/web/src/template_parser.c +++ b/libs/web/src/template_parser.c @@ -58,12 +58,12 @@ static char *strfind(char *haystack, int hslen, const char *needle, int ndlen) 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. */ @@ -186,8 +186,8 @@ static const char * generate_expression(struct template_parser *data, size_t *sz } } - /* 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; } diff --git a/modules/admin-full/luasrc/model/cbi/admin_system/system.lua b/modules/admin-full/luasrc/model/cbi/admin_system/system.lua index b3c2a4e86c..1d35dee7f6 100644 --- a/modules/admin-full/luasrc/model/cbi/admin_system/system.lua +++ b/modules/admin-full/luasrc/model/cbi/admin_system/system.lua @@ -35,11 +35,11 @@ s:option(DummyValue, "_memtotal", translate("m_i_memory")).value = 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") diff --git a/modules/admin-mini/luasrc/model/cbi/mini/system.lua b/modules/admin-mini/luasrc/model/cbi/mini/system.lua index fa23b7c138..4ef97e48e1 100644 --- a/modules/admin-mini/luasrc/model/cbi/mini/system.lua +++ b/modules/admin-mini/luasrc/model/cbi/mini/system.lua @@ -38,11 +38,11 @@ s:option(DummyValue, "_memtotal", translate("m_i_memory")).value = 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") diff --git a/modules/freifunk/luasrc/model/cbi/freifunk/public_status.lua b/modules/freifunk/luasrc/model/cbi/freifunk/public_status.lua index 56e956363e..2192697fde 100644 --- a/modules/freifunk/luasrc/model/cbi/freifunk/public_status.lua +++ b/modules/freifunk/luasrc/model/cbi/freifunk/public_status.lua @@ -27,11 +27,11 @@ f:field(DummyValue, "_memtotal", translate("m_i_memory")).value = 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")