lmtlibrary.h /size: 1890 b    last modification: 2024-01-16 10:22
1/*
2    See license.txt in the root of this project.
3*/
4
5# ifndef LMT_LLIBRARY_H
6# define LMT_LLIBRARY_H
7
8/*tex
9
10    The normal \LUA\ library loader uses the same calls as below. After loading the initializer is
11    looked up and called but here we use that method for locating more functions.
12
13    -- anonymous cast: void(*)(void)
14
15*/
16
17/* Do we need LoadLibraryW here or are we never utf/wide? */
18
19/* void : dlclose(lib) | string: dlerror() */
20
21typedef void *lmt_library_function;
22
23# ifdef _WIN32
24
25    # include <windows.h>
26
27    typedef struct lmt_library {
28        HMODULE lib;
29        int     okay;
30        int     padding;
31    } lmt_library;
32
33    // 126 : ERROR_MOD_NOT_FOUND
34    // 193 : ERROR_BAD_EXE_FORMAT
35
36    # define lmt_library_open_indeed(filename)   LoadLibraryExA(filename, NULL, 0)
37    # define lmt_library_close_indeed(lib)       FreeLibrary((HMODULE) lib)
38    # define lmt_library_find_indeed(lib,source) (void *) GetProcAddress((HMODULE) lib, source)
39    # define lmt_library_last_error()            GetLastError()
40
41# else
42
43    # include <dlfcn.h>
44
45    typedef struct lmt_library {
46        void *lib;
47        int   okay;
48        int   padding;
49    } lmt_library;
50
51    # define lmt_library_open_indeed(filename)   dlopen(filename, RTLD_NOW | RTLD_LOCAL)
52    # define lmt_library_close_indeed(lib)       dlclose(lib)
53    # define lmt_library_find_indeed(lib,source) (void *) dlsym(lib, source)
54    # define lmt_library_last_error()            0
55
56# endif
57
58extern void                 lmt_library_register   (lua_State *L, const char *name, luaL_Reg functions[]);
59extern void                 lmt_library_initialize (lua_State *L);
60
61extern lmt_library          lmt_library_load       (const char *filename);
62extern lmt_library_function lmt_library_find       (lmt_library lib, const char *source);
63extern int                  lmt_library_okay       (lmt_library lib);
64
65# endif
66