webmcp

annotate framework/env/__init.lua @ 324:1c3ba14bd679

Root __init.lua function must not set global variables without _G now; Documentation for "_" function added
author jbe
date Mon Mar 23 22:41:40 2015 +0100 (2015-03-23)
parents 1fbdccf4f8e9
children 3384306aa7bc
rev   line source
jbe@324 1 --[[--
jbe@324 2 translated_string = -- translated string
jbe@324 3 _(
jbe@324 4 string_to_translate, -- string to translate
jbe@324 5 {
jbe@324 6 placeholder_name1 = text1, -- replace all occurrences of "#{placeholder_name1}" with the string text1
jbe@324 7 placeholder_name2 = text2, -- replace all occurrences of "#{placeholder_name2}" with the string text2
jbe@324 8 ...
jbe@324 9 }
jbe@324 10 )
jbe@324 11
jbe@324 12 Translation function for internationalization. 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@324 13
jbe@324 14 --]]--
jbe@324 15
jbe@324 16 function _G._(text, replacements)
jbe/bsw@0 17 local text = locale._get_translation_table()[text] or text
jbe/bsw@0 18 if replacements then
jbe/bsw@0 19 return (
jbe/bsw@0 20 string.gsub(
jbe/bsw@0 21 text,
jbe/bsw@0 22 "#{(.-)}",
jbe/bsw@0 23 function (placeholder)
jbe/bsw@0 24 return replacements[placeholder]
jbe/bsw@0 25 end
jbe/bsw@0 26 )
jbe/bsw@0 27 )
jbe/bsw@0 28 else
jbe/bsw@0 29 return text
jbe/bsw@0 30 end
jbe/bsw@0 31 end
jbe@324 32 --//--
jbe@203 33
jbe@203 34 --[[--
jbe@203 35 cloned_table = -- newly generated table
jbe@203 36 table.new(
jbe@203 37 table_or_nil -- keys of a given table will be copied to the new table
jbe@203 38 )
jbe@203 39
jbe@203 40 If a table is given, then a cloned table is returned.
jbe@203 41 If nil is given, then a new empty table is returned.
jbe@203 42
jbe@203 43 --]]--
jbe@203 44 function table.new(tbl)
jbe@240 45 local new_tbl = {}
jbe@203 46 if tbl then
jbe@203 47 for key, value in pairs(tbl) do
jbe@203 48 new_tbl[key] = value
jbe@203 49 end
jbe@203 50 end
jbe@203 51 return new_tbl
jbe@203 52 end
jbe@203 53 --//--
jbe@203 54
jbe@286 55 -- load libraries (except "multirand", which must be loaded after forking)
jbe@324 56 _G.extos = require 'extos'
jbe@324 57 _G.nihil = require 'nihil'
jbe@324 58 _G.mondelefant = require 'mondelefant'
jbe@324 59 _G.atom = require 'atom'
jbe@324 60 _G.json = require 'json'
jbe@203 61 require 'mondelefant_atom_connector'
jbe@286 62 -- NOTE: "multirand" library is loaded in mcp.lua after forking
jbe@203 63
jbe@295 64 -- setup mondelefant
jbe@295 65 mondelefant.connection_prototype.error_objects = true
jbe@295 66 function mondelefant.connection_prototype:sql_tracer(command)
jbe@295 67 if trace.is_disabled() then
jbe@295 68 return
jbe@295 69 end
jbe@295 70 local start_time = extos.monotonic_hires_time()
jbe@295 71 return function(error_info)
jbe@295 72 trace.sql{
jbe@295 73 command = command,
jbe@295 74 execution_time = extos.monotonic_hires_time() - start_time,
jbe@295 75 error_position = error_info and error_info.position or nil
jbe@295 76 }
jbe@295 77 end
jbe@295 78 end
jbe@295 79
jbe@206 80 --[[--
jbe@206 81 config -- table to store application configuration
jbe@206 82
jbe@206 83 '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 84 --]]--
jbe@324 85 _G.config = {}
jbe@206 86 --//--
jbe@206 87

Impressum / About Us