posted by Kaj-de-Vos on Fri 18th Feb 2011 16:03 UTC
IconSyllable now has its first separate REBOL binding (screenshot on Syllable Desktop). The project created a binding with the popular cURL library, which is included in Syllable as its networking library. Documentation and downloads for Syllable, Linux and Windows are available here. The binding will be demonstrated at the upcoming REBOL & Boron conference.

The current version of REBOL 3 for Syllable interfaces with the system at the POSIX level. Beyond that, you can write your own bindings with system and user libraries. Bindings are written as REBOL 3 extensions. Amazingly, and just like the core REBOL 3 interpreter library, Syllable Desktop can run the Linux binary of the cURL binding unchanged, so that the same binary can be shared between Syllable Desktop and Syllable Server. This is possible because the interfaces between REBOL 3 and its extensions are designed for maximal portability, to avoid dependency hell.

The binding consists of a dynamic (shared) library; one single, binary file. On Syllable, either Desktop or Server, installation consists of just dropping it into place, exactly like native Syllable drivers and plug-ins. On other systems, installation may be more complicated.

REBOL has network protocols built in, but the new REBOL version 3 doesn't have many of the protocols of REBOL 2 yet. The cURL binding fills this gap, and also provides missing features such as SSL and proxy support, and even some protocols that REBOL 2 never had. The exact protocol support depends on the cURL version that you use. Here's a basic programming example that reads a page from an SSL encrypted website:

import %cURL-binding.so
session: curl/new-session
curl/read session data: copy #{}
curl/verify-peer session off
curl/do session https://github.com/carls/R3A110
curl/end-session session
result: to-string data

cURL is very powerful and flexible, and the REBOL binding gives you an easy way to access its capabilities. For example, if you need to do special web programming to make a website think that your program is a human user, custom headers can be set that will be sent to the server along with a request:

session: curl/new-session
curl/headers session [
    "Referer: ..."
    "User-Agent: ..."
    "Cookie: name1=content1; name2=content2;"
]

Advanced communication with REBOL is possible in both directions. A callback that provides progress status can be added that is written in REBOL, but is called periodically by cURL. Here's an example, including error checking:

progress: func [
    download-goal [decimal!] download-now [decimal!]
    upload-goal [decimal!] upload-now [decimal!]
][
    print [
        "Read" to-integer download-now
        "of" to-integer download-goal "bytes"

    ]
    0  ; Return non-zero to abort transfer
]
session: curl/new-session
unless all [
    curl/progress session self 'progress
    curl/read session data: copy #{}
    curl/do session http://rebol.com
][
    do make error! second curl/session-error session
]
curl/end-session session
result: to-string data

e p (1)    9 Comment(s)

Technology White Papers

See More