RPM Community Forums

Mailing List Message of <rpm-cvs>

[CVS] RPM: lua/local/ llocal.lua

From: Ralf S. Engelschall <rse@rpm5.org>
Date: Mon 24 Dec 2007 - 23:22:58 CET
Message-Id: <20071224222258.B6FF834844D@rpm5.org>
  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Ralf S. Engelschall
  Root:   /v/rpm/cvs                       Email:  rse@rpm5.org
  Module: lua                              Date:   24-Dec-2007 23:22:58
  Branch: HEAD                             Handle: 2007122422225800

  Modified files:
    lua/local               llocal.lua

  Log:
    allow one to optionally dump objects in compact format (no
    whitespaces) and fix table key formatting

  Summary:
    Revision    Changes     Path
    1.4         +11 -4      lua/local/llocal.lua
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: lua/local/llocal.lua
  ============================================================================
  $ cvs diff -u -r1.3 -r1.4 llocal.lua
  --- lua/local/llocal.lua	24 Dec 2007 15:12:57 -0000	1.3
  +++ lua/local/llocal.lua	24 Dec 2007 22:22:58 -0000	1.4
  @@ -88,7 +88,7 @@
   
   --  WORK HORSE:
   --  dump a single object recursively into a string
  -function util.dump_object(obj)
  +function util.dump_object(obj, compact)
       local dump = "<unknown>"
       if type(obj) == "nil" then
           dump = "nil"
  @@ -117,17 +117,24 @@
               dump = "false"
           end
       elseif type(obj) == "table" then
  +        local space = " "
  +        if compact ~= nil and compact == true then
  +            space = ""
  +        end
           dump = "{"
           local first = true
           for k, v in pairs(obj) do
               if not first then
                   dump = dump .. ","
               end
  -            dump = dump .. " " .. util.dump_object(k) .. " = "
  -            dump = dump .. util.dump_object(v)
  +            if string.match(k, "^[a-zA-Z_][a-zA-Z0-9_]*$") == nil then
  +                k = "[" .. util.dump_object(k, true) .. "]"
  +            end
  +            dump = dump .. space .. k .. space .. "=" .. space
  +            dump = dump .. util.dump_object(v, compact)
               first = false
           end
  -        dump = dump .. " }"
  +        dump = dump .. space .. "}"
       elseif type(obj) == "function" then
           dump = "<function>"
       elseif type(obj) == "thread" then
  @@ .
Received on Mon Dec 24 23:22:58 2007
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.