-------------------------------------------------------------------------------- -- Title: LWInfoPage.lua -- Description: Like a square peg in a round hole -- Author: Raphaël Szwarc http://alt.textdrive.com/lua/ -- Creation Date: February 1, 2005 -- Legal: Copyright (C) 2005 Raphaël Szwarc -------------------------------------------------------------------------------- -- import dependencies local LWComponent = require( "LWComponent" ) local LWResponse = require( "LWResponse" ) local LUList = require( "LUList" ) local LULocale = require( "LULocale" ) local LUModule = require( "LUModule" ) -- define the class local super = LWComponent local self = super() -- method to describe the loaded modules function self:modulesDescription() return LUModule:moduleNames():join( ", " ) end function self:gcAction() collectgarbage() return self end -- method to return a plain text representation of this component function self:txtAction() local aBuffer = LUList() aBuffer:add( "server: " .. LWResponse:server() ) aBuffer:add( "version: " .. LWResponse:version() ) aBuffer:add( "encoding: " .. LWResponse:encoding() ) aBuffer:add( "locale: " .. LULocale:default() ) aBuffer:add( "vm: " .. _VERSION ) aBuffer:add( "memory: " .. math.floor( collectgarbage( "count" ) ) .. " KB" ) aBuffer:add( "modules: " .. self:modulesDescription() ) self:context():response():headers():put( "content-type", "text/plain; charset=" .. LWResponse:encoding() ) return aBuffer:join( "\r\n" ) end -- method for string representation function self:toString() local aTemplate = self:template() aTemplate:put( "name", LWResponse:server() ) aTemplate:put( "version", LWResponse:version() ) aTemplate:put( "encoding", LWResponse:encoding() ) aTemplate:put( "locale", LULocale:default() ) aTemplate:put( "vm", _VERSION ) aTemplate:put( "memory", math.floor( collectgarbage( "count" ) ) ) aTemplate:put( "modules", self:modulesDescription() ) return aTemplate:toString() end return self