webmcp
changeset 31:1cd9e69b85cb
add execute.load_chunk(args)
load_chunk loads the content of a lua file and returns the code.
It can construct the path name easily so you can put helper code in
seperate files for DRYness.
load_chunk loads the content of a lua file and returns the code.
It can construct the path name easily so you can put helper code in
seperate files for DRYness.
author | Daniel Poelzleithner <poelzi@poelzi.org> |
---|---|
date | Tue Oct 05 02:34:04 2010 +0200 (2010-10-05) |
parents | 6e08067e66c1 |
children | e31af860e97c |
files | framework/env/execute/load_chunk.lua framework/env/trace/_render_sub_tree.lua |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/framework/env/execute/load_chunk.lua Tue Oct 05 02:34:04 2010 +0200 1.3 @@ -0,0 +1,32 @@ 1.4 +--[[-- 1.5 +status_code = -- executes and returns a lua file 1.6 +execute.load_chunk{ 1.7 + file_path = file_path, -- path to a lua source or byte-code file 1.8 + app = app, -- app name to use or the current will be used 1.9 + module = module, -- module where chunk is located 1.10 + chunk = chunk -- filename of lua file to load 1.11 +} 1.12 + 1.13 +This function loads and executes a lua file specified by a given path or constructs 1.14 +a path to load from the module and chunk name. 1.15 + 1.16 +--]]-- 1.17 + 1.18 +function execute.load_chunk(args) 1.19 + local file_path = args.file_path 1.20 + local app = args.app 1.21 + local module = args.module 1.22 + local chunk = args.chunk 1.23 + 1.24 + app = app or request.get_app_name() 1.25 + 1.26 + file_path = file_path or encode.file_path(request.get_app_basepath(), 1.27 + 'app', app, module, chunk) 1.28 + 1.29 + local func, load_errmsg = loadfile(file_path) 1.30 + if not func then 1.31 + error('Could not load file "' .. file_path .. '": ' .. load_errmsg) 1.32 + end 1.33 + local result = func() 1.34 + return result 1.35 +end
2.1 --- a/framework/env/trace/_render_sub_tree.lua Mon Sep 20 20:11:29 2010 +0200 2.2 +++ b/framework/env/trace/_render_sub_tree.lua Tue Oct 05 02:34:04 2010 +0200 2.3 @@ -35,6 +35,18 @@ 2.4 open("debug") 2.5 slot.put(encode.html(node.message)) 2.6 close() 2.7 + elseif node_type == "debug_table" then 2.8 + open("debug") 2.9 + slot.put("<table>") 2.10 + if type(node.message) == "table" then 2.11 + for k, v in pairs(node.message) do 2.12 + slot.put("<tr><td>", encode.html(tostring(k)),"</td><td>", encode.html(tostring(v)), "</td></tr>") 2.13 + end 2.14 + slot.put("</table>") 2.15 + else 2.16 + slot.put("debug_table: not of table type") 2.17 + end 2.18 + close() 2.19 elseif node_type == "traceback" then 2.20 open("debug") 2.21 slot.put('<pre>')