Thread: [SailfishOS] [Announce] Poor Maps
View Single Post
otsaloma's Avatar
Posts: 141 | Thanked: 1,530 times | Joined on May 2011 @ Finland
#53
Thanks, but that 1.4.4 version didn't seem to work either. Probably something else in the Iijoki update has triggered the bug.

But anyway, on second thought, it seems fairly easy to work around this after all, in the common case of scalar arguments and assuming no weird values. For anyone else interested, something like the below seems to work.

Code:
Python {
    id: py
    ...
    function call_sync(func, args) {
        // XXX: Work around a call_sync bug by using evaluate.
        // https://github.com/thp/pyotherside/issues/49
        args = args.map(py.stringify).join(", ");
        return py.evaluate("%1(%2)".arg(func).arg(args));
    }
    function stringify(obj) {
        // Return Python string representation of obj.
        if (Array.isArray(obj)) {
            return "[%1]".arg(obj.map(py.stringify).join(", "));
        } else if (obj === null || obj === undefined) {
            return "None";
        } else if (typeof obj === "string") {
            return "'%1'".arg(obj.replace(/'/, "\\'"));
        } else if (typeof obj === "number") {
            return obj.toString();
        } else if (typeof obj === "boolean") {
            return obj ? "True" : "False";
        } else if (typeof obj === "object") {
            // Assume all remaining objects are dictionaries.
            return "{%1}".arg(Object.keys(obj).map(function(x) {
                return [py.stringify(x), py.stringify(obj[x])].join(": ");
            }).join(", "));
        } else {
            throw "Unrecognized argument type: %1: %2"
                .arg(obj).arg(typeof obj);
        }
    }
}

Last edited by otsaloma; 2017-02-15 at 22:12. Reason: Updated work-around code in case someone wants to use it.
 

The Following 6 Users Say Thank You to otsaloma For This Useful Post: