[Ur] interfacing with C or other languages - how to pass more complex types?

Adam Chlipala adamc at impredicative.com
Sat Nov 27 12:43:20 EST 2010


Marc Weber wrote:
> Passing primitive datatypes (strings, ints, blobs, ...) from C to urweb
> is known. Is there a way to pass more complex (foreign types) such as
> XML documents you can run XPATH queries on etc?
>    

XML isn't a particularly good example, since Ur/Web values of [xml] 
types are represented as strings at runtime, which makes them trivial to 
pass back and forth with C or JavaScript.  You could easily do the same 
for some other presentation of XML.

For structured types that should be FFI-compatible, I recommend 
declaring an abstract type with a set of constructor and modification 
functions, implemented in the foreign language.

> Would it be crazy to add json encoding and decoding so that you can
> interface with PHP, Pytohn or Ruby easily and reuse existing code (eg
> OpenID)?
> Of course it somehow defeats the purpose of Ur. But having to code up
> everything using C doesn't feel right to me either.
>    

JSON encoding (treated much like [serialize] is now) doesn't sound crazy 
to me.  Interfacing with popular dynamic scripting languages isn't 
necessarily crazy, but it also isn't something that I see _myself_ 
spending time on.  If there's an existing C library providing the 
functionality you want, then it should be nearly trivial to wrap it for 
Ur/Web use.  Perhaps you are worried about cases without C libraries or 
that only have C libraries that you don't like for some reason.



More information about the Ur mailing list