webmcp
changeset 214:6ac7133bb58e
Work on Moonbridge integration: added execute._initializers(...), new function request.get_param{...}; Code cleanup in mcp.lua and tempstore.save(...)
author | jbe |
---|---|
date | Sat Jan 10 10:44:17 2015 +0100 (2015-01-10) |
parents | d69106e271fc |
children | ba3dd4a17e3d |
files | framework/bin/mcp.lua framework/env/execute/_initializers.lua framework/env/request/get_param.lua framework/env/tempstore/save.lua |
line diff
1.1 --- a/framework/bin/mcp.lua Sat Jan 10 10:30:01 2015 +0100 1.2 +++ b/framework/bin/mcp.lua Sat Jan 10 10:44:17 2015 +0100 1.3 @@ -170,6 +170,13 @@ 1.4 try_exec(WEBMCP_BASE_PATH .. "env/__init.lua") 1.5 end 1.6 1.7 +-- replace Moonbridge listen function 1.8 +local moonbridge_listen = listen 1.9 +local listeners 1.10 +function listen(args) 1.11 + listeners[#listeners+1] = args 1.12 +end 1.13 + 1.14 -- prohibit (unintended) definition of new global variables 1.15 _ENV = setmetatable({}, { 1.16 __index = _G, 1.17 @@ -178,12 +185,7 @@ 1.18 end 1.19 }) 1.20 1.21 --- replace Moonbridge listen function and execute configurations 1.22 -local moonbridge_listen = listen 1.23 -local listeners 1.24 -function _G.listen(args) 1.25 - listeners[#listeners+1] = args 1.26 -end 1.27 +-- execute configurations 1.28 for i, config_name in ipairs(WEBMCP_CONFIG_NAMES) do 1.29 execute.config(config_name) 1.30 end
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/framework/env/execute/_initializers.lua Sat Jan 10 10:44:17 2015 +0100 2.3 @@ -0,0 +1,25 @@ 2.4 +function execute._initializers(initializer_path_element) 2.5 + local yieldvalue = {} 2.6 + local coro = coroutine.wrap(function() 2.7 + execute.multi_wrapped( 2.8 + execute._create_sorted_execution_list( 2.9 + function(add_by_path) 2.10 + add_by_path(initializer_path_element) 2.11 + add_by_path(WEBMCP_APP_NAME, initializer_path_element) 2.12 + end, 2.13 + function(full_path, relative_path) 2.14 + execute.file_path{ file_path = full_path } 2.15 + end 2.16 + ), 2.17 + function() 2.18 + coroutine.yield(yieldvalue) 2.19 + end 2.20 + ) 2.21 + return yieldvalue 2.22 + end) 2.23 + local function cont() 2.24 + assert(coro() == yieldvalue, "Unexpected yield") 2.25 + end 2.26 + cont() 2.27 + execute._finalizers[#execute._finalizers+1] = cont 2.28 +end
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/framework/env/request/get_param.lua Sat Jan 10 10:44:17 2015 +0100 3.3 @@ -0,0 +1,33 @@ 3.4 +--[[-- 3.5 +value = -- value of GET/POST parameter, or value list if multiple == true 3.6 +request.get_param{ 3.7 + method = method, -- "GET", "POST", or nil to query both (POST has precedence) 3.8 + name = name, -- field name 3.9 + index = index, -- defaults to 1 to get first occurrence, only applicable if multiple == false 3.10 + multiple = multiple -- boolean to indicate whether to return a single value or a value list 3.11 +} 3.12 + 3.13 +Reads GET/POST parameters directly from the underlaying request. 3.14 + 3.15 +--]]-- 3.16 + 3.17 +function request.get_param(args) 3.18 + local param_list 3.19 + if args.method == "GET" then 3.20 + param_list = request._http_request.get_params_list[args.name] 3.21 + elseif args.method == "POST" then 3.22 + param_list = request._http_request.post_params_list[args.name] 3.23 + elseif not args.method then 3.24 + param_list = request._http_request.post_params_list[args.name] 3.25 + if not param_list[index or 1] then 3.26 + param_list = request._http_request.get_params_list[args.name] 3.27 + end 3.28 + end 3.29 + if multiple then 3.30 + return param_list 3.31 + else 3.32 + return param_list[index or 1] 3.33 + end 3.34 +end 3.35 + 3.36 +--//--
4.1 --- a/framework/env/tempstore/save.lua Sat Jan 10 10:30:01 2015 +0100 4.2 +++ b/framework/env/tempstore/save.lua Sat Jan 10 10:44:17 2015 +0100 4.3 @@ -9,7 +9,7 @@ 4.4 --]]-- 4.5 4.6 function tempstore.save(blob) 4.7 - local key = multirand.string(26, "123456789bcdfghjklmnpqrstvwxyz"); 4.8 + local key = multirand.string(26, "123456789bcdfghjklmnpqrstvwxyz") 4.9 local filename = encode.file_path( 4.10 WEBMCP_BASE_PATH, 'tmp', "tempstore-" .. key .. ".tmp" 4.11 )