diff http/src/luan/modules/http/LuanHandler.java @ 743:2c41f2aec92f

improve Rpc and implement rpc call for local webserver
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 13 Jul 2016 17:27:35 -0600
parents ca169567ce07
children 3f461f85243d
line wrap: on
line diff
--- a/http/src/luan/modules/http/LuanHandler.java	Tue Jul 12 17:47:30 2016 -0600
+++ b/http/src/luan/modules/http/LuanHandler.java	Wed Jul 13 17:27:35 2016 -0600
@@ -10,7 +10,10 @@
 import org.eclipse.jetty.server.Request;
 import org.eclipse.jetty.server.handler.AbstractHandler;
 import luan.LuanState;
+import luan.LuanTable;
+import luan.LuanFunction;
 import luan.LuanException;
+import luan.modules.PackageLuan;
 
 
 public class LuanHandler extends AbstractHandler {
@@ -58,4 +61,20 @@
 		super.destroy();
 	}
 */
+
+	public Object call_rpc(String fnName,Object... args) throws LuanException {
+		return callRpc(luan,fnName,args);
+	}
+
+	public static Object callRpc(LuanState luan,String fnName,Object... args) throws LuanException {
+		synchronized(luan) {
+			LuanTable rpc = (LuanTable)PackageLuan.require(luan,"luan:Rpc.luan");
+			LuanTable fns = (LuanTable)rpc.get(luan,"functions");
+			LuanFunction fn = (LuanFunction)fns.get(luan,fnName);
+			if( fn == null )
+				throw new LuanException( "function not found: " + fnName );
+			return fn.call(luan,args);
+		}
+	}
+
 }