RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Ralf S. Engelschall
  Root:   /v/rpm/cvs                       Email:  [EMAIL PROTECTED]
  Module: rpm                              Date:   23-Dec-2007 23:50:05
  Branch: HEAD                             Handle: 2007122322500500

  Added files:
    rpm/scripts             lua-dump.lua
  Modified files:
    rpm                     CHANGES
    rpm/scripts             Makefile.am

  Log:
    Add scripts/lua-dump.lua, a recursive Lua data structure dumper which I
    recently coded for use in the Monotone VCS. But here for RPM it is also
    useful in when developing RPM Lua scripts.
    
    Example to get an impression:
    $ rpm --eval '%{lua: rpm.load("lua-dump.lua"); 
lua_dump_stderr(rpm.macros()); }'
    
    PS: Without this I would have not found out why the keys in the table of
        rpm.macros() were totally broken.

  Summary:
    Revision    Changes     Path
    1.2011      +1  -0      rpm/CHANGES
    1.46        +1  -1      rpm/scripts/Makefile.am
    1.1         +88 -0      rpm/scripts/lua-dump.lua
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/CHANGES
  ============================================================================
  $ cvs diff -u -r1.2010 -r1.2011 CHANGES
  --- rpm/CHANGES       23 Dec 2007 22:46:00 -0000      1.2010
  +++ rpm/CHANGES       23 Dec 2007 22:50:05 -0000      1.2011
  @@ -1,4 +1,5 @@
   5.0b3 -> 5.0b4:
  +    - rse: add scripts/lua-dump.lua, a recursive dumper for Lua data 
structures
       - rse: fix parsing of the table key in RPM Lua function rpm.macros()
       - rse: add an RPM Lua function rpm.load() for loading external Lua 
scripts
       - rse: output "Fetching(SourceX): <url>" to clearly indicate that 
something is fetched remotely
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/scripts/Makefile.am
  ============================================================================
  $ cvs diff -u -r1.45 -r1.46 Makefile.am
  --- rpm/scripts/Makefile.am   8 Dec 2007 06:31:08 -0000       1.45
  +++ rpm/scripts/Makefile.am   23 Dec 2007 22:50:05 -0000      1.46
  @@ -22,7 +22,7 @@
        rpm.daily rpm.log rpm.xinetd \
        rpmsort symset-table \
        sql.prov sql.req symclash.py symclash.sh tcl.req tgpg trpm u_pkg.sh \
  -     vcheck vpkg-provides.sh vpkg-provides2.sh \
  +     vcheck lua-dump.lua vpkg-provides.sh vpkg-provides2.sh \
        macros.perl* macros.python* \
        macros.php* find-*.php find-php-*
   
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/scripts/lua-dump.lua
  ============================================================================
  $ cvs diff -u -r0 -r1.1 lua-dump.lua
  --- /dev/null 2007-12-23 23:44:00 +0100
  +++ lua-dump.lua      2007-12-23 23:50:05 +0100
  @@ -0,0 +1,88 @@
  +--
  +--  lua-dump.lua -- Simple Lua Object Dumper (language: Lua)
  +--  Copyright (c) 2007 Ralf S. Engelschall <[EMAIL PROTECTED]>
  +--
  +--  You can redistribute and/or modify this file under the terms of
  +--  the GNU General Public License as published by the Free Software
  +--  Foundation; either version 2 of the License, or (at your option) any
  +--  later version.
  +--
  +--  This file is distributed in the hope that it will be useful,
  +--  but WITHOUT ANY WARRANTY; without even the implied warranty of
  +--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  +--  General Public License for more details.
  +--
  +--  You should have received a copy of the GNU General Public License
  +--  along with this program; if not, write to the Free Software
  +--  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  +--  USA, or contact Ralf S. Engelschall <[EMAIL PROTECTED]>.
  +--
  +
  +--  WORK HORSE:
  +--  dump a single object recursively into a string
  +function lua_dump_object(obj)
  +    local dump = "<unknown>"
  +    if type(obj) == "nil" then
  +        dump = "nil"
  +    elseif type(obj) == "number" then
  +        dump = string.format("%d", obj)
  +    elseif type(obj) == "string" then
  +        local str = obj
  +        str = string.gsub(str, "\\\\", "\\\\")
  +        str = string.gsub(str, "\"", "\\\"")
  +        str = string.gsub(str, "\r", "\\r")
  +        str = string.gsub(str, "\n", "\\n")
  +        str = string.gsub(str, ".",
  +            function(c)
  +                local n = string.byte(c)
  +                if n < 32 or n >= 127 then
  +                    c = string.format("\\%03d", n)
  +                end
  +                return c
  +            end
  +        )
  +        dump = "\"" .. str .. "\""
  +    elseif type(obj) == "boolean" then
  +        if obj then
  +            dump = "true"
  +        else
  +            dump = "false"
  +        end
  +    elseif type(obj) == "table" then
  +        dump = "{"
  +        local first = true
  +        for k, v in pairs(obj) do
  +            if not first then
  +                dump = dump .. ","
  +            end
  +            dump = dump .. " " .. lua_dump_object(k) .. " = "
  +            dump = dump .. lua_dump_object(v)
  +            first = false
  +        end
  +        dump = dump .. " }"
  +    elseif type(obj) == "function" then
  +        dump = "<function>"
  +    elseif type(obj) == "thread" then
  +        dump = "<thread>"
  +    elseif type(obj) == "userdata" then
  +        dump = "<userdata>"
  +    end
  +    return dump
  +end
  +
  +--  CONVENIENCE FRONTEND:
  +--  dump one or more objects recursively, one per line
  +function lua_dump(obj1, ...)
  +    local dump = lua_dump_object(obj1) .. "\n"
  +    for _, obj in ipairs(arg) do
  +        dump = dump .. lua_dump_object(obj) .. "\n"
  +    end
  +    return dump
  +end
  +
  +--  CONVENIENCE FRONTEND:
  +--  dump one or more objects recursively, one per line, to stderr
  +function lua_dump_stderr(obj1, ...)
  +    io.stderr:write(lua_dump(obj1, unpack(arg)))
  +end
  +
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                [email protected]

Reply via email to