comparison src/luan/modules/http/HttpServicer.java @ 1283:503bde9a7c80

add luan.require() and table.call()
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 21 Dec 2018 09:12:09 -0700
parents 9fa8b8389578
children 25746915a241
comparison
equal deleted inserted replaced
1282:2531942abaf3 1283:503bde9a7c80
31 //e.printStackTrace(); 31 //e.printStackTrace();
32 synchronized(luan) { 32 synchronized(luan) {
33 LuanCloner cloner = new LuanCloner(LuanCloner.Type.INCREMENTAL); 33 LuanCloner cloner = new LuanCloner(LuanCloner.Type.INCREMENTAL);
34 luan = (LuanState)cloner.clone(luan); 34 luan = (LuanState)cloner.clone(luan);
35 } 35 }
36 LuanTable module = (LuanTable)PackageLuan.require(luan,"luan:http/Http.luan"); 36 LuanTable module = (LuanTable)luan.require("luan:http/Http.luan");
37 LuanFunction fn = (LuanFunction)module.rawGet("handle_error"); 37 return (Response)module.call( "handle_error", request, e.table(luan) );
38 return (Response)fn.call( luan, new Object[]{request,e.table(luan)} );
39 } 38 }
40 39
41 private static Response serviceLuan(LuanState luan,Request request,String modName) 40 private static Response serviceLuan(LuanState luan,Request request,String modName)
42 throws LuanException 41 throws LuanException
43 { 42 {
53 LuanCloner cloner = new LuanCloner(LuanCloner.Type.INCREMENTAL); 52 LuanCloner cloner = new LuanCloner(LuanCloner.Type.INCREMENTAL);
54 luan = (LuanState)cloner.clone(luan); 53 luan = (LuanState)cloner.clone(luan);
55 fn = (LuanFunction)cloner.get(mod); 54 fn = (LuanFunction)cloner.get(mod);
56 } 55 }
57 56
58 LuanTable module = (LuanTable)PackageLuan.require(luan,"luan:http/Http.luan"); 57 LuanTable module = (LuanTable)luan.require("luan:http/Http.luan");
59 58 module.call( "new_request", request );
60 // request 59 module.call( "new_response" );
61 LuanFunction newRequestFn = (LuanFunction)module.rawGet("new_request");
62 newRequestFn.call( luan, new Object[]{request} );
63
64 // response
65 LuanFunction newResponseFn = (LuanFunction)module.rawGet("new_response");
66 newResponseFn.call(luan);
67 60
68 fn.call(luan); 61 fn.call(luan);
69 62
70 LuanFunction finishFn = (LuanFunction)module.rawGet("finish"); 63 return (Response)module.call( "finish" );
71 Response response = (Response)finishFn.call(luan);
72 return response;
73 } 64 }
74 65
75 private HttpServicer() {} // never 66 private HttpServicer() {} // never
76 } 67 }