Hello Kepler developers.
I have fixed a couple of issues I have had with Lua XML-RPC while using
it for roslua (http://github.com/timn/roslua), that uses and provides an
XML-RPC API to communicate with a broker node.
The modifications are:
- consider "1" as true for booleans, some implementations send that
- if for a string a table entry is nil return the empty string. It
simply would skip these fields, causing arrays not to have the
intended indexes
- for unknown value types, e.g. arrays without type tags, return the
empty string for unset values instead of nil, again array indexes get
messed up otherwise
- Fixed array parsing for arrays with undefined or different value
types for entries.
Please find the patch attached. It's based on the package that ships
with Ubuntu 10.04. I would be thankful for doing an updated release so
that downstream distros can pickup the changes.
Tim
--
AllemaniACs RoboCup Team KBSG - Knowledge-Based Systems Group
========================================================================
http://robocup.rwth-aachen.de RWTH Aachen University
http://www.kbsg.rwth-aachen.de Ahornstrasse 55
http://www.fawkesrobotics.org D-52056 Aachen
Currently at:
Carnegie Mellon University, Intel Research Pittsburgh, Personal Robotics
diff -urN luaxmlrpc-1.0b/xmlrpc.lua luaxmlrpc-1.0b.timn/xmlrpc.lua
--- luaxmlrpc-1.0b/xmlrpc.lua 2004-12-02 13:32:08.000000000 -0500
+++ luaxmlrpc-1.0b.timn/xmlrpc.lua 2010-07-30 12:47:35.000000000 -0400
@@ -13,7 +13,8 @@
local ceil = math.ceil
local parse = lxp.lom.parse
-module (arg and arg[1])
+--module (arg and arg[1])
+module("xmlrpc")
_COPYRIGHT = "Copyright (C) 2003-2004 Kepler Project"
_DESCRIPTION = "LuaXMLRPC is a library to make remote procedure calls using
XML-RPC"
@@ -77,13 +78,13 @@
local function x2boolean (tab)
if tab.tag == "boolean" then
local v = next_nonspace (tab, 1)
- return v == true or v == "true" or false
+ return v == true or v == "true" or v == "1" or false
end
end
---------------------------------------------------------------------
local function x2string (tab)
- return tab.tag == "string" and tab[1]
+ return tab.tag == "string" and (tab[1] or "")
end
---------------------------------------------------------------------
@@ -204,6 +205,9 @@
local get = xmlrpc_types[t]
if not get then error ("Invalid <"..t.."> element") end
return get (next_nonspace (tab))
+ elseif type(n) == "nil" then
+ -- the next best thing is to assume it's an empty string
+ return ""
end
end
@@ -367,7 +371,13 @@
local et = typ.elemtype
local f = format_func (et)
for i,v in ipairs (val) do
- tinsert (ret, format (formats.value, f (v, et)))
+ if et and et ~= "array" then
+ tinsert (ret, format (formats.value, f (v, et)))
+ else
+ local ct,cv = type_val(v)
+ local cf = format_func(ct)
+ tinsert (ret, format (formats.value, cf(cv, ct)))
+ end
end
return format (formats.array, concat (ret, '\n'))
end
@@ -400,7 +410,7 @@
---------------------------------------------------------------------
-- Get type and value of object.
---------------------------------------------------------------------
-local function type_val (obj)
+function type_val (obj)
local t = type (obj)
local v = obj
if t == "table" then
_______________________________________________
Kepler-Project mailing list
Kepler-Project@lists.luaforge.net
http://lists.luaforge.net/cgi-bin/mailman/listinfo/kepler-project
http://www.keplerproject.org/