webmcp

view framework/env/__init.lua @ 382:810c020b0da4

Reverted changes to mondelefant_result_index and mondelefant_result_newindex C-functions (proxying of JSON document)
author jbe
date Mon Nov 16 18:31:49 2015 +0100 (2015-11-16)
parents 2b5bdf9028fb
children 7eec5b604b00
line source
1 --[[--
2 translated_string = -- translated string
3 _(
4 string_to_translate, -- string to translate
5 {
6 placeholder_name1 = text1, -- replace all occurrences of "#{placeholder_name1}" with the string text1
7 placeholder_name2 = text2, -- replace all occurrences of "#{placeholder_name2}" with the string text2
8 ...
9 }
10 )
12 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.
14 Hint: Lua's syntax rules allow to write _"text" as a shortcut for _("text"), or _'text' instead of _('text') respectivly.
16 --]]--
18 function _G._(text, replacements)
19 local text = locale._get_translation_table()[text] or text
20 if replacements then
21 return (
22 string.gsub(
23 text,
24 "#{(.-)}",
25 function (placeholder)
26 return replacements[placeholder]
27 end
28 )
29 )
30 else
31 return text
32 end
33 end
34 --//--
36 --[[--
37 cloned_table = -- newly generated table
38 table.new(
39 table_or_nil -- keys of a given table will be copied to the new table
40 )
42 If a table is given, then a cloned table is returned.
43 If nil is given, then a new empty table is returned.
45 --]]--
46 function table.new(tbl)
47 local new_tbl = {}
48 if tbl then
49 for key, value in pairs(tbl) do
50 new_tbl[key] = value
51 end
52 end
53 return new_tbl
54 end
55 --//--
57 -- load libraries
58 -- (except "extos", which has to be loaded earlier, and "multirand", which must be loaded after forking)
59 _G.nihil = require 'nihil'
60 _G.mondelefant = require 'mondelefant'
61 _G.atom = require 'atom'
62 _G.json = require 'json'
63 require 'mondelefant_atom_connector'
64 -- NOTE: "multirand" library is loaded in mcp.lua after forking
66 -- setup mondelefant
67 mondelefant.connection_prototype.error_objects = true
68 function mondelefant.connection_prototype:sql_tracer(command)
69 if trace.is_disabled() then
70 return
71 end
72 local start_time = extos.monotonic_hires_time()
73 return function(error_info)
74 trace.sql{
75 command = command,
76 execution_time = extos.monotonic_hires_time() - start_time,
77 error_position = error_info and error_info.position or nil
78 }
79 end
80 end
82 --[[--
83 config -- table to store application configuration
85 'config' is a global table, which can be modified by a config file of an application to modify the behaviour of that application.
86 --]]--
87 _G.config = {}
88 --//--

Impressum / About Us