User-defined main()

If your application requirements include running custom C code before Lisp starts up, you may build your own Lisp executable. Here is an example:

On UNIX:

struct shlib_library_item {
  char *    name;
  int        system;
};

#include <stdio.h>
#include "misc/shlibs.h"

void my_exit( int );

main( int argc, char **argv, char **envp )
{

  /* put custom installation code here */
  fprintf(stderr, "custom code runs..\n" );
  lisp_init(
  /* these three arguments are the main() arguments */
            argc, argv, envp,
  /* custom exit function; use 0 if default exit() call desired */
            my_exit,
  /* directory containing ACL shared library and Lisp image(s ) */
            "/room2/test/src",
  /* ACL shared library name; name could vary, so check your ACL
     directory for the correct name */
            "libacl50.so",
  /* default lisp image name; use 0 if no default desired */
            "lisp.dxl",
  /* quiet flag; if 1,  "Mapping..." message will be suppressed */
            0,
  /* Win32app flag; on UNIX, must be 0 */
            0,
  /* global variable containing prelinked library list;
     defined by shlibs.h include file */
            linked_shared_libraries ); 
}

void
my_exit( int n )
{
  fprintf( stderr, "my exit code can run here\n" );
  exit( n );
}

Remarks

  1. You most likely will not want to hardwire a pathname such as /room2/test/src. For example, you may require the user to set an environmental variable specifying the directory containing the required shared library and image; you can then call getenv() to find the needed value.
  2. The default image name is used when there is no command line -I image name specified.
  3. The linked_shared_libraries variable is needed for profiling, disassembly, and foreign function support. If you link your main program with additional shared libraries, add them to the shlibs.h file. For libraries that you add, set the "system" structure member to 0.
  4. The lisp_init() function is found in the ACL shared library. After you have successfully compiled and linked you custom executable, users will have to add the directory containing the ACL shared library to their environmental variable containing the directories to be searched when a dynamic shared library load occurs.

On Windows:

#include <windows.h>
#include <process.h>

unsigned _stdcall startlisp(void *x)
{
  StartLisp((char *) x, 1, 1);
}

int
WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
        int nCmdShow)
{
  HANDLE handle;
  int lisp_thread_id;

/* custom code can go here */
  MessageBox(NULL, "custom code could run now", "before Lisp starts",
             MB_OK);

  handle = (HANDLE) _beginthreadex(0, 0, startlisp, (void *) lpCmdLine, 0,
                                   &lisp_thread_id);

  WaitForSingleObject(handle, INFINITE);

/* custom code can go here; it runs after Lisp exits */
  MessageBox(NULL, "custom code could run now", "after Lisp exits",
             MB_OK);

  return 0;
}

Remarks

  1. The StartLisp() function is in the elm50.dll (the name of this file will vary, so check your ACL directory for the correct name of this .dll and the .lib below).  Assuming the above code is in a file named testm.c, an executable named testm.exe is produced by the command: cl testm.c /Zi /MD /link elm50.lib user32.lib
  2. There is no default Lisp image filename - either the user specifies one using the -I command line option, or a file dialog will pop up.