Mercurial Hosting > luan
changeset 1088:bae2d0c2576c
change module naming convention
line wrap: on
line diff
--- a/examples/blog/src/lib/Db_mod.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/examples/blog/src/lib/Db_mod.luan Mon Dec 26 22:29:36 2016 -0700 @@ -2,12 +2,12 @@ local Io = require "luan:Io.luan" -local M = {} +local Db_mod = {} -M.lucene_dir = "site:/private/local/lucene" +Db_mod.lucene_dir = "site:/private/local/lucene" -function M.new_db() - local dir = Io.uri(M.lucene_dir).to_string() +function Db_mod.new_db() + local dir = Io.uri(Db_mod.lucene_dir).to_string() local db = Lucene.index( dir, Lucene.type.english, {"subject","content"} ) -- this is how you index a field @@ -16,4 +16,4 @@ return db end -return M +return Db_mod
--- a/examples/blog/src/lib/Post.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/examples/blog/src/lib/Post.luan Mon Dec 26 22:29:36 2016 -0700 @@ -9,10 +9,10 @@ local Db = require "site:/lib/Db.luan" -local M = {} +local Post = {} local function from_doc(doc) - return M.new { + return Post.new { id = doc.id subject = doc.subject content = doc.content @@ -20,7 +20,7 @@ } end -function M.new(this) +function Post.new(this) assert_string(this.subject) assert_string(this.content) this.date = this.date or now() @@ -40,12 +40,12 @@ return this end -function M.get_by_id(id) +function Post.get_by_id(id) local doc = Db.get_document("id:"..id) return doc and from_doc(doc) end -function M.get_all() +function Post.get_all() local docs = Db.search("type:post",1,1000,"id desc") local posts = {} for _, doc in ipairs(docs) do @@ -54,10 +54,10 @@ return posts end -function M.search(query) +function Post.search(query) query = trim(query) if #query == 0 then - return M.get_all() + return Post.get_all() end local docs = Db.search(query,1,1000) local posts = {} @@ -67,4 +67,4 @@ return posts end -return M +return Post
--- a/src/luan/modules/Binary.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/Binary.luan Mon Dec 26 22:29:36 2016 -0700 @@ -2,10 +2,10 @@ local BinaryLuan = require "java:luan.modules.BinaryLuan" -local M = {} +local Binary = {} -M.binary = BinaryLuan.binary -M.byte = BinaryLuan.byte_ -M.to_string = BinaryLuan.to_string +Binary.binary = BinaryLuan.binary +Binary.byte = BinaryLuan.byte_ +Binary.to_string = BinaryLuan.to_string -return M +return Binary
--- a/src/luan/modules/Html.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/Html.luan Mon Dec 26 22:29:36 2016 -0700 @@ -11,20 +11,20 @@ local output_of = Io.output_of or error() -local M = {} +local Html = {} -M.encode = HtmlLuan.encode +Html.encode = HtmlLuan.encode local quote = HtmlLuan.quote -M.quote = quote +Html.quote = quote -function M.parse(text,container_tags) +function Html.parse(text,container_tags) text or error "text required" container_tags = container_tags or {"script","style","textarea"} return HtmlParser.toList(text,container_tags) end -function M.url_encode(s) +function Html.url_encode(s) return URLEncoder.encode(s,"UTF-8") end @@ -43,7 +43,7 @@ %>><% end -function M.to_string(list) +function Html.to_string(list) return output_of( function() for _, obj in ipairs(list) do local tp = type(obj) @@ -73,4 +73,4 @@ end ) end -return M +return Html
--- a/src/luan/modules/Io.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/Io.luan Mon Dec 26 22:29:36 2016 -0700 @@ -2,20 +2,20 @@ local IoLuan = require "java:luan.modules.IoLuan" local System = require "java:java.lang.System" -local M = {} +local Io = {} -M.ip = IoLuan.ip -M.my_ips = IoLuan.my_ips -M.read_console_line = IoLuan.read_console_line -M.schemes = IoLuan.newSchemes() -M.uri = IoLuan.uri -M.stdin = IoLuan.defaultStdin.table() -M.socket_server = IoLuan.socket_server -M.stdout = IoLuan.textWriter(System.out) -M.stderr = IoLuan.textWriter(System.err) +Io.ip = IoLuan.ip +Io.my_ips = IoLuan.my_ips +Io.read_console_line = IoLuan.read_console_line +Io.schemes = IoLuan.newSchemes() +Io.uri = IoLuan.uri +Io.stdin = IoLuan.defaultStdin.table() +Io.socket_server = IoLuan.socket_server +Io.stdout = IoLuan.textWriter(System.out) +Io.stderr = IoLuan.textWriter(System.err) -- used by http and rpc -M.password = "password" +Io.password = "password" local Luan = require "luan:Luan.luan" local error = Luan.error @@ -34,12 +34,12 @@ -- do not change -function M.template_write(...) - return M.stdout.write(...) +function Io.template_write(...) + return Io.stdout.write(...) end -function M.print_to(out,...) +function Io.print_to(out,...) local list = {} for v in values(...) do list[#list+1] = to_string(v) @@ -51,30 +51,30 @@ end end -function M.print(...) - M.print_to(M.stdout,...) +function Io.print(...) + Io.print_to(Io.stdout,...) end -function M.output_to(out,fn,...) - local old_out = M.stdout +function Io.output_to(out,fn,...) + local old_out = Io.stdout return try( { function(...) - M.stdout = out + Io.stdout = out fn(...) end; finally = function() - M.stdout = old_out + Io.stdout = old_out end; }, ... ) end -local uri = M.uri -- make local +local uri = Io.uri -- make local -function M.output_of(fn,...) +function Io.output_of(fn,...) local string_uri = uri "string:" local out = string_uri.text_writer() - M.output_to(out,fn,...) + Io.output_to(out,fn,...) out.close() return string_uri.read_text() end @@ -126,7 +126,7 @@ end end -function M.repr(obj,strict) +function Io.repr(obj,strict) local string_uri = uri "string:" local out = string_uri.text_writer() do_repr(out,obj,strict or false,{}) @@ -138,9 +138,9 @@ -- useful for SimplyHTML responsiveness local NO = {} -M.NO = NO +Io.NO = NO -function M.dont_write_when_no(write_fn) +function Io.dont_write_when_no(write_fn) return function(...) for v in values(...) do if v == NO then @@ -154,10 +154,10 @@ -- debug -function M.debug(prompt) +function Io.debug(prompt) prompt = prompt or "luan_debug> " local function console() - return M.read_console_line(prompt) + return Io.read_console_line(prompt) end local env = {} for line in console do @@ -172,14 +172,14 @@ fn = load(line,"stdin",env) end } - M.print( fn() ) + Io.print( fn() ) end catch = function(e) - M.print(e) + Io.print(e) end } end end -return M +return Io
--- a/src/luan/modules/Luan.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/Luan.luan Mon Dec 26 22:29:36 2016 -0700 @@ -1,50 +1,50 @@ java() local BasicLuan = require "java:luan.modules.BasicLuan" -local M = {} +local Luan = {} -M.assert_binary = BasicLuan.assert_binary -M.assert_boolean = BasicLuan.assert_boolean -M.assert_function = BasicLuan.assert_function -M.assert_integer = BasicLuan.assert_integer -M.assert_long = BasicLuan.assert_long -M.assert_number = BasicLuan.assert_number -M.assert_string = BasicLuan.assert_string -M.assert_table = BasicLuan.assert_table -M.get_metatable = BasicLuan.get_metatable -M.ipairs = BasicLuan.ipairs -M.load = BasicLuan.load -M.load_file = BasicLuan.load_file -M.new_error = BasicLuan.new_error -M.pairs = BasicLuan.pairs -M.pcall = BasicLuan.pcall -M.range = BasicLuan.range -M.raw_equal = BasicLuan.raw_equal -M.raw_get = BasicLuan.raw_get -M.raw_len = BasicLuan.raw_len -M.raw_set = BasicLuan.raw_set -M.set_metatable = BasicLuan.set_metatable -M.to_string = BasicLuan.to_string -M.try = BasicLuan.try_ -M.type = BasicLuan.type -M.values = BasicLuan.values +Luan.assert_binary = BasicLuan.assert_binary +Luan.assert_boolean = BasicLuan.assert_boolean +Luan.assert_function = BasicLuan.assert_function +Luan.assert_integer = BasicLuan.assert_integer +Luan.assert_long = BasicLuan.assert_long +Luan.assert_number = BasicLuan.assert_number +Luan.assert_string = BasicLuan.assert_string +Luan.assert_table = BasicLuan.assert_table +Luan.get_metatable = BasicLuan.get_metatable +Luan.ipairs = BasicLuan.ipairs +Luan.load = BasicLuan.load +Luan.load_file = BasicLuan.load_file +Luan.new_error = BasicLuan.new_error +Luan.pairs = BasicLuan.pairs +Luan.pcall = BasicLuan.pcall +Luan.range = BasicLuan.range +Luan.raw_equal = BasicLuan.raw_equal +Luan.raw_get = BasicLuan.raw_get +Luan.raw_len = BasicLuan.raw_len +Luan.raw_set = BasicLuan.raw_set +Luan.set_metatable = BasicLuan.set_metatable +Luan.to_string = BasicLuan.to_string +Luan.try = BasicLuan.try_ +Luan.type = BasicLuan.type +Luan.values = BasicLuan.values -function M.do_file(uri) - return M.load_file(uri)() +function Luan.do_file(uri) + return Luan.load_file(uri)() end -M.VERSION = M.do_file "classpath:luan/version.luan" +Luan.VERSION = Luan.do_file "classpath:luan/version.luan" -function M.error(message) - M.new_error(message).throw() +function Luan.error(message) + Luan.new_error(message).throw() end -function M.assert(v,message) - return v or M.error(message or "assertion failed!") +function Luan.assert(v,message) + return v or Luan.error(message or "assertion failed!") end -function M.eval(s,source_name) - return M.load( "return "..s, source_name or "eval" )() +function Luan.eval(s,source_name) + return Luan.load( "return "..s, source_name or "eval" )() end -return M +return Luan
--- a/src/luan/modules/Math.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/Math.luan Mon Dec 26 22:29:36 2016 -0700 @@ -5,32 +5,32 @@ local Double = require "java:java.lang.Double" -local M = {} +local Math = {} -M.abs = MathLuan.abs -M.acos = MathLuan.acos -M.asin = MathLuan.asin -M.atan = MathLuan.atan -M.atan2 = MathLuan.atan2 -M.ceil = MathLuan.ceil -M.cos = MathLuan.cos -M.cosh = MathLuan.cosh -M.deg = MathLuan.deg -M.exp = MathLuan.exp -M.floor = MathLuan.floor -M.fmod = MathLuan.fmod -M.huge = Double.POSITIVE_INFINITY -M.log = MathLuan.log -M.max = MathLuan.max -M.max_integer = Integer.MAX_VALUE -M.min = MathLuan.min -M.min_integer = Integer.MIN_VALUE -M.modf = MathLuan.modf -M.pi = JavaMath.PI -M.rad = MathLuan.rad -M.random = MathLuan.random -M.sin = MathLuan.sin -M.sqrt = MathLuan.sqrt -M.tan = MathLuan.tan +Math.abs = MathLuan.abs +Math.acos = MathLuan.acos +Math.asin = MathLuan.asin +Math.atan = MathLuan.atan +Math.atan2 = MathLuan.atan2 +Math.ceil = MathLuan.ceil +Math.cos = MathLuan.cos +Math.cosh = MathLuan.cosh +Math.deg = MathLuan.deg +Math.exp = MathLuan.exp +Math.floor = MathLuan.floor +Math.fmod = MathLuan.fmod +Math.huge = Double.POSITIVE_INFINITY +Math.log = MathLuan.log +Math.max = MathLuan.max +Math.max_integer = Integer.MAX_VALUE +Math.min = MathLuan.min +Math.min_integer = Integer.MIN_VALUE +Math.modf = MathLuan.modf +Math.pi = JavaMath.PI +Math.rad = MathLuan.rad +Math.random = MathLuan.random +Math.sin = MathLuan.sin +Math.sqrt = MathLuan.sqrt +Math.tan = MathLuan.tan -return M +return Math
--- a/src/luan/modules/Number.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/Number.luan Mon Dec 26 22:29:36 2016 -0700 @@ -3,12 +3,12 @@ local MathLuan = require "java:luan.modules.MathLuan" -local M = {} +local Number = {} -M.double = BasicLuan.assert_double -M.integer = BasicLuan.assert_integer -M.long = BasicLuan.assert_long -M.long_to_string = MathLuan.long_to_string -M.type = BasicLuan.number_type +Number.double = BasicLuan.assert_double +Number.integer = BasicLuan.assert_integer +Number.long = BasicLuan.assert_long +Number.long_to_string = MathLuan.long_to_string +Number.type = BasicLuan.number_type -return M +return Number
--- a/src/luan/modules/Package.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/Package.luan Mon Dec 26 22:29:36 2016 -0700 @@ -1,9 +1,9 @@ java() local PackageLuan = require "java:luan.modules.PackageLuan" -local M = {} +local Package = {} -M.loaded = PackageLuan.loaded() -M.load = PackageLuan.load +Package.loaded = PackageLuan.loaded() +Package.load = PackageLuan.load -return M +return Package
--- a/src/luan/modules/Parsers.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/Parsers.luan Mon Dec 26 22:29:36 2016 -0700 @@ -4,13 +4,13 @@ local Theme = require "java:luan.modules.parsers.Theme" local Json = require "java:luan.modules.parsers.Json" -local M = {} +local Parsers = {} -M.bbcode_to_html = BBCode.toHtml -M.bbcode_to_text = BBCode.toText -M.csv_to_list = Csv.toList -M.json_parse = Json.parse -- converts json string to luan object -M.json_string = Json.toString -- converts luan object to json string -M.theme_to_luan = Theme.toLuan +Parsers.bbcode_to_html = BBCode.toHtml +Parsers.bbcode_to_text = BBCode.toText +Parsers.csv_to_list = Csv.toList +Parsers.json_parse = Json.parse -- converts json string to luan object +Parsers.json_string = Json.toString -- converts luan object to json string +Parsers.theme_to_luan = Theme.toLuan -return M +return Parsers
--- a/src/luan/modules/Rpc.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/Rpc.luan Mon Dec 26 22:29:36 2016 -0700 @@ -10,24 +10,24 @@ local logger = Logging.logger "Rpc" -local M = {} +local Rpc = {} -M.port = 9101 +Rpc.port = 9101 -M.call = RpcLuan.call -- Rpc.call(socket,fn_name,...) +Rpc.call = RpcLuan.call -- Rpc.call(socket,fn_name,...) -M.functions = {} +Rpc.functions = {} -function M.respond(socket,fns) - RpcLuan.respond( socket, fns or M.functions ) +function Rpc.respond(socket,fns) + RpcLuan.respond( socket, fns or Rpc.functions ) end -function M.remote_socket(socket_uri) +function Rpc.remote_socket(socket_uri) local mt = {} function mt.__index(_,key) return function(...) local socket = Io.uri(socket_uri) - return M.call(socket,key,...) + return Rpc.call(socket,key,...) end end local t = {} @@ -35,13 +35,13 @@ return t end -function M.remote(domain) - local socket = "socket:" .. domain .. ":" .. M.port - return M.remote_socket(socket) +function Rpc.remote(domain) + local socket = "socket:" .. domain .. ":" .. Rpc.port + return Rpc.remote_socket(socket) end -function M.serve(port,fns) - local server = Io.socket_server(port or M.port) +function Rpc.serve(port,fns) + local server = Io.socket_server(port or Rpc.port) while true do try { function() @@ -49,7 +49,7 @@ local function respond() try { function() - M.respond(socket,fns) + Rpc.respond(socket,fns) end catch = function(e) logger.error(e) @@ -65,4 +65,4 @@ end end -return M +return Rpc
--- a/src/luan/modules/String.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/String.luan Mon Dec 26 22:29:36 2016 -0700 @@ -2,27 +2,27 @@ local StringLuan = require "java:luan.modules.StringLuan" local Pattern = require "java:java.util.regex.Pattern" -local M = {} +local String = {} -M.char = StringLuan.char_ -M.concat = StringLuan.concat -M.encode = StringLuan.encode -M.find = StringLuan.find -M.format = StringLuan.format -M.gmatch = StringLuan.gmatch -M.gsub = StringLuan.gsub -M.literal = Pattern.quote -M.lower = StringLuan.lower -M.match = StringLuan.match -M.matches = StringLuan.matches -M.rep = StringLuan.rep -M.reverse = StringLuan.reverse -M.split = StringLuan.split -M.sub = StringLuan.sub -M.to_binary = StringLuan.to_binary -M.to_number = StringLuan.to_number -M.trim = StringLuan.trim -M.unicode = StringLuan.unicode -M.upper = StringLuan.upper +String.char = StringLuan.char_ +String.concat = StringLuan.concat +String.encode = StringLuan.encode +String.find = StringLuan.find +String.format = StringLuan.format +String.gmatch = StringLuan.gmatch +String.gsub = StringLuan.gsub +String.literal = Pattern.quote +String.lower = StringLuan.lower +String.match = StringLuan.match +String.matches = StringLuan.matches +String.rep = StringLuan.rep +String.reverse = StringLuan.reverse +String.split = StringLuan.split +String.sub = StringLuan.sub +String.to_binary = StringLuan.to_binary +String.to_number = StringLuan.to_number +String.trim = StringLuan.trim +String.unicode = StringLuan.unicode +String.upper = StringLuan.upper -return M +return String
--- a/src/luan/modules/Table.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/Table.luan Mon Dec 26 22:29:36 2016 -0700 @@ -1,23 +1,23 @@ java() local TableLuan = require "java:luan.modules.TableLuan" -local M = {} +local Table = {} -M.clear = TableLuan.clear -M.concat = TableLuan.concat -M.copy = TableLuan.copy -M.insert = TableLuan.insert -M.pack = TableLuan.pack -M.remove = TableLuan.remove -M.sort = TableLuan.sort -M.unpack = TableLuan.unpack +Table.clear = TableLuan.clear +Table.concat = TableLuan.concat +Table.copy = TableLuan.copy +Table.insert = TableLuan.insert +Table.pack = TableLuan.pack +Table.remove = TableLuan.remove +Table.sort = TableLuan.sort +Table.unpack = TableLuan.unpack local Luan = require "luan:Luan.luan" local pairs = Luan.pairs -function M.is_empty(t) +function Table.is_empty(t) return pairs(t)() == nil end -return M +return Table
--- a/src/luan/modules/Thread.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/Thread.luan Mon Dec 26 22:29:36 2016 -0700 @@ -5,16 +5,16 @@ local set_metatable = Luan.set_metatable or error() -local M = {} +local Thread = {} -M.fork = ThreadLuan.fork -M.schedule = ThreadLuan.schedule +Thread.fork = ThreadLuan.fork +Thread.schedule = ThreadLuan.schedule -M.global = {} -- shared across threads +Thread.global = {} -- shared across threads local map = ThreadLuan.StringMap.new() local global_mt = {} -set_metatable(M.global,global_mt) +set_metatable(Thread.global,global_mt) function global_mt.__index(_,key) return map.get(key) @@ -33,4 +33,4 @@ end -return M +return Thread
--- a/src/luan/modules/Time.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/Time.luan Mon Dec 26 22:29:36 2016 -0700 @@ -14,9 +14,9 @@ local TimeZone = require "java:java.util.TimeZone" local SimpleDateFormat = require "java:java.text.SimpleDateFormat" -local M = {} +local Time = {} -function M.now() +function Time.now() return System.currentTimeMillis() end @@ -27,7 +27,7 @@ day_of_month = Calendar.DAY_OF_MONTH; } -function M.get( time, ... ) +function Time.get( time, ... ) local cal = Calendar.getInstance() cal.setTimeInMillis(time) local rtn = {} @@ -43,13 +43,13 @@ return Table.unpack(rtn) end -function M.format(time,pattern) +function Time.format(time,pattern) time = assert_long(time) pattern = pattern or "yyyy-MM-dd HH:mm:ss" return SimpleDateFormat.new(pattern).format(Date.new(time)) end -function M.on( year, month, day, hour, minute, second, millis ) +function Time.on( year, month, day, hour, minute, second, millis ) month = month - 1 local cal = Calendar.getInstance() cal.setLenient(false) @@ -58,7 +58,7 @@ return cal.getTimeInMillis() end -function M.period( t ) +function Time.period( t ) local cal = Calendar.getInstance() cal.setTimeZone(TimeZone.getTimeZone("GMT")) local days = t.days or 0 @@ -68,19 +68,19 @@ return cal.getTimeInMillis() end -function M.parse( pattern, source ) +function Time.parse( pattern, source ) return SimpleDateFormat.new(pattern).parse(source).getTime() end local count_times = { - days = M.period{days=1} - hours = M.period{hours=1} - minutes = M.period{minutes=1} - seconds = M.period{seconds=1} + days = Time.period{days=1} + hours = Time.period{hours=1} + minutes = Time.period{minutes=1} + seconds = Time.period{seconds=1} } -function M.count( time, ... ) +function Time.count( time, ... ) local cal = Calendar.getInstance() cal.setTimeInMillis(time) local rtn = {} @@ -95,4 +95,4 @@ end -return M +return Time
--- a/src/luan/modules/Which_mod.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/Which_mod.luan Mon Dec 26 22:29:36 2016 -0700 @@ -10,9 +10,9 @@ local print = Io.print or error() -local M = {} +local Which_mod = {} -M.uris = { +Which_mod.uris = { "luan:Luan" "luan:Binary" "luan:Html" @@ -33,9 +33,9 @@ "luan:stripe/Stripe" } -function M.which(name) +function Which_mod.which(name) local ptn = "[:./]"..literal(name).."$" - for _, uri in ipairs(M.uris) do + for _, uri in ipairs(Which_mod.uris) do local mod = require(uri) if matches(uri,ptn) then print(uri) @@ -50,4 +50,4 @@ end end -return M +return Which_mod
--- a/src/luan/modules/host/Hosting.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/host/Hosting.luan Mon Dec 26 22:29:36 2016 -0700 @@ -12,10 +12,10 @@ local matches = String.matches or error() -local M = {} +local Hosting = {} -function M.push(domain,password,dir) +function Hosting.push(domain,password,dir) local my_dir = Io.uri("file:"..dir) my_dir.exists() or error("directory '"..dir.."' not found") my_dir.is_directory() or error("'"..dir.."' is not a directory") @@ -61,27 +61,27 @@ host.update_handler(domain,password) end -function M.delete(domain,password) +function Hosting.delete(domain,password) local host = Rpc.remote(domain) host.delete(domain,password) end -function M.exists(domain) +function Hosting.exists(domain) local host = Rpc.remote(domain) return host.exists(domain) end -function M.change_domain(old_domain,new_domain,password) +function Hosting.change_domain(old_domain,new_domain,password) local host = Rpc.remote(new_domain) return host.change_domain(old_domain,new_domain,password) end -function M.change_password(domain,old_password,new_password) +function Hosting.change_password(domain,old_password,new_password) local host = Rpc.remote(domain) return host.change_password(domain,old_password,new_password) end -function M.caller(domain) +function Hosting.caller(domain) local host = Rpc.remote(domain) local mt = {} function mt.__index(_,key) @@ -94,4 +94,4 @@ return t end -return M +return Hosting
--- a/src/luan/modules/http/Http.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/http/Http.luan Mon Dec 26 22:29:36 2016 -0700 @@ -15,7 +15,7 @@ local HttpServicer = require "java:luan.modules.http.HttpServicer" local IoLuan = require "java:luan.modules.IoLuan" -local M = {} +local Http = {} local singular_metatable = {} @@ -42,7 +42,7 @@ local sent_error_metatable = { __index=sent_error, __new_index=sent_error } -function M.sent_headers(headers) +function Http.sent_headers(headers) clear(headers) set_metatable(headers,sent_error_metatable) end @@ -57,7 +57,7 @@ end -function M.new_request(this) +function Http.new_request(this) this = new_common(this) this.method = "GET" -- default -- this.path @@ -102,9 +102,9 @@ OK = 200; -- add more as needed } -M.STATUS = STATUS +Http.STATUS = STATUS -function M.new_response(this) +function Http.new_response(this) this = new_common(this) this.status = STATUS.OK if this.java ~= nil then @@ -112,16 +112,16 @@ this.send_error = this.java.sendError function this.set_cookie(name,value,is_persistent,domain) - HttpServicer.setCookie(M.request.java,this.java,name,value,is_persistent,domain) + HttpServicer.setCookie(Http.request.java,this.java,name,value,is_persistent,domain) end function this.remove_cookie(name,domain) - HttpServicer.removeCookie(M.request.java,this.java,name,domain) + HttpServicer.removeCookie(Http.request.java,this.java,name,domain) end function this.set() HttpServicer.setResponse(this,this.java) - M.sent_headers(this.headers) + Http.sent_headers(this.headers) end function this.text_writer() @@ -148,18 +148,18 @@ -- response = new_response{} -- filled in by HttpServicer -M.per_session_pages = {} +Http.per_session_pages = {} -function M.per_session(page) - M.per_session_pages[page] = true +function Http.per_session(page) + Http.per_session_pages[page] = true end -function M.clear_session() - M.request.java.getSession().removeAttribute("luan") +function Http.clear_session() + Http.request.java.getSession().removeAttribute("luan") end -function M.uncache_site() +function Http.uncache_site() for k in pairs(Table.copy(Package.loaded)) do if matches(k,"^site:") then Package.loaded[k] = nil @@ -167,6 +167,6 @@ end end -M.run_later = HttpServicer.run_later +Http.run_later = HttpServicer.run_later -return M +return Http
--- a/src/luan/modules/http/Http_test.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/http/Http_test.luan Mon Dec 26 22:29:36 2016 -0700 @@ -9,15 +9,15 @@ local Http = require "luan:http/Http.luan" -local M = {} +local Http_test = {} -M.welcome_file = "index.html" -M.cookie = {} +Http_test.welcome_file = "index.html" +Http_test.cookie = {} -function M.get_page(path) +function Http_test.get_page(path) Http.request.path = path - if M.welcome_file ~= nil and matches(path,"/$") then - path = path .. M.welcome_file + if Http_test.welcome_file ~= nil and matches(path,"/$") then + path = path .. Http_test.welcome_file end local old_out = Io.stdout try { @@ -30,34 +30,34 @@ not_found or error(path.." not found") not_found() end - M.text_writer.close() + Http_test.text_writer.close() end finally = function() Io.stdout = old_out end } - return M.result.read_text() + return Http_test.result.read_text() end -function M.init() +function Http_test.init() Http.request = Http.new_request{} - Http.request.cookie = M.cookie + Http.request.cookie = Http_test.cookie Http.response = Http.new_response{ text_writer = function() Http.sent_headers(Http.response.headers) - M.result = Io.uri "string:" - M.text_writer = M.result.text_writer() - return M.text_writer + Http_test.result = Io.uri "string:" + Http_test.text_writer = Http_test.result.text_writer() + return Http_test.text_writer end set_cookie = function(name,value) - M.cookie[name] = value + Http_test.cookie[name] = value end remove_cookie = function(name) - M.cookie[name] = nil + Http_test.cookie[name] = nil end send_redirect = function(url) @@ -72,4 +72,4 @@ end -return M +return Http_test
--- a/src/luan/modules/http/Server.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/http/Server.luan Mon Dec 26 22:29:36 2016 -0700 @@ -13,7 +13,7 @@ local logger = Logging.logger "http/Server" java() -local Server = require "java:org.eclipse.jetty.server.Server" +local JavaServer = require "java:org.eclipse.jetty.server.Server" local NCSARequestLog = require "java:org.eclipse.jetty.server.NCSARequestLog" local DefaultHandler = require "java:org.eclipse.jetty.server.handler.DefaultHandler" local HandlerList = require "java:org.eclipse.jetty.server.handler.HandlerList" @@ -28,90 +28,90 @@ local LuanHandler = require "java:luan.modules.http.LuanHandler" local NotFound = require "java:luan.modules.http.NotFound" -local M = {} +local Server = {} -M.port = 8080 +Server.port = 8080 -M.welcome_file = "index.html" +Server.welcome_file = "index.html" -M.authentication_handler = AuthenticationHandler.new("/private/") +Server.authentication_handler = AuthenticationHandler.new("/private/") -M.luan_handler = LuanHandler.new() +Server.luan_handler = LuanHandler.new() -M.resource_handler = ResourceHandler.new() -M.resource_handler.setDirectoriesListed(true) +Server.resource_handler = ResourceHandler.new() +Server.resource_handler.setDirectoriesListed(true) -M.handlers = HandlerList.new() -M.handlers.setHandlers { M.authentication_handler, M.luan_handler, M.resource_handler } +Server.handlers = HandlerList.new() +Server.handlers.setHandlers { Server.authentication_handler, Server.luan_handler, Server.resource_handler } -function M.add_folder(context,dir) +function Server.add_folder(context,dir) local rh = ResourceHandler.new() rh.setResourceBase(dir) rh.setDirectoriesListed(true) local ch = ContextHandler.new(context) ch.setHandler(rh) - M.handlers.addHandler(ch) + Server.handlers.addHandler(ch) return rh end -M.handler_wrapper = HandlerWrapper.new() -M.handler_wrapper.setHandler(M.handlers) +Server.handler_wrapper = HandlerWrapper.new() +Server.handler_wrapper.setHandler(Server.handlers) -function M.zip() +function Server.zip() local h = GzipHandler.new() - h.setHandler(M.handler_wrapper.getHandler()) - M.handler_wrapper.setHandler(h) + h.setHandler(Server.handler_wrapper.getHandler()) + Server.handler_wrapper.setHandler(h) end -M.log = NCSARequestLog.new() -M.log.setExtended(false) -M.log_handler = RequestLogHandler.new() -M.log_handler.setRequestLog(M.log) +Server.log = NCSARequestLog.new() +Server.log.setExtended(false) +Server.log_handler = RequestLogHandler.new() +Server.log_handler.setRequestLog(Server.log) -function M.set_log_file(file_name) - M.log.setFilename(file_name) +function Server.set_log_file(file_name) + Server.log.setFilename(file_name) end local hc = HandlerCollection.new() -hc.setHandlers { SessionHandler.new(), M.handler_wrapper, DefaultHandler.new(), M.log_handler } +hc.setHandlers { SessionHandler.new(), Server.handler_wrapper, DefaultHandler.new(), Server.log_handler } -function M.init(dir) +function Server.init(dir) dir = gsub(dir,"/$","") -- remove trailing '/' if any Http.dir = dir function Io.schemes.site(path) return Io.uri( dir..path ) end - M.authentication_handler.setPassword(Io.password) + Server.authentication_handler.setPassword(Io.password) local base = dir if matches(base,"^classpath:") then - base = dir.."#"..M.welcome_file.."#"..M.welcome_file..".luan" + base = dir.."#"..Server.welcome_file.."#"..Server.welcome_file..".luan" end - M.resource_handler.setResourceBase(Io.uri(base).to_string()) - M.resource_handler.setWelcomeFiles {M.welcome_file} - M.luan_handler.setWelcomeFile(M.welcome_file) - M.handlers.addHandler(NotFound.new(M.luan_handler)) - M.server = Server.new(M.port) - M.server.setHandler(hc) + Server.resource_handler.setResourceBase(Io.uri(base).to_string()) + Server.resource_handler.setWelcomeFiles {Server.welcome_file} + Server.luan_handler.setWelcomeFile(Server.welcome_file) + Server.handlers.addHandler(NotFound.new(Server.luan_handler)) + Server.server = JavaServer.new(Server.port) + Server.server.setHandler(hc) end -function M.start() - LuanHandler.start(M.server) +function Server.start() + LuanHandler.start(Server.server) end -function M.start_rpc() +function Server.start_rpc() function Rpc.functions.call(domain,fn_name,...) - return M.luan_handler.call_rpc(fn_name,...) + return Server.luan_handler.call_rpc(fn_name,...) end Thread.fork(Rpc.serve) end -function M.serve(dir) - M.init(dir) - M.start_rpc() - M.start() +function Server.serve(dir) + Server.init(dir) + Server.start_rpc() + Server.start() end -return M +return Server
--- a/src/luan/modules/http/tools/Dump_mod.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/http/tools/Dump_mod.luan Mon Dec 26 22:29:36 2016 -0700 @@ -6,12 +6,12 @@ java() local HttpServicer = require "java:luan.modules.http.HttpServicer" -local M = {} +local Dump_mod = {} local to_http_header_name = HttpServicer.toHttpHeaderName -M.to_http_header_name = to_http_header_name +Dump_mod.to_http_header_name = to_http_header_name -function M.respond() +function Dump_mod.respond() Http.response.header.content_type = "text/plain" Io.stdout = Http.response.text_writer() @@ -24,7 +24,7 @@ %> <%=method%> <%=path%> <%=Http.request.protocol%> <% - M.dump_headers(Http.request.headers) + Dump_mod.dump_headers(Http.request.headers) %> <% @@ -36,7 +36,7 @@ end -function M.dump_headers(headers) +function Dump_mod.dump_headers(headers) for name, values in pairs(headers) do local header_name = to_http_header_name(name) for _, value in ipairs(values) do @@ -47,4 +47,4 @@ end end -return M +return Dump_mod
--- a/src/luan/modules/http/tools/Shell_mod.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/http/tools/Shell_mod.luan Mon Dec 26 22:29:36 2016 -0700 @@ -8,12 +8,12 @@ local Http = require "luan:http/Http.luan" -local M = {} +local Shell_mod = {} local history = {} -M.env = {} +Shell_mod.env = {} -function M.respond() +function Shell_mod.respond() if Http.request.parameter.clear ~= nil then Http.clear_session() Http.response.send_redirect(Http.request.path) -- reload page @@ -33,10 +33,10 @@ local line try { function() - line = load("return "..cmd,"<web_shell>",M.env) + line = load("return "..cmd,"<web_shell>",Shell_mod.env) end catch = function(e) - line = load(cmd,"<web_shell>",M.env) + line = load(cmd,"<web_shell>",Shell_mod.env) end } print( line() ) @@ -103,6 +103,6 @@ <% end -Http.per_session(M.respond) +Http.per_session(Shell_mod.respond) -return M +return Shell_mod
--- a/src/luan/modules/logging/Logging.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/logging/Logging.luan Mon Dec 26 22:29:36 2016 -0700 @@ -6,49 +6,49 @@ local RollingFileAppender = require "java:org.apache.log4j.RollingFileAppender" local LuanLogger = require "java:luan.modules.logging.LuanLogger" -local M = {} +local Logging = {} -M.layout = "%d %-5p %c - %m%n" +Logging.layout = "%d %-5p %c - %m%n" -M.level = "INFO" +Logging.level = "INFO" -M.console = "System.err" -- or "System.out" or set to nil for no console +Logging.console = "System.err" -- or "System.out" or set to nil for no console -M.file = nil -- set to file name if you want logging to a file +Logging.file = nil -- set to file name if you want logging to a file -M.max_file_size = nil -- by default is "10MB" +Logging.max_file_size = nil -- by default is "10MB" -M.log4j_root_logger = Logger.getRootLogger() +Logging.log4j_root_logger = Logger.getRootLogger() local function to_level(level) return level and Level.toLevel(level) end -function M.log_to_file(file,logger_name) -- logger_name is optional, defaults to root logger - local appender = RollingFileAppender.new(M.ptn_layout, file) - appender.setMaxFileSize(M.max_file_size) - local logger = logger_name and Logger.getLogger(logger_name) or M.log4j_root_logger +function Logging.log_to_file(file,logger_name) -- logger_name is optional, defaults to root logger + local appender = RollingFileAppender.new(Logging.ptn_layout, file) + appender.setMaxFileSize(Logging.max_file_size) + local logger = logger_name and Logger.getLogger(logger_name) or Logging.log4j_root_logger logger.addAppender(appender) return appender end -function M.init() - M.log4j_root_logger.removeAllAppenders() - M.log4j_root_logger.setLevel( to_level(M.level) ) - M.ptn_layout = EnhancedPatternLayout.new(M.layout) +function Logging.init() + Logging.log4j_root_logger.removeAllAppenders() + Logging.log4j_root_logger.setLevel( to_level(Logging.level) ) + Logging.ptn_layout = EnhancedPatternLayout.new(Logging.layout) - if M.console ~= nil then - M.console_appender = ConsoleAppender.new(M.ptn_layout,M.console) - M.log4j_root_logger.addAppender(M.console_appender) + if Logging.console ~= nil then + Logging.console_appender = ConsoleAppender.new(Logging.ptn_layout,Logging.console) + Logging.log4j_root_logger.addAppender(Logging.console_appender) else - M.console_appender = nil + Logging.console_appender = nil end - if M.file ~= nil then - M.file_appender = M.log_to_file(M.file) + if Logging.file ~= nil then + Logging.file_appender = Logging.log_to_file(Logging.file) else - M.file_appender = nil + Logging.file_appender = nil end end @@ -79,12 +79,12 @@ return tbl end -function M.logger(name) +function Logging.logger(name) return to_luan_logger( Logger.getLogger(name) ) end -function M.root_logger() +function Logging.root_logger() return to_luan_logger( Logger.getRootLogger() ) end -return M +return Logging
--- a/src/luan/modules/lucene/Ab_testing.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/lucene/Ab_testing.luan Mon Dec 26 22:29:36 2016 -0700 @@ -12,11 +12,11 @@ local Logging = require "luan:logging/Logging.luan" local Lucene = require "luan:lucene/Lucene.luan" -local M = {} +local Ab_testing = {} local logger = Logging.logger "Ab_testing" -function M.of(index) +function Ab_testing.of(index) local ab_testing = {} @@ -94,8 +94,8 @@ for value, count in pairs(results[event]) do fancy[event][value] = {} fancy[event][value].count = count - fancy[event][value].pct_of_total = M.percent(count,all[value]) - fancy[event][value].pct_of_prev = M.percent(count,prev[value]) + fancy[event][value].pct_of_total = Ab_testing.percent(count,all[value]) + fancy[event][value].pct_of_prev = Ab_testing.percent(count,prev[value]) end prev = results[event] end @@ -143,7 +143,7 @@ results[name] = test.fancy_results() end Io.stdout = Http.response.text_writer() - M.html(test_names,ab_testing.test_map,results) + Ab_testing.html(test_names,ab_testing.test_map,results) end end @@ -154,7 +154,7 @@ -- aggregator factories -- fn(doc) should return boolean whether doc should be counted -function M.count(fn) +function Ab_testing.count(fn) return function() local aggregator = {} aggregator.result = 0 @@ -167,10 +167,10 @@ end end -M.count_all = M.count( function(doc) return true end ) +Ab_testing.count_all = Ab_testing.count( function(doc) return true end ) -- fn(doc) should return number to add to result, return 0 for nothing -function M.sum(fn) +function Ab_testing.sum(fn) return function() local aggregator = {} aggregator.result = 0 @@ -183,7 +183,7 @@ -function M.percent(x,total) +function Ab_testing.percent(x,total) if total==0 then return 0 else @@ -207,7 +207,7 @@ return gsub( v, [[(\d+\.\d{1})\d+]], '$1' ) end -function M.html(test_names,tests,results) %> +function Ab_testing.html(test_names,tests,results) %> <!DOCTYPE html> <html lang="en"> <head> @@ -269,4 +269,4 @@ </html> <% end -return M +return Ab_testing
--- a/src/luan/modules/lucene/Lucene.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/lucene/Lucene.luan Mon Dec 26 22:29:36 2016 -0700 @@ -18,11 +18,11 @@ local EnglishAnalyzer = require "java:org.apache.lucene.analysis.en.EnglishAnalyzer" -local M = {} +local Lucene = {} -M.instances = {} +Lucene.instances = {} -M.type = { +Lucene.type = { string = LuceneIndex.STRING_FIELD_PARSER; integer = NumberFieldParser.INT; long = NumberFieldParser.LONG; @@ -31,9 +31,9 @@ english = StringFieldParser.new(EnglishAnalyzer.new(Version.LUCENE_CURRENT)) } -M.literal = SaneQueryParser.literal +Lucene.literal = SaneQueryParser.literal -function M.index(index_dir,default_type,default_fields) +function Lucene.index(index_dir,default_type,default_fields) local index = {} index.dir = index_dir local java_index = LuceneIndex.new(index_dir,default_type,default_fields) @@ -66,10 +66,10 @@ index.next_id = java_index.nextId index.highlighter = java_index.highlighter - M.instances[index] = true + Lucene.instances[index] = true function index.close() - M.instances[index] = nil + Lucene.instances[index] = nil java_index.close() end @@ -169,4 +169,4 @@ return index end -return M +return Lucene
--- a/src/luan/modules/lucene/Versioning.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/lucene/Versioning.luan Mon Dec 26 22:29:36 2016 -0700 @@ -17,9 +17,9 @@ local logger = Logging.logger "lucene versioning" -local M = {} +local Versioning = {} -function M.update(db,steps,version) +function Versioning.update(db,steps,version) local doc = db.get_document"type:version" or { type="version", version=integer(0) } while doc.version < version do doc.version = integer(doc.version + 1) @@ -34,7 +34,7 @@ -- hack to deal with latest changes -function M.a_big_step(db) +function Versioning.a_big_step(db) db.indexed_fields["id index"] = Lucene.type.string db.advanced_search( Lucene.literal"id index" .. ":*", function(_,doc_fn) local doc = doc_fn() @@ -53,4 +53,4 @@ db.delete( Lucene.literal"type index" .. ":*" ) end -return M +return Versioning
--- a/src/luan/modules/lucene/Web_search.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/lucene/Web_search.luan Mon Dec 26 22:29:36 2016 -0700 @@ -1,4 +1,4 @@ - local Luan = require "luan:Luan.luan" +local Luan = require "luan:Luan.luan" local error = Luan.error local pairs = Luan.pairs or error() local ipairs = Luan.ipairs or error() @@ -12,7 +12,7 @@ local Html = require "luan:Html.luan" -local M = {} +local Web_search = {} local function style() %> body { @@ -159,7 +159,7 @@ end -function M.of(index) +function Web_search.of(index) index or error "index is nil" return function() @@ -186,4 +186,4 @@ end -return M +return Web_search
--- a/src/luan/modules/mail/Mail.luan Mon Dec 19 01:38:21 2016 -0700 +++ b/src/luan/modules/mail/Mail.luan Mon Dec 26 22:29:36 2016 -0700 @@ -4,14 +4,14 @@ local System = require "java:java.lang.System" local SmtpCon = require "java:luan.modules.mail.SmtpCon" -local M = {} +local Mail = {} System.setProperty( "mail.mime.charset", "UTF-8" ) -function M.Sender(params) +function Mail.Sender(params) assert_table(params) local smtpCon = SmtpCon.new(params) return { send = smtpCon.send } end -return M +return Mail