[Zrouter-src] ZRouter.org: push to ZRouter profiles/lua_web_ui/files/etc/www/h...

zrouter-src at zrouter.org zrouter-src at zrouter.org
Mon Sep 24 11:23:54 UTC 2012


details:   http://zrouter.org/hg/zrouter//rev/cf66b8733a66
changeset: 472:cf66b8733a66
user:      Aleksandr Rybalko <ray at ddteam.net>
date:      Mon Sep 24 14:24:52 2012 +0300
description:
Use protected call (pcall) for proccessed files with embedded Lua code.

diffstat:

 profiles/lua_web_ui/files/etc/www/httpd.lua |  11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diffs (31 lines):

diff -r a581dc308cff -r cf66b8733a66 profiles/lua_web_ui/files/etc/www/httpd.lua
--- a/profiles/lua_web_ui/files/etc/www/httpd.lua	Mon Sep 24 14:23:30 2012 +0300
+++ b/profiles/lua_web_ui/files/etc/www/httpd.lua	Mon Sep 24 14:24:52 2012 +0300
@@ -493,7 +493,7 @@
 			    " " .. urlEncode(path));
 			retcode = "500";
 		else
-			t = code();
+			st, t = pcall(code);
 		end
 	end
 	client:send(t);
@@ -509,11 +509,16 @@
 
 	match, _, code = string.find(s, "^code%:(.*)$");
 	if match then
-		local func, err = loadstring("return " .. code);
+		local func, err = assert(loadstring("return " .. code));
 		if not func then
 			return err;
 		end
-		return func();
+		local status, ret = pcall(func);
+		if status == false then
+			print(code, " failed");
+			return "";
+		end
+		return (ret);
 	else
 		node = c:getNode(s);
 		if node then


More information about the Zrouter-src mailing list