Changeset

6706:60c692828cf6

hostmanager: Metatable with __tostring on hosts
author Kim Alvefur <zash@zash.se>
date Mon, 18 May 2015 20:50:50 +0200
parents 6704:03afecdf2e3c
children 6707:06cdd4afaaf9
files core/hostmanager.lua
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/core/hostmanager.lua	Fri May 15 15:32:39 2015 +0200
+++ b/core/hostmanager.lua	Mon May 18 20:50:50 2015 +0200
@@ -26,9 +26,23 @@
 
 local pairs, select, rawget = pairs, select, rawget;
 local tostring, type = tostring, type;
+local setmetatable = setmetatable;
 
 module "hostmanager"
 
+local host_mt = { }
+function host_mt:__tostring()
+	if self.type == "component" then
+		local typ = configmanager.get(self.host, "component_module");
+		if typ == "component" then
+			return ("Component %q"):format(self.host);
+		end
+		return ("Component %q %q"):format(self.host, typ);
+	elseif self.type == "local" then
+		return ("VirtualHost %q"):format(self.host);
+	end
+end
+
 local hosts_loaded_once;
 
 local function load_enabled_hosts(config)
@@ -76,6 +90,7 @@
 		send = host_send;
 		modules = {};
 	};
+	setmetatable(host_session, host_mt);
 	if not host_config.component_module then -- host
 		host_session.type = "local";
 		host_session.sessions = {};