Mercurial Hosting > luan
comparison web/src/luan/modules/web/HttpServicer.java @ 426:23a93c118042
fix LuanTable.get() to use metatables
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 01 May 2015 18:44:20 -0600 |
parents | 91af5337b9ae |
children | dae264ad6a7b |
comparison
equal
deleted
inserted
replaced
425:0a2fb80907f9 | 426:23a93c118042 |
---|---|
49 if( mod==null ) | 49 if( mod==null ) |
50 return false; | 50 return false; |
51 if( !(mod instanceof LuanTable) ) | 51 if( !(mod instanceof LuanTable) ) |
52 throw luan.exception( "module '"+modName+"' must return a table" ); | 52 throw luan.exception( "module '"+modName+"' must return a table" ); |
53 LuanTable tbl = (LuanTable)mod; | 53 LuanTable tbl = (LuanTable)mod; |
54 if( Luan.toBoolean( tbl.get("per_session") ) ) { | 54 if( Luan.toBoolean( tbl.get(luan,"per_session") ) ) { |
55 HttpSession session = request.getSession(); | 55 HttpSession session = request.getSession(); |
56 LuanState sessionLuan = (LuanState)session.getValue("luan"); | 56 LuanState sessionLuan = (LuanState)session.getValue("luan"); |
57 if( sessionLuan!=null ) { | 57 if( sessionLuan!=null ) { |
58 luan = sessionLuan; | 58 luan = sessionLuan; |
59 } else { | 59 } else { |
69 luan = cloner.deepClone(luan); | 69 luan = cloner.deepClone(luan); |
70 fn = cloner.get(fn); | 70 fn = cloner.get(fn); |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
74 LuanTable module = (LuanTable)PackageLuan.loaded(luan).get("luan:web/Http"); | 74 LuanTable module = (LuanTable)PackageLuan.require(luan,"luan:web/Http"); |
75 if( module == null ) | |
76 throw luan.exception( "module 'web/Http' not defined" ); | |
77 HttpServicer lib = new HttpServicer(request,response); | 75 HttpServicer lib = new HttpServicer(request,response); |
78 try { | 76 try { |
79 module.put( "request", lib.requestTable() ); | 77 module.put( "request", lib.requestTable() ); |
80 module.put( "response", lib.responseTable() ); | 78 module.put( "response", lib.responseTable() ); |
81 module.put( "session", lib.sessionTable() ); | 79 module.put( "session", lib.sessionTable() ); |
97 } | 95 } |
98 | 96 |
99 private static LuanFunction getService(LuanState luan,LuanTable tbl) | 97 private static LuanFunction getService(LuanState luan,LuanTable tbl) |
100 throws LuanException | 98 throws LuanException |
101 { | 99 { |
102 Object service = tbl.get("service"); | 100 Object service = tbl.get(luan,"service"); |
103 if( service == null ) | 101 if( service == null ) |
104 throw luan.exception( "function 'service' is not defined" ); | 102 throw luan.exception( "function 'service' is not defined" ); |
105 if( !(service instanceof LuanFunction) ) | 103 if( !(service instanceof LuanFunction) ) |
106 throw luan.exception( "'service' must be a function but is a " + Luan.type(service) ); | 104 throw luan.exception( "'service' must be a function but is a " + Luan.type(service) ); |
107 return (LuanFunction)service; | 105 return (LuanFunction)service; |