next up previous contents
Next: Compiler Phases Up: The Foreign Function Interface Previous: Introducing New HTML Tags   Contents

The Less Safe FFI

An alternative interface is provided for declaring FFI functions inline within normal Ur/Web modules. This facility must be opted into with the lessSafeFfi .urp directive, since it breaks a crucial property, allowing code in a .ur file to break basic invariants of the Ur/Web type system. Without this option, one only needs to audit .urp files to be sure an application obeys the type-system rules. The alternative interface may be more convenient for such purposes as declaring an FFI function typed in terms of some type local to a module.

When the less safe mode is enabled, declarations like this one are accepted, at the top level of a .ur file:

  ffi foo : int -> int

Now foo is available as a normal function. If called in server-side code, and if the above declaration appeared in bar.ur, the C function will be linked as uw_Bar_foo(). It is also possible to declare an FFI function to be implemented in JavaScript, using a general facility for including modifiers in an FFI declaration. The modifiers appear before the colon, separated by spaces. Here are the available ones, which have the same semantics as corresponding .urp directives.


next up previous contents
Next: Compiler Phases Up: The Foreign Function Interface Previous: Introducing New HTML Tags   Contents
2014-07-14