Archived

This forum has been archived. Please start a new discussion on GitHub.

Python and Ice v3.5.0 Mappings

I searched the Ice 3.5 Docs as well as the Forum, but was unable to find a few things. I write mostly in Python, and noticed I could not do 2 things.

1) I have an interface as follows:

idempotent capstone::dataobjects::event::EventInfoSeq getEvents(capstone::enums::event::EventLevel el, optional(1) long start_seq, optional(2) long end_seq);
idempotent capstone::dataobjects::event::EventInfoSeq getEventsForTopic(string topic, optional(1) long start_seq, optional(2) long end_seq);

when this is slice2py, the methods still seem to require all the parameters:

def getEvents(self, el, start_seq, end_seq, current=None):
pass

def getEventsForTopic(self, topic, start_seq, end_seq, current=None):
pass

How can I make these really optional? Do I need to suplly something when I call the methods via the proxy? Like the Ice.None?

2) I was also trying to set a specific enum value as a default inside a class. That works fine, but say the enum is another namespace:

class Foo {
capstone::enums::SomeEnum value = capstone::enums::SomeEnum::Value1;
};

This fails and says ‘capstone::enums::SomeEnum::Value1’ is not defined

Any help is appreciated.

Thanks,
Tom

Comments

  • mes
    mes California
    Hi Tom,

    Welcome to the forum.

    You still need to pass a value for each parameter, regardless of whether it's declared as optional. For those parameters you wish to remain unset, pass the value Ice.Unset.

    Since Slice allows you to declare any combination of required and optional parameters, in any order, it could lead to confusing run-time errors if you were able to simply leave out the values of optional parameters.

    Regarding your enumerator question, keep in mind that enumerator symbols appear in the enclosing scope (like in C++), so you would need to write it like this:
    class Foo {
        capstone::enums::SomeEnum value = capstone::enums::Value1;
    };
    

    I'll add another example to the enumeration docs to make this clear.

    Regards,
    Mark
  • Very nice Explanations. I saw in the Doc that the Python section does not have the part about Optional Parameters (like the C++ does). So worth putting that there.

    The enum piece still errored though:


    module capstone {
    module enums {
    module event {

    enum EventType {etNone,etChanged,etSize};
    enum EventLevel {elNone,elCritical,elError,elWarning,elInfo,elDebug1,elDebug2,elSize};

    };
    };
    };

    class EventInfo {
    capstone::dataobjects::IDateTime m_timestamp;
    capstone::enums::event::EventType m_type = capstone::enums::event::etChanged;
    capstone::enums::event::EventLevel m_level = capstone::enums::event:elDebug2;
    };


    home/tpologruto/workspace/ctp1/trunk/IceFiles/EventDataObjects.ice:20: illegal initializer: `capstone::enums::event' is a module
    /home/tpologruto/workspace/ctp1/trunk/IceFiles/EventDataObjects.ice:20: `;' missing after definition
    /home/tpologruto/workspace/ctp1/trunk/IceFiles/EventDataObjects.ice:20: syntax error
    /home/tpologruto/workspace/ctp1/trunk/IceFiles/EventDataObjects.ice:20: illegal initializer: `capstone::enums::event' is a module
    /home/tpologruto/workspace/ctp1/trunk/IceFiles/EventDataObjects.ice:20: `;' missing after definition
    /home/tpologruto/workspace/ctp1/trunk/IceFiles/EventDataObjects.ice:20: syntax error


    As an aside, can you pass a default value to an optional parameter? I guess not, but would be very clever.

    Many thanks. Love Ice.
  • mes
    mes California
    tpologruto wrote: »
    I saw in the Doc that the Python section does not have the part about Optional Parameters (like the C++ does). So worth putting that there.
    We do discuss the Python mapping for optional parameters. Let us know if anything is unclear there.

    There is a missing colon in the definition of EventLevel, it should be:
    capstone::enums::event::EventLevel m_level = capstone::enums::event::elDebug2;
    
    As an aside, can you pass a default value to an optional parameter? I guess not, but would be very clever.
    No, Slice doesn't allow you to specify default values for parameters.

    Mark
  • Many Thanks. Sorry for my typo. Works perfect.

    Documentation looks great. I guess I was missing the special sub section under Python.