[Ur] Calling an Ur/Web function from Javascript

Adam Chlipala adamc at csail.mit.edu
Sun Apr 7 20:15:14 EDT 2013


On 04/07/2013 06:57 PM, Istvan Chung wrote:
> I'm trying to use the FFI to call an Ur/Web function from javascript,
> but there's very little in the manual about this; how can I do this? At
> present, anything I've tried has failed at compile time with the error:
> "Unsupported FFI function Module.functionName in JavaScript"
>    

There is no facility for referring to Ur/Web-defined identifiers from 
JavaScript code, whether or not those identifiers are bound to 
functions.  However, you can pass Ur/Web functions to JavaScript 
functions as first-class values, at which point you can call them in the 
usual execF() way documented in the manual's FFI section.

The error message above is a little surprising to me, though.  How does 
[Module.functionName] come into this?  Also, since that's an urweb error 
message, what does it have to do with JavaScript code?

> Also, although there's an explanation of how Ur/Web objects are
> marshalled to javascript types, what of the reverse: how are javascript
> objects marshalled to Ur/Web types?
>    

I wouldn't say any marshaling of that kind goes on.  Instead, any values 
flowing into or out of Ur/Web code, such that this code will actually 
need to know their structure, should be encoded in the way set out in 
the JavaScript FFI manual section.  That is, the values should be in the 
proper encoding in the first place, and there is no translation step.



More information about the Ur mailing list