jbe@324: --[[-- jbe@324: translated_string = -- translated string jbe@324: _( jbe@324: string_to_translate, -- string to translate jbe@324: { jbe@324: placeholder_name1 = text1, -- replace all occurrences of "#{placeholder_name1}" with the string text1 jbe@324: placeholder_name2 = text2, -- replace all occurrences of "#{placeholder_name2}" with the string text2 jbe@324: ... jbe@324: } jbe@324: ) jbe@324: jbe@325: Translation function for localization. The "_" function translates a given string to the currently selected language (see locale.set{...}). If the translated string contains placeholders in the form #{name}, then those placeholders may be automatically replaced with a corresponding substring which is taken from the table passed as optional second argument. jbe@325: jbe@325: Hint: Lua's syntax rules allow to write _"text" as a shortcut for _("text"), or _'text' instead of _('text') respectivly. jbe@324: jbe@324: --]]-- jbe@324: jbe@324: function _G._(text, replacements) jbe/bsw@0: local text = locale._get_translation_table()[text] or text jbe/bsw@0: if replacements then jbe/bsw@0: return ( jbe/bsw@0: string.gsub( jbe/bsw@0: text, jbe/bsw@0: "#{(.-)}", jbe/bsw@0: function (placeholder) jbe/bsw@0: return replacements[placeholder] jbe/bsw@0: end jbe/bsw@0: ) jbe/bsw@0: ) jbe/bsw@0: else jbe/bsw@0: return text jbe/bsw@0: end jbe/bsw@0: end jbe@324: --//-- jbe@203: jbe@203: --[[-- jbe@203: cloned_table = -- newly generated table jbe@203: table.new( jbe@203: table_or_nil -- keys of a given table will be copied to the new table jbe@203: ) jbe@203: jbe@203: If a table is given, then a cloned table is returned. jbe@203: If nil is given, then a new empty table is returned. jbe@203: jbe@203: --]]-- jbe@203: function table.new(tbl) jbe@240: local new_tbl = {} jbe@203: if tbl then jbe@203: for key, value in pairs(tbl) do jbe@203: new_tbl[key] = value jbe@203: end jbe@203: end jbe@203: return new_tbl jbe@203: end jbe@203: --//-- jbe@203: jbe@495: --[[-- jbe@495: table.insert( jbe@495: t, -- table jbe@495: index, -- optional index jbe@495: value -- value jbe@495: ) jbe@495: jbe@495: Custom implementation of Lua's table.insert(...) where table.insert(table, value) also respects metamethods in Lua 5.2 (this behavior is already supported by Lua 5.3). jbe@495: jbe@495: --]]-- jbe@498: if _VERSION == "Lua 5.2" then jbe@495: local old_insert = table.insert jbe@495: function table.insert(...) jbe@498: if select("#", ...) == 2 then jbe@495: local t, value = ... jbe@495: t[#t+1] = value jbe@495: return jbe@495: end jbe@495: return old_insert(...) jbe@495: end jbe@495: end jbe@495: --//-- jbe@495: jbe@352: -- load libraries jbe@352: -- (except "extos", which has to be loaded earlier, and "multirand", which must be loaded after forking) jbe@324: _G.nihil = require 'nihil' jbe@324: _G.mondelefant = require 'mondelefant' jbe@324: _G.atom = require 'atom' jbe@324: _G.json = require 'json' jbe@203: require 'mondelefant_atom_connector' jbe@286: -- NOTE: "multirand" library is loaded in mcp.lua after forking jbe@203: jbe@295: -- setup mondelefant jbe@295: mondelefant.connection_prototype.error_objects = true jbe@295: function mondelefant.connection_prototype:sql_tracer(command) jbe@295: if trace.is_disabled() then jbe@295: return jbe@295: end jbe@295: local start_time = extos.monotonic_hires_time() jbe@295: return function(error_info) jbe@295: trace.sql{ jbe@295: command = command, jbe@295: execution_time = extos.monotonic_hires_time() - start_time, jbe@295: error_position = error_info and error_info.position or nil jbe@295: } jbe@295: end jbe@295: end jbe@295: jbe@206: --[[-- jbe@206: config -- table to store application configuration jbe@206: jbe@206: 'config' is a global table, which can be modified by a config file of an application to modify the behaviour of that application. jbe@206: --]]-- jbe@324: _G.config = {} jbe@206: --//-- jbe@206: