diff options
author | Hans Hagen <pragma@wxs.nl> | 2022-09-16 15:53:42 +0200 |
---|---|---|
committer | Context Git Mirror Bot <phg@phi-gamma.net> | 2022-09-16 15:53:42 +0200 |
commit | c161b7d6fe142231346cc1844e6e27c0ab7718c1 (patch) | |
tree | 3fd877b8986137703e987e4651a2db8e946a0f72 /source/luametatex/source/lua/lmtlibrary.h | |
parent | e94fa4dc30ec28a6727aa85e17aaac18b76aeadb (diff) | |
download | context-c161b7d6fe142231346cc1844e6e27c0ab7718c1.tar.gz |
2022-09-16 14:41:00
Diffstat (limited to 'source/luametatex/source/lua/lmtlibrary.h')
-rw-r--r-- | source/luametatex/source/lua/lmtlibrary.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/source/luametatex/source/lua/lmtlibrary.h b/source/luametatex/source/lua/lmtlibrary.h new file mode 100644 index 000000000..40f5f47f4 --- /dev/null +++ b/source/luametatex/source/lua/lmtlibrary.h @@ -0,0 +1,60 @@ +/* + See license.txt in the root of this project. +*/ + +# ifndef LMT_LLIBRARY_H +# define LMT_LLIBRARY_H + +/*tex + + The normal \LUA\ library loader uses the same calls as below. After loading the initializer is + looked up and called but here we use that method for locating more functions. + + -- anonymous cast: void(*)(void) + +*/ + +/* Do we need LoadLibraryW here or are we never utf/wide? */ + +/* void : dlclose(lib) | string: dlerror() */ + +typedef void (*lmt_library_function); + +# ifdef _WIN32 + + # include <windows.h> + + typedef struct lmt_library { + HMODULE lib; + int okay; + int padding; + } lmt_library; + + # define lmt_library_open_indeed(filename) LoadLibraryExA(filename, NULL, 0) + # define lmt_library_close_indeed(lib) FreeLibrary((HMODULE) lib) + # define lmt_library_find_indeed(lib,source) (void *) GetProcAddress((HMODULE) lib, source) + +# else + + # include <dlfcn.h> + + typedef struct lmt_library { + void *lib; + int okay; + int padding; + } lmt_library; + + # define lmt_library_open_indeed(filename) dlopen(filename, RTLD_NOW | RTLD_LOCAL) + # define lmt_library_close_indeed(lib) dlclose(lib) + # define lmt_library_find_indeed(lib,source) (void *) dlsym(lib, source) + +# endif + +extern void lmt_library_register (lua_State *L, const char *name, luaL_Reg functions[]); +extern void lmt_library_initialize (lua_State *L); + +extern lmt_library lmt_library_load (const char *filename); +extern lmt_library_function lmt_library_find (lmt_library lib, const char *source); +extern int lmt_library_okay (lmt_library lib); + +# endif |