diff web/src/luan/modules/web/HttpServicer.java @ 325:78a6a71afbfd

use SimplyHTML git-svn-id: https://luan-java.googlecode.com/svn/trunk@326 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Tue, 03 Mar 2015 06:00:59 +0000
parents 1f6d828986b9
children 496d61b1fb5a
line wrap: on
line diff
--- a/web/src/luan/modules/web/HttpServicer.java	Mon Feb 09 23:15:42 2015 +0000
+++ b/web/src/luan/modules/web/HttpServicer.java	Tue Mar 03 06:00:59 2015 +0000
@@ -53,11 +53,9 @@
 					session.putValue("luan",luan);
 				}
 				tbl = (LuanTable)PackageLuan.require(luan,modName);
-				fn = (LuanFunction)tbl.get("service");
+				fn = getService(luan,tbl);
 			} else {
-				fn = (LuanFunction)tbl.get("service");
-				if( fn == null )
-					throw luan.exception( "function 'service' is not defined" );
+				fn = getService(luan,tbl);
 				DeepCloner cloner = new DeepCloner();
 				luan = cloner.deepClone(luan);
 				fn = cloner.get(fn);
@@ -89,6 +87,16 @@
 		return true;
 	}
 
+	private static LuanFunction getService(LuanState luan,LuanTable tbl)
+		throws LuanException
+	{
+		Object service = tbl.get("service");
+		if( service == null )
+			throw luan.exception( "function 'service' is not defined" );
+		if( !(service instanceof LuanFunction) )
+			throw luan.exception( "'service' must be a function but is a " + Luan.type(service) );
+		return (LuanFunction)service;
+	}
 
 
 	private final HttpServletRequest request;