Savarese Software Research Corporation
Lua/Perl/Python/Ruby API Differences

The Lua, Perl, Python, and Ruby bindings use the same naming scheme as the C++ API in almost every case.

No attempt has been made to customize the API to the idioms of the respective scripting languages. This allows you to use the C++ API documentation for all environments. However, a few differences are forced upon the API by the languages. See the unit tests in tests/swig/lua, tests/swig/perl, tests/swig/python, and tests/swig/ruby for usage examples.

Lua Differences

Perl Differences

Python Differences

Ruby Differences

Shared Differences

Additional Considerations

The Mailbox class uses the C++ idiom of resource acquisition is initialization. Therefore, no disconnect method is exposed and the disconnect happens in the destructor. In a garbage-collected scripting language, this means the disconnect may not happen at a predictable point when you stop using the object. You can invoke Mailbox::kill to free the file descriptor immediately, but don't continue to use the object afterward.

In order to specify a connection timeout, you may use the Timeout class or you may specify a timeout in seconds with a single integer. For example, to specify a connection timeout of 3 seconds in Python, you could use:

mbox = ssrc.spread.Mailbox("4803@localhost", "", True, ssrc.spread.Timeout(3));

or:

mbox = ssrc.spread.Mailbox("4803@localhost", "", True, 3);

You can't access the contents of a Message directly via &Message[0] as in C++. Instead, you always have to read and write the contents using Message::read and Message::write. Because messages are treated as strings in the script environment, your data shouldn't contain null/0 characters. For example, if you write two strings to a message in a row and read them back into one string, you'll find that the result is treated as only the first string because of the null termination. For example:

m = ssrc.spread.Message()
m.write("foo")
m.write("bar")
m.rewind()
s = m.read(m.size())
"foo" == s # This expression evaluates to True.
"foobar" == s # This expression evaluates to False.
m.rewind()
s1 = m.read(4)
s2 = m.read(4)
"foo" == s1 # This expression evaluates to True.
"bar" == s2 # This expression evaluates to True.

As long as you use the script environment's object serialization mechanisms, you shouldn't run into any problems in this regard.

Don't add raw data parts (things that are not of type Message) to ScatterMessage::add or Mailbox::add_message_part if they will be garbage-collected before a send. For example:

s = "foo"
mbox.add_message_part(s)
s = None # Don't do this before the send or you may segfault!
mbox.send()

Savarese Software Research Corporation
Copyright © 2006-2015 Savarese Software Research Corporation. All rights reserved.