1 /* Lisp interface to dynamic loading.
2 Copyright (C) 1998 Joshua Rowe.
3 Additional cleanup by Hrvoje Niksic.
5 This file is part of XEmacs.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* Synched up with: Not in FSF. */
24 /* A shared object must have the symbol `emacs_initialize' defined.
25 It should contain initialization of functions, symbols, etc. and
26 their loading into Lisp-land. The function will be called without
27 arguments and is not expected to return any.
29 All of this needs lots and LOTS of work. Some things to work on:
31 1) A good foreign interface. This is probably tough, because it
32 implies drawing a new border between "external" and "internal"
33 stuff (traditionally, Lisp code was external, while C was
34 internal). Also, we need a modules/ directory with a few nice
35 sample modules, a sample Makefile, etc. so people can start
38 2) All of this is sooo simple-minded. As it gets more complex,
39 we'll have to look at how others have done similar things
40 (e.g. Perl 5 and Zsh 3.1), to avoid botching it up. */
47 DEFUN ("dll-open", Fdll_open, 1, 1, "FShared object: ", /*
48 Load LIBRARY as a shared object file.
50 After the LIBRARY is dynamically linked with the executable, the
51 `emacs_initialize' function will be called without arguments. It
52 should define all the symbols, subr's and variables the module
55 After this point, any lisp symbols defined in the shared object are
60 /* This function can GC */
62 void (*function) (void);
65 CHECK_STRING (library);
66 library = Fexpand_file_name (library, Qnil);
68 GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA (XSTRING_DATA (library), filename);
70 handle = (dll_handle *) dll_open (filename);
74 list3 (build_translated_string ("Cannot load shared library"),
75 library, build_translated_string (dll_error (handle))));
78 /* #### Perhaps emacs_initialize() should return a Lisp_Object, so
81 function = (void (*)(void)) dll_function (handle, "emacs_initialize");
83 signal_simple_error ("Shared library does not define `emacs_initialize'",