增强扩展模块
This commit is contained in:
@@ -12,7 +12,7 @@ endif()
|
||||
# C++等级
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
|
||||
set(FASTWEBCORE ${PROJECT_NAME}core)
|
||||
set(FASTWEBCORE ${PROJECT_NAME}core)
|
||||
# 安装复制
|
||||
set(CMAKE_INSTALL_ALWAYS_COPY TRUE)
|
||||
# 设置根目录
|
||||
|
||||
@@ -35,13 +35,8 @@ If you have any questions, please contact us: 1585346868@qq.com Or visit our web
|
||||
#include "module/http/subscribe.h"
|
||||
#include "module/globalfuns.h"
|
||||
#include "module/mutex.h"
|
||||
#include "module/codec.h"
|
||||
#include "module/time.h"
|
||||
#include "module/filesystem.h"
|
||||
#include "module/sys.h"
|
||||
#include "module/timer.h"
|
||||
#include "module/process.h"
|
||||
#include "module/ini.h"
|
||||
fastweb::module_manager::module_manager(fastweb::app* app):Interface(app)
|
||||
{
|
||||
}
|
||||
@@ -88,7 +83,15 @@ void fastweb::module_manager::start()
|
||||
}
|
||||
mi.func = (fastweb_module_regist)GetProcAddress((HMODULE)mi.dll, "fastweb_module_regist");
|
||||
if (mi.func == nullptr) {
|
||||
LOG_ERROR("function not found: `fastweb_module_regist`, filename: " + mod_filepath);
|
||||
|
||||
#if 0
|
||||
std::string filename = ylib::file::filename(mod_filepath,false);
|
||||
std::string funcname = "luaopen_" + filename;
|
||||
if (GetProcAddress((HMODULE)mi.dll, funcname.c_str()) == nullptr)
|
||||
{
|
||||
LOG_ERROR("function not found: `fastweb_module_regist` and `"+ funcname + "`, filename: " + mod_filepath);
|
||||
}
|
||||
#endif
|
||||
FreeLibrary((HMODULE)mi.dll);
|
||||
continue;
|
||||
}
|
||||
@@ -103,6 +106,42 @@ void fastweb::module_manager::start()
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// 查找所有引用
|
||||
{
|
||||
#ifdef _WIN32
|
||||
#define DLL_EXT "dll"
|
||||
#else
|
||||
#define DLL_EXT "so"
|
||||
#endif
|
||||
// 用户
|
||||
{
|
||||
|
||||
m_lua_include_path += ";" + app()->config->website.dir + "/?.lua";
|
||||
m_lua_include_path += ";" + app()->config->scripts.module_dir + "/?.lua";
|
||||
|
||||
m_lua_include_cpath += ";" + app()->config->website.dir + "/?." + DLL_EXT;
|
||||
m_lua_include_cpath += ";" + app()->config->scripts.module_dir + "/?." + DLL_EXT;
|
||||
}
|
||||
// FastWeb管理器
|
||||
{
|
||||
std::string search_path = app()->config->scripts.module_dir + "/.install";
|
||||
|
||||
std::map<std::string, bool> dirs;
|
||||
ylib::file::list(search_path, dirs);
|
||||
for_iter(iter, dirs)
|
||||
{
|
||||
if (iter->second == false)
|
||||
continue;
|
||||
if (iter->first == "." || iter->first == "..")
|
||||
continue;
|
||||
m_lua_include_path += ";" + search_path + "/" + iter->first + "/?.lua";
|
||||
m_lua_include_cpath += ";" + search_path + "/" + iter->first + "/?." + DLL_EXT;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void fastweb::module_manager::close()
|
||||
@@ -151,12 +190,7 @@ void fastweb::module_manager::load_core(sol::state* lua)
|
||||
module::globalfuncs::regist(lua);
|
||||
module::mutex::regist(lua);
|
||||
module::auto_lock::regist(lua);
|
||||
module::codec::regist(lua);
|
||||
module::time::regist(lua);
|
||||
module::filesystem::regist(lua);
|
||||
module::sys::regist(lua);
|
||||
module::timer::regist(lua);
|
||||
module::ini::regist(lua);
|
||||
module::process::regist(lua);
|
||||
|
||||
app()->global->regist(lua);
|
||||
@@ -176,12 +210,11 @@ void fastweb::module_manager::load_3rdparty(sol::state* lua)
|
||||
|
||||
void fastweb::module_manager::load_lualib(sol::state* lua)
|
||||
{
|
||||
// 获取当前的package.path,添加新的搜索路径
|
||||
std::string current_path = (*lua)["package"]["path"]; // 获取当前的路径
|
||||
//for (size_t i = 0; i < app()->config->scripts.lib_dir.size(); i++)
|
||||
// current_path += ";" + app()->config->scripts.lib_dir[i] + "/?.lua"; // 添加新的路径
|
||||
current_path += ";" + app()->config->website.dir + "/?.lua"; // 添加新的路径
|
||||
(*lua)["package"]["path"] = current_path; // 设置修改后的路径
|
||||
std::string path = (*lua)["package"]["path"];
|
||||
std::string cpath = (*lua)["package"]["cpath"];
|
||||
|
||||
(*lua)["package"]["path"] = path + m_lua_include_path;
|
||||
(*lua)["package"]["cpath"] = cpath + m_lua_include_cpath;
|
||||
}
|
||||
|
||||
std::vector<std::string> fastweb::module_manager::modules()
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "core/structs.h"
|
||||
#include "core/define.h"
|
||||
typedef int (*fastweb_module_regist)(void*, void*);
|
||||
typedef int (*lua_interface)(void*);
|
||||
struct module_info {
|
||||
void* dll = nullptr;
|
||||
fastweb_module_regist func = nullptr;
|
||||
@@ -48,5 +49,8 @@ namespace fastweb
|
||||
private:
|
||||
// DLL模块
|
||||
std::map<std::string, module_info> m_modules;
|
||||
// LUA虚拟机引用
|
||||
std::string m_lua_include_path;
|
||||
std::string m_lua_include_cpath;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -22,6 +22,9 @@ If you have any questions, please contact us: 1585346868@qq.com Or visit our web
|
||||
#include "util/strutils.h"
|
||||
#include "util/system.h"
|
||||
#include "slave.h"
|
||||
|
||||
#define FASTWEB_VERSION "V1.0.4"
|
||||
|
||||
#define QUIT_WAIT std::cout << "Please exit after entering any character...";std::cin.get();return -1
|
||||
|
||||
void* start(const char* config_filepath)
|
||||
@@ -47,6 +50,7 @@ void ouput_help()
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
std::cout << "|------------------------[FASTWEB]----------------------------" << std::endl;
|
||||
std::cout << "| Version:\t"<< FASTWEB_VERSION << std::endl;
|
||||
std::cout << "| WorkingDirectory:\t"<< strutils::replace(system::current_dir(),'\\','/') << std::endl;
|
||||
std::cout << "| Args" << std::endl;
|
||||
for (int i = 0; i < argc; i++)
|
||||
|
||||
Reference in New Issue
Block a user