webmcp
view framework/env/locale/do_with.lua @ 194:654ddbcc49d0
Bugfix in autodoc.lua; Added documentation for JSON library; json.import(...) returns json.null for "null" on top-level
| author | jbe | 
|---|---|
| date | Mon Aug 11 17:38:12 2014 +0200 (2014-08-11) | 
| parents | 9fdfb27f8e67 | 
| children | c3d539e33710 | 
 line source
     1 --[[--
     2 locale.do_with(
     3   locale_options,  -- table with locale information (as if passed to locale.set(...))
     4   function()
     5     ...            -- code to be executed with the given locale settings
     6   end
     7 )
     9 This function executes code with temporarily changed locale settings. See locale.set(...) for correct usage of 'locale_options'.
    11 --]]--
    13 function locale.do_with(locale_options, block)
    14   local old_data = {}
    15   for key, value in pairs(locale._current_data) do
    16     old_data[key] = value
    17   end
    18   locale.set(locale_options)
    19   block()
    20   old_data.reset = true
    21   locale.set(old_data)
    22 end
