Calling Dylan from C

Home
Introduction
Tips and Techniques
Projects
Libraries
Links

The Functional Developer C-FFI library allows you to call methods and functions written in Dylan from other languages. This is a simple example of how I called a Dylan function from C.

I wanted to call the Dylan function run-application to execute another console program. For various reasons I was unable to use the C run time library call to do this. I wrapped run-application to have the method signature that I wanted:

  define method dylan-system(command) => ()
    run-application(command, 
                    inherit-console?: #f, 
                    under-shell?: #t, 
                    activate?: #t);
  end method dylan-system;

To make this callable from a C program requires the c-callable-wrapper macro:

  define c-callable-wrapper of dylan-system
    parameter command :: <c-string>;
    export: #t;
    c-modifiers: "__stdcall";
    c-name: "dylan_system";
  end;

This macro will generate a C function called dylan_system that takes a char* as an argument. The function will have the Windows __stdcall calling convention and it will be exported from the DLL.

Calling this from C just requires linking to the DLL generated by Functional Developer (via the import library created) and calling dylan_system:

  void dylan_system(char* app);

  void doit()
  {
    dylan_system("notepad.exe");
  }

Copyright © 2000, Chris ^M Double. All Rights Reserved.
^M All products and brand names are the registered trademarks or trademarks ^M of their respective owners.

^M