webmcp
view libraries/nihil/nihil.lua @ 2:72860d232f32
Version 1.0.2
Fixed bug with explicit garbage collection (requests > 256kB caused an error)
Views prefixed with an underscore can't be called externally
ui.paginate now displays the last page, if the selected page number is too high.
Fixed bug with explicit garbage collection (requests > 256kB caused an error)
Views prefixed with an underscore can't be called externally
ui.paginate now displays the last page, if the selected page number is too high.
| author | jbe/bsw | 
|---|---|
| date | Thu Dec 10 12:00:00 2009 +0100 (2009-12-10) | 
| parents | 9fdfb27f8e67 | 
| children | 3d43a5cf17c1 | 
 line source
     1 #!/usr/bin/env lua
     3 local error          = error
     4 local getmetatable   = getmetatable
     5 local module         = module
     6 local rawset         = rawset
     7 local setmetatable   = setmetatable
     9 module(...)
    11 metatable = {
    12   __tostring = function(self)
    13     return "nil" .. self[1]
    14   end,
    15   __newindex = function()
    16     error("Objects representing nil are immutable.")
    17   end
    18 }
    20 nils = setmetatable({}, {
    21   __mode = "v",
    22   __index = function(self, level)
    23     if level > 0 then
    24       local result = setmetatable({ level }, metatable)
    25       rawset(self, level, result)
    26       return result
    27     end
    28   end,
    29   __newindex = function()
    30     error("Table is immutable.")
    31   end
    32 })
    34 function lift(value)
    35   if value == nil then
    36     return nils[1]
    37   elseif getmetatable(value) == metatable then
    38     return nils[value[1]+1]
    39   else
    40     return value
    41   end
    42 end
    44 function lower(value)
    45   if value == nil then
    46     error("Cannot lower nil.")
    47   elseif getmetatable(value) == metatable then
    48     return nils[value[1]-1]
    49   else
    50     return value
    51   end
    52 end
