#include typedef void(*init_ptr_t)(Lua *); #ifdef _WIN32 #include void LuaLoadPlugin(const String & _fname, Lua * L) throw (GeneralException) { HMODULE handle; String fname = _fname + ".dll"; printm(M_INFO, "Loading library " + fname + "\n"); if (!(handle = LoadLibraryEx(fname.to_charp(), NULL, LOAD_WITH_ALTERED_SEARCH_PATH)) && !(handle = LoadLibraryEx(fname.to_charp(), NULL, NULL))) { throw GeneralException("File not found or error loading shared object file: " + fname + "; Error #" + String((int) GetLastError())); } init_ptr_t init_ptr = (init_ptr_t) GetProcAddress(handle, "init_plugin"); if (!init_ptr) { throw GeneralException("No init pointer on plugin " + fname); } printm(M_INFO, "Library loaded, init ptr = %p\n", init_ptr); init_ptr(L); } #else #include void LuaLoadPlugin(const String & fname, Lua * L) throw (GeneralException) { void * handle = dlopen(("./" + fname + ".so").to_charp(), RTLD_NOW | RTLD_GLOBAL); printm(M_INFO, "Loading library " + fname + "\n"); if (!handle) { throw GeneralException("File not found or error loading shared object file: " + fname + "; " + dlerror()); } init_ptr_t init_ptr = (init_ptr_t) dlsym(handle, "init_plugin"); if (!init_ptr) { throw GeneralException("No init pointer on plugin " + fname); } printm(M_INFO, "Library loaded, init ptr = %p\n", init_ptr); init_ptr(L); } #endif