<commit_before>local Route = require("route")
local Request = require("request")

local Application = {}

function Application:init(this, req, res)
        ls('Application:init')
        le('Application:init')
end

function Application:new()
        ls('Application.new')
        local base = {}
        base.id = 1123

        function base.init(this, req, res)
        ls('Application.base.init')
                lp("base:init")
                lp(base.id)
        le('Application.base.init')
        end

        local app = {}
        app.id = 123
        app.router = Route:getInstance()
        app.req = Request:getInstance()
        app.get = function(this, url, callback)
                ls('Application.app.get')
                ll('this type')
                lp(type(this))
                ll('this')
                for k,v in pairs(this) do
                        lp(k,v)
                end
                ll('url')
                lp(url)
                ll('callback type')
                lp(type(callback))
                ll()
                app:router(this, url, callback, "GET")
                le('Application.app.get')
        end

        app.post = function(this, url, callback)
                ls('Application.app.post')
                app:router(this, url, callback, "POST")
                le('Application.app.post')
        end

        app.run = function()
                ls('Application.app.run')
                fun = Route:run(app.router)
                if fun then
                    fun(app.req, app.id)
                end
                le('Application.app.run')
        end


        base.__call = base.init

        setmetatable(app, base)
        ll('APP Type')
        lp(type(app))
        ll('APP')
        for k,v in pairs(app) do
            lp(k,v)
        end
        le('Application:new')
        return app
end

function Application:get1(url, callback)
        ls('Application:get1')
        app.router(url, callback)
        le('Application:get1')
end

function Application:doEvent()
        ls('Application:doEvent')
        app.router("one", function()
                lp("test1")
        end)
        app.router("two", function()
                lp("test2")
        end)
        app.router("three", function()
                lp("test3")
        end)
        Route:run(app.router)
        le('Application:doEvent')
end

function Application:run()
        ls('Application:run')
        fun = Route:run(app.router)
        fun(app.req, app.id)
        le('Application:run')
end
<commit_msg>添加JSON数据返回演示处理。<commit_after>local Route = require("route")
local Request = require("request")

local Application = {}

function Application:init(this, req, res)
        ls('Application:init')
        le('Application:init')
end

function Application:new()
        ls('Application.new')
        local base = {}
        base.id = 1123

        function base.init(this, req, res)
        ls('Application.base.init')
                lp("base:init")
                lp(base.id)
        le('Application.base.init')
        end

        local app = {}
        app.id = 123
        app.router = Route:getInstance()
        app.req = Request:getInstance()
        app.get = function(this, url, callback)
                ls('Application.app.get')
                ll('this type')
                lp(type(this))
                ll('this')
                for k,v in pairs(this) do
                        lp(k,v)
                end
                ll('url')
                lp(url)
                ll('callback type')
                lp(type(callback))
                ll()
                app:router(this, url, callback, "GET")
                le('Application.app.get')
        end

        app.post = function(this, url, callback)
                ls('Application.app.post')
                app:router(this, url, callback, "POST")
                le('Application.app.post')
        end

        app.run = function()
                ls('Application.app.run')
                fun = Route:run(app.router)
                if fun then
                    local ret = fun(app.req, app.id)
                    local rtype = type(ret)
                    if rtype == "table"  then
                        json = require "cjson"
                        ngx.say(json.encode(ret))
                    end
                end
                le('Application.app.run')
        end


        base.__call = base.init

        setmetatable(app, base)
        ll('APP Type')
        lp(type(app))
        ll('APP')
        for k,v in pairs(app) do
            lp(k,v)
        end
        le('Application:new')
        return app
end

function Application:get1(url, callback)
        ls('Application:get1')
        app.router(url, callback)
        le('Application:get1')
end

function Application:doEvent()
        ls('Application:doEvent')
        app.router("one", function()
                lp("test1")
        end)
        app.router("two", function()
                lp("test2")
        end)
        app.router("three", function()
                lp("test3")
        end)
        Route:run(app.router)
        le('Application:doEvent')
end

function Application:run()
        ls('Application:run')
        fun = Route:run(app.router)
        local ret = fun(app.req, app.id)
        le('Application:run')
end

{'fraction_non_alphanumeric': 0.12310286677908938, 'fraction_numerical': 0.0048716507401161705, 'mean_word_length': 1.4142921754862052, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7404632', 'n_tokens_mistral': 1540, 'n_tokens_neox': 1437, 'n_words': 306}