Define the foreign functions in the top level of the module

This means:

* The foreign functions only get set up once.
* Any problems with the foreign functions are thrown up when the module
  is opened, rather than when the native functions are called.

Signed-off-by: John Else <john.else@citrix.com>