This commit is contained in:
xx
2024-06-16 15:07:19 +08:00
parent 761966db0d
commit d85905f4f5
8 changed files with 330 additions and 14 deletions

View File

@@ -14,7 +14,7 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(FASTWEBCORE ${PROJECT_NAME}core)
# 安装复制
set(CMAKE_INSTALL_ALWAYS_COPY TRUE)
set(CMAKE_INSTALL_ALWAYS_COPY TRUE)
# 设置根目录
set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})

View File

@@ -37,6 +37,9 @@ If you have any questions, please contact us: 1585346868@qq.com Or visit our web
#include "module/mutex.h"
#include "module/timer.h"
#include "module/process.h"
#include "module/ini.h"
#include "module/codec.h"
#include "module/sys.h"
fastweb::module_manager::module_manager(fastweb::app* app):Interface(app)
{
}
@@ -70,13 +73,13 @@ void fastweb::module_manager::start()
for (size_t i = 0; i < ms.size(); i++)
{
module_info mi;
std::string mod_filepath = app()->config->scripts.module_dir + "/" + ms[i];
std::string mod_filepath =ms[i];
#ifdef _WIN32
SetDllDirectoryA(ylib::file::parent_dir(mod_filepath).c_str());
mi.dll = LoadLibrary(mod_filepath.c_str());
if (mi.dll == nullptr)
{
LOG_ERROR("module loading failed, filename: " + mod_filepath
LOG_DEBUG("module loading failed, filename: " + mod_filepath
+","+ codec::to_utf8(get_last_error_desc())
);
continue;
@@ -192,6 +195,9 @@ void fastweb::module_manager::load_core(sol::state* lua)
module::auto_lock::regist(lua);
module::timer::regist(lua);
module::process::regist(lua);
module::ini::regist(lua);
module::codec::regist(lua);
module::sys::regist(lua);
app()->global->regist(lua);
@@ -220,20 +226,42 @@ void fastweb::module_manager::load_lualib(sol::state* lua)
std::vector<std::string> fastweb::module_manager::modules()
{
std::vector<std::string> results;
auto luas = ylib::file::traverse(app()->config->scripts.module_dir, "(.*\\.dll)");
for_iter(iter, luas)
{
if (iter->second == IS_DIRECTORY)
continue;
std::string path = strutils::replace(iter->first, '\\', '/');
if (path.find("/") != -1)
auto insert_dll_path = [&](const std::string& dir) {
auto luas = ylib::file::traverse(dir, "(.*\\.dll)");
for_iter(iter, luas)
{
if (strutils::split(path, '/').size() != 2)
continue; //多级不支持
if (ylib::file::parent_dir(path) != ylib::file::filename(path, false))
if (iter->second == IS_DIRECTORY)
continue;
std::string path = strutils::replace(iter->first, '\\', '/');
if (path.find("/") != -1)
{
if (strutils::split(path, '/').size() != 2)
continue; //多级不支持
if (ylib::file::parent_dir(path) != ylib::file::filename(path, false))
continue;
}
results.push_back(dir+"/"+path);
}
results.push_back(path);
};
std::string search_path = app()->config->scripts.module_dir + "/.install";
insert_dll_path(app()->config->scripts.module_dir);
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;
insert_dll_path(search_path+"/"+iter->first);
}
// auto luas = ylib::file::traverse(app()->config->scripts.module_dir, "(.*\\.dll)");
return results;
}

54
src/module/codec.cpp Normal file
View File

@@ -0,0 +1,54 @@
/*Software License
Copyright(C) 2024[liuyingjie]
License Terms
Usage Rights
Any individual or entity is free to use, copy, and distribute the binary form of this software without modification to the source code, without the need to disclose the source code.
If the source code is modified, the modifications must be open - sourced under the same license.This means that the modifications must be disclosed and accompanied by a copy of this license.
Future Versions Updates
From this version onwards, all future releases will be governed by the terms of the latest version of the license.This license will automatically be nullified and replaced by the new version.
Users must comply with the terms of the new license issued in future releases.
Liability and Disclaimer
This software is provided “as is”, without any express or implied warranties, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non - infringement.In no event shall the author or copyright holder be liable for any claims, damages, or other liabilities, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.
Contact Information
If you have any questions, please contact us: 1585346868@qq.com Or visit our website fwlua.com.
*/
#include "codec.h"
#include "util/codec.h"
std::string module::codec::url_de(const std::string& value)
{
return ylib::codec::url::de(value);
}
std::string module::codec::url_en(const std::string& value)
{
return ylib::codec::url::en(value);
}
std::string module::codec::to_utf8(const std::string& value)
{
return ylib::codec::to_utf8(value);
}
std::string module::codec::to_gbk(const std::string& value)
{
return ylib::codec::to_gbk(value);
}
std::string module::codec::md5(const std::string& value)
{
return ylib::codec::md5(value);
}
void module::codec::regist(sol::state* lua)
{
lua->new_usertype<module::codec>("codec",
"url_de", &module::codec::url_de,
"url_en", &module::codec::url_en,
"to_utf8", &module::codec::to_utf8,
"to_gbk", &module::codec::to_gbk,
"md5", &module::codec::md5
);
}

37
src/module/codec.h Normal file
View File

@@ -0,0 +1,37 @@
#pragma once
#include "sol/sol.hpp"
#include "basemodule.h"
namespace module
{
/// <summary>
/// 编解码
/// </summary>
class codec{
public:
/// <summary>
/// URL解码
/// </summary>
static std::string url_de(const std::string& value);
/// <summary>
/// URL编码
/// </summary>
static std::string url_en(const std::string& value);
/// <summary>
/// GBK转UTF8
/// </summary>
/// <returns></returns>
static std::string to_utf8(const std::string& value);
static std::string to_gbk(const std::string& value);
/// <summary>
/// MD5校验
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
static std::string md5(const std::string& value);
static void regist(sol::state* lua);
};
}

119
src/module/ini.cpp Normal file
View File

@@ -0,0 +1,119 @@
/*Software License
Copyright(C) 2024[liuyingjie]
License Terms
Usage Rights
Any individual or entity is free to use, copy, and distribute the binary form of this software without modification to the source code, without the need to disclose the source code.
If the source code is modified, the modifications must be open - sourced under the same license.This means that the modifications must be disclosed and accompanied by a copy of this license.
Future Versions Updates
From this version onwards, all future releases will be governed by the terms of the latest version of the license.This license will automatically be nullified and replaced by the new version.
Users must comply with the terms of the new license issued in future releases.
Liability and Disclaimer
This software is provided “as is”, without any express or implied warranties, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non - infringement.In no event shall the author or copyright holder be liable for any claims, damages, or other liabilities, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.
Contact Information
If you have any questions, please contact us: 1585346868@qq.com Or visit our website fwlua.com.
*/
#include "ini.h"
module::ini::ini()
{
}
module::ini::~ini()
{
}
bool module::ini::open(const std::string& filepath)
{
return m_ini.open(filepath);
}
void module::ini::close()
{
m_ini.close();
}
std::string module::ini::read(const std::string& node, const std::string& key, const std::string& default_value) const
{
return m_ini.read(node,key,default_value);
}
bool module::ini::write(const std::string& node, const std::string& key, const std::string& value)
{
return m_ini.write(node,key,value);
}
bool module::ini::del(const std::string& node, const std::string& key)
{
return m_ini.del(node, key);
}
sol::table module::ini::nodes(sol::this_state s)
{
sol::state_view lua(s);
sol::table result_table = lua.create_table();
int row_num = 1;
auto names = m_ini.names();
for_iter(iter, names)
result_table[row_num++] = *iter;
return result_table;
}
sol::table module::ini::keys(const std::string& node, sol::this_state s)
{
sol::state_view lua(s);
sol::table result_table = lua.create_table();
int row_num = 1;
auto names = m_ini.keys(node);
for_iter(iter, names)
result_table[row_num++] = *iter;
return result_table;
}
bool module::ini::exist_key(const std::string& node, const std::string& key)
{
return m_ini.exist_key(node, key);
}
bool module::ini::exist_node(const std::string& node)
{
return m_ini.exist_name(node);
}
sol::table module::ini::table(sol::this_state s)
{
sol::state_view lua(s);
sol::table result_table = lua.create_table();
auto nodes = m_ini.names();
for_iter(iter, nodes)
{
sol::table node_table = lua.create_table();
auto keys = m_ini.keys(*iter);
for (size_t i = 0; i < keys.size(); i++)
{
node_table[keys[i]] = m_ini.read(*iter,keys[i]);
}
result_table[*iter] = node_table;
}
return result_table;
}
void module::ini::regist(sol::state* lua)
{
lua->new_usertype<module::ini>("ini",
"new", sol::constructors<module::ini()>(),
"close", &module::ini::close,
"del", &module::ini::del,
"exist_key", &module::ini::exist_key,
"exist_node", &module::ini::exist_node,
"keys", &module::ini::keys,
"nodes", &module::ini::nodes,
"open", &module::ini::open,
"read", &module::ini::read,
"table", &module::ini::table,
"write", &module::ini::write
);
}

30
src/module/ini.h Normal file
View File

@@ -0,0 +1,30 @@
#pragma once
#include "sol/sol.hpp"
#include "util/ini.h"
namespace module
{
/// <summary>
/// INI配置
/// </summary>
class ini {
public:
ini();
~ini();
bool open(const std::string& filepath);
void close();
std::string read(const std::string& node, const std::string& key, const std::string& default_value) const;
bool write(const std::string& node, const std::string& key, const std::string& value);
bool del(const std::string& node, const std::string& key);
sol::table nodes(sol::this_state s);
sol::table keys(const std::string& node, sol::this_state s);
bool exist_key(const std::string& node, const std::string& key);
bool exist_node(const std::string& node);
sol::table table(sol::this_state s);
static void regist(sol::state* lua);
private:
ylib::ini m_ini;
};
}

31
src/module/sys.cpp Normal file
View File

@@ -0,0 +1,31 @@
/*Software License
Copyright(C) 2024[liuyingjie]
License Terms
Usage Rights
Any individual or entity is free to use, copy, and distribute the binary form of this software without modification to the source code, without the need to disclose the source code.
If the source code is modified, the modifications must be open - sourced under the same license.This means that the modifications must be disclosed and accompanied by a copy of this license.
Future Versions Updates
From this version onwards, all future releases will be governed by the terms of the latest version of the license.This license will automatically be nullified and replaced by the new version.
Users must comply with the terms of the new license issued in future releases.
Liability and Disclaimer
This software is provided “as is”, without any express or implied warranties, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non - infringement.In no event shall the author or copyright holder be liable for any claims, damages, or other liabilities, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.
Contact Information
If you have any questions, please contact us: 1585346868@qq.com Or visit our website fwlua.com.
*/
#include "sys.h"
#include "util/system.h"
void module::sys::sleep_msec(uint32 msec)
{
system::sleep_msec(msec);
}
void module::sys::regist(sol::state* lua)
{
lua->new_usertype<module::sys>("sys",
"sleep_msec", &module::sys::sleep_msec
);
}

17
src/module/sys.h Normal file
View File

@@ -0,0 +1,17 @@
#pragma once
#include "sol/sol.hpp"
#include "core/define.h"
namespace module
{
/// <summary>
/// 系统
/// </summary>
class sys {
public:
static void sleep_msec(uint32 msec);
static void regist(sol::state* lua);
};
}