增加自定义模块

This commit is contained in:
xx
2024-06-01 19:18:14 +08:00
parent ae449ff5d3
commit a090307768
26 changed files with 438 additions and 105 deletions

View File

@@ -1,7 +1,8 @@
cmake_minimum_required(VERSION 3.5)
project("fastweb")
# 设置全局属性
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# 设置自定义配置类型
@@ -14,7 +15,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(FASTWEBCORE ${PROJECT_NAME}core)
# 安装复制
set(CMAKE_INSTALL_ALWAYS_COPY TRUE)
# 设置根目录
set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
# Recursively get all source files
file(GLOB_RECURSE SOURCE_FILES
"${PROJECT_SOURCE_DIR}/src/*.cpp"
@@ -126,10 +128,19 @@ else()
endif()
# 编译测试调用示例
add_executable(${PROJECT_NAME} tests/main.cpp)
target_link_libraries(${PROJECT_NAME} ${FASTWEBCORE})
set_target_properties(${PROJECT_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
# 查找并添加所有模块
file(GLOB MODULES RELATIVE ${CMAKE_SOURCE_DIR}/module ${CMAKE_SOURCE_DIR}/module/*)
foreach(MODULE ${MODULES})
if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/module/${MODULE})
add_subdirectory(${CMAKE_SOURCE_DIR}/module/${MODULE})
endif()
endforeach()
######################## 安装 ########################
install(TARGETS ${FASTWEBCORE} DESTINATION $<IF:$<CONFIG:Debug>,bin/debug,bin/release>)
install(TARGETS ${PROJECT_NAME} DESTINATION $<IF:$<CONFIG:Debug>,bin/debug,bin/release>)

View File

@@ -7,6 +7,8 @@ base=${current_dir}
app_dir=${base}/scripts/app
; LUA库目录
lib_dir=${base}/scripts/lib
; 模块目录
module_dir=${base}/module
; LUA虚拟机缓存数量(并发越高越大)-建议10
lua_cache_size=3000
; 脚本映射网站目录
@@ -16,6 +18,7 @@ app_mapping_dir=/scripts/
; 自动检测文件修改时间(秒)
auto_update_sec=3
[website]
; 网站静态文件目录
static_dir=${base}/www

View File

@@ -0,0 +1,95 @@
# 获取当前目录的名称
get_filename_component(MODULE_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
# 设置项目名为当前目录名
project(${MODULE_NAME})
# 搜索源文件和头文件
file(GLOB_RECURSE SOURCE_FILES "${PROJECT_SOURCE_DIR}/*.cpp")
file(GLOB_RECURSE HEADER_FILES
"${PROJECT_SOURCE_DIR}/*.h"
"../*.h"
)
# 将源文件分配到 Source Files 文件夹
foreach(source IN LISTS SOURCE_FILES)
get_filename_component(source_path "${source}" PATH)
file(RELATIVE_PATH source_path_rel "${PROJECT_SOURCE_DIR}" "${source_path}")
string(REPLACE "/" "\\" source_path_rel_win "${source_path_rel}")
source_group("Source Files\\${source_path_rel_win}" FILES "${source}")
endforeach()
# 将头文件分配到 Header Files 文件夹
foreach(header IN LISTS HEADER_FILES)
get_filename_component(header_path "${header}" PATH)
file(RELATIVE_PATH header_path_rel "${PROJECT_SOURCE_DIR}" "${header_path}")
string(REPLACE "/" "\\" header_path_rel_win "${header_path_rel}")
source_group("Header Files\\${header_path_rel_win}" FILES "${header}")
endforeach()
include_directories(${ROOT_DIR}/module)
include_directories(${ROOT_DIR}/3rdpary)
# 添加共享库
add_library(${MODULE_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES})
if(MSVC)
target_link_libraries(${MODULE_NAME} PRIVATE
odbc32.lib
User32.lib
Advapi32.lib
IPHLPAPI.lib
WS2_32.lib
Shell32.lib
${YLIB}/lib/libcrypto_static_win64.lib
$<$<CONFIG:Debug>:${ROOT_DIR}/3rdparty/HP-Socket/Lib/HPSocket_D.lib>
$<$<CONFIG:Debug>:${ROOT_DIR}/3rdparty/mysql/lib/Debug/mysqlcppconn.lib>
$<$<CONFIG:Debug>:${YLIB}/lib/leveldb_d.lib>
$<$<CONFIG:Debug>:${YLIB}/lib/libzip_d.lib>
$<$<CONFIG:Debug>:${YLIB}/lib/lua_d.lib>
$<$<CONFIG:Debug>:${YLIB}/lib/sqlite3_d.lib>
$<$<CONFIG:Debug>:${YLIB}/lib/ylib_d.lib>
$<$<CONFIG:Debug>:${YLIB}/lib/zlib_d.lib>
$<$<CONFIG:Debug>:${ROOT_DIR}/3rdparty/soci/lib/Debug/libsoci_core_4_1.lib>
$<$<CONFIG:Debug>:${ROOT_DIR}/3rdparty/soci/lib/Debug/libsoci_empty_4_1.lib>
$<$<CONFIG:Debug>:${ROOT_DIR}/3rdparty/soci/lib/Debug/libsoci_odbc_4_1.lib>
$<$<CONFIG:Debug>:${ROOT_DIR}/3rdparty/soci/lib/Debug/soci_core_4_1.lib>
$<$<CONFIG:Debug>:${ROOT_DIR}/3rdparty/soci/lib/Debug/soci_empty_4_1.lib>
$<$<CONFIG:Debug>:${ROOT_DIR}/3rdparty/soci/lib/Debug/soci_odbc_4_1.lib>
$<$<CONFIG:Release>:${ROOT_DIR}/3rdparty/HP-Socket/Lib/HPSocket.lib>
$<$<CONFIG:Release>:${ROOT_DIR}/3rdparty/mysql/lib/Release/mysqlcppconn.lib>
$<$<CONFIG:Release>:${YLIB}/lib/leveldb.lib>
$<$<CONFIG:Release>:${YLIB}/lib/libzip.lib>
$<$<CONFIG:Release>:${YLIB}/lib/lua.lib>
$<$<CONFIG:Release>:${YLIB}/lib/sqlite3.lib>
$<$<CONFIG:Release>:${YLIB}/lib/ylib.lib>
$<$<CONFIG:Release>:${YLIB}/lib/zlib.lib>
$<$<CONFIG:Release>:${ROOT_DIR}/3rdparty/soci/lib/Release/libsoci_core_4_1.lib>
$<$<CONFIG:Release>:${ROOT_DIR}/3rdparty/soci/lib/Release/libsoci_empty_4_1.lib>
$<$<CONFIG:Release>:${ROOT_DIR}/3rdparty/soci/lib/Release/libsoci_odbc_4_1.lib>
$<$<CONFIG:Release>:${ROOT_DIR}/3rdparty/soci/lib/Release/soci_core_4_1.lib>
$<$<CONFIG:Release>:${ROOT_DIR}/3rdparty/soci/lib/Release/soci_empty_4_1.lib>
$<$<CONFIG:Release>:${ROOT_DIR}/3rdparty/soci/lib/Release/soci_odbc_4_1.lib>
)
else()
target_link_libraries(${MODULE_NAME}
hpsocket
ylib
leveldb
soci_core
soci_firebird
soci_mysql
soci_odbc
soci_postgresql
soci_sqlite3
crypto
lua5.3
mysqlcppconn
pthread
)
endif()
# 设置生成的项目文件夹为 module
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "module")
install(TARGETS ${MODULE_NAME} DESTINATION $<IF:$<CONFIG:Debug>,bin/debug/module,bin/release/module>)

33
module/hello/hello.cpp Normal file
View File

@@ -0,0 +1,33 @@
#include "hello.h"
#include "module.h"
#include "sol/sol.hpp"
hello::hello()
{
}
hello::~hello()
{
}
std::string hello::name()
{
return "My name is `Fast Web`";
}
extern "C" {
#ifdef _WIN32
DLL_EXPORT
#endif
int fastweb_module_regist(void* sol2, void* lua)
{
sol::state* state = static_cast<sol::state*>(sol2);
state->new_usertype<hello>("hello",
"name", &hello::name
);
// 返回成功
return 0;
}
}

9
module/hello/hello.h Normal file
View File

@@ -0,0 +1,9 @@
#pragma once
#include <string>
class hello
{
public:
hello();
~hello();
static std::string name();
};

18
module/module.h Normal file
View File

@@ -0,0 +1,18 @@
#if defined(_WIN32) || defined(_WIN64)
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __attribute__((visibility("default")))
#endif
extern "C" {
/// <summary>
/// 注册模块入口
/// </summary>
/// <param name="sol2"></param>
/// <param name="lua"></param>
/// <returns>
/// 0=成功
/// 1=失败
/// </returns>
DLL_EXPORT int fastweb_module_regist(void* sol2,void* lua);
}

View File

@@ -91,6 +91,7 @@ void config::cache()
scripts.app_dir = m_ini.read("scripts","app_dir");
scripts.lib_dir = m_ini.read("scripts", "lib_dir");
scripts.module_dir = m_ini.read("scripts", "module_dir");
scripts.lua_cache_size = ylib::stoi(m_ini.read("scripts", "lua_cache_size"));
scripts.app_mapping_dir = m_ini.read("scripts", "app_mapping_dir");
scripts.auto_update_sec = ylib::stoi(m_ini.read("scripts", "auto_update_sec"));

View File

@@ -14,6 +14,7 @@ public:
struct scripts {
std::string app_dir;
std::string lib_dir;
std::string module_dir;
uint32 lua_cache_size = 0;
std::string app_mapping_dir;
uint32 auto_update_sec = 0;

161
src/core/modulemanager.cpp Normal file
View File

@@ -0,0 +1,161 @@
#include "modulemanager.h"
#include "util/file.h"
#include "core/config.h"
#include "core/global.h"
#ifdef _WIN32
#include <Windows.h>
#else
#endif
#include "module/http/request.h"
#include "module/http/response.h"
#include "module/http/session.h"
#include "module/http/httpclient.h"
#include "module/mysql.h"
#ifdef _WIN32
#include "module/mssql.h"
#endif
#include "module/localstorage.h"
#include "module/globalfuns.h"
#include "module/mutex.h"
#include "module/codec.h"
#include "module/time.h"
#include "module/file.h"
#include "module/sys.h"
module_manager::module_manager()
{
}
module_manager::~module_manager()
{
}
void module_manager::start()
{
close();
auto ms = modules();
for (size_t i = 0; i < ms.size(); i++)
{
module_info mi;
std::string mod_filepath = sConfig->scripts.module_dir + "/" + ms[i];
#ifdef _WIN32
mi.dll = LoadLibrary(mod_filepath.c_str());
if (mi.dll == nullptr)
{
LOG_ERROR("module loading failed, filename: " + mod_filepath);
continue;
}
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);
FreeLibrary((HMODULE)mi.dll);
continue;
}
m_modules.emplace(mod_filepath, mi);
/*if (api_func(lua, lua->lua_state()) == 0)
{
LOG_INFO("successfully regist module, filename: " + mod_filepath);
continue;
}
LOG_ERROR("regist module failed, filename: " + mod_filepath);*/
#else
#endif
}
}
void module_manager::close()
{
for_iter(iter, m_modules)
{
#ifdef _WIN32
FreeLibrary((HMODULE)iter->second.dll);
#else
#endif
}
m_modules.clear();
}
void module_manager::load(sol::state* lua)
{
load_core(lua);
load_lualib(lua);
load_3rdparty(lua);
}
void module_manager::load_core(sol::state* lua)
{
lua->open_libraries(
sol::lib::base,
sol::lib::package,
sol::lib::math,
sol::lib::string,
sol::lib::table,
sol::lib::utf8,
sol::lib::bit32,
sol::lib::coroutine,
sol::lib::count,
sol::lib::ffi,
sol::lib::io,
sol::lib::jit,
sol::lib::os
);
module::request::regist(lua);
module::response::regist(lua);
module::session::regist(lua);
module::httpclient::regist(lua);
module::mysql_regist(lua);
#ifdef _WIN32
module::mssql::regist(lua);
#endif
module::regist_globalfuns(lua);
module::local_storage::regist(lua);
module::mutex::regist(lua);
module::auto_lock::regist(lua);
module::codec::regist(lua);
module::time::regist(lua);
module::file::regist(lua);
module::sys::regist(lua);
global::getInstance()->regist_lua(lua);
}
void module_manager::load_3rdparty(sol::state* lua)
{
for_iter(iter, m_modules)
{
if (iter->second.func(lua, lua->lua_state()) != 0)
{
LOG_ERROR("egist module failed, filename: "+iter->first);
}
}
}
void module_manager::load_lualib(sol::state* lua)
{
// 获取当前的package.path添加新的搜索路径
std::string current_path = (*lua)["package"]["path"]; // 获取当前的路径
current_path += ";" + sConfig->scripts.lib_dir + "/?.lua"; // 添加新的路径
(*lua)["package"]["path"] = current_path; // 设置修改后的路径
}
std::vector<std::string> module_manager::modules()
{
std::vector<std::string> results;
auto luas = ylib::file::traverse(sConfig->scripts.module_dir, "(.*\\.dll)");
for_iter(iter, luas)
{
if (iter->second == IS_DIRECTORY)
continue;
std::string path = strutils::replace(iter->first, '\\', '/');
results.push_back(path);
}
return results;
}

48
src/core/modulemanager.h Normal file
View File

@@ -0,0 +1,48 @@
#pragma once
#include <map>
#include "sol/sol.hpp"
#include "core/structs.h"
typedef int (*fastweb_module_regist)(void*, void*);
struct module_info {
void* dll = nullptr;
fastweb_module_regist func = nullptr;
};
/// <summary>
/// 模块管理器
/// </summary>
class module_manager{
public:
module_manager();
~module_manager();
void start();
void close();
/// <summary>
/// 创建虚拟机
/// </summary>
/// <returns></returns>
void load(sol::state* lua);
private:
/// <summary>
/// 加载核心库
/// </summary>
/// <param name="lua"></param>
void load_core(sol::state* lua);
/// <summary>
/// 加载三方库
/// </summary>
void load_3rdparty(sol::state* lua);
/// <summary>
/// 加载LUA库
/// </summary>
/// <param name="lua"></param>
void load_lualib(sol::state* lua);
/// <summary>
/// 取模块文件列表
/// </summary>
/// <returns></returns>
std::vector<std::string> modules();
private:
std::map<std::string, module_info> m_modules;
};

View File

@@ -8,26 +8,13 @@
#include "core/config.h"
#include "core/global.h"
#include "module/http/request.h"
#include "module/http/response.h"
#include "module/http/session.h"
#include "module/http/httpclient.h"
#include "module/mysql.h"
#ifdef _WIN32
#include "module/mssql.h"
#endif
#include "module/localstorage.h"
#include "module/globalfuns.h"
#include "module/mutex.h"
#include "module/codec.h"
#include "module/time.h"
#include "module/file.h"
#include "module/sys.h"
#define LOOP_STATE_USE 1
bool state_manager::start()
{
close();
::ithread::start();
m_module_manager.start();
return true;
}
@@ -38,50 +25,14 @@ void state_manager::close()
luastate* state = nullptr;
while (m_states.pop(state))
delete state;
m_module_manager.close();
}
luastate* state_manager::create()
{
luastate* lua = new luastate();
lua->flag = m_flag;
lua->state->open_libraries(
sol::lib::base,
sol::lib::package,
sol::lib::math,
sol::lib::string,
sol::lib::table,
sol::lib::utf8,
sol::lib::bit32,
sol::lib::coroutine,
sol::lib::count,
sol::lib::ffi,
sol::lib::io,
sol::lib::jit,
sol::lib::os
);
{
// 获取当前的package.path添加新的搜索路径
std::string current_path = (*lua->state)["package"]["path"]; // 获取当前的路径
current_path += ";"+ sConfig->scripts.lib_dir +"/?.lua"; // 添加新的路径
(*lua->state)["package"]["path"] = current_path; // 设置修改后的路径
}
module::request::regist(*lua->state);
module::response::regist(*lua->state);
module::session::regist(*lua->state);
module::httpclient::regist(*lua->state);
module::mysql_regist(*lua->state);
#ifdef _WIN32
module::mssql::regist(*lua->state);
#endif
module::regist_globalfuns(*lua->state);
module::local_storage::regist(lua->state);
module::mutex::regist(lua->state);
module::auto_lock::regist(lua->state);
module::codec::regist(lua->state);
module::time::regist(lua->state);
module::file::regist(lua->state);
module::sys::regist(lua->state);
global::getInstance()->regist_lua(lua->state);
// 加载库或模块
m_module_manager.load(lua->state);
return lua;
}

View File

@@ -11,7 +11,7 @@
#include "core/structs.h"
#include "core/lualibdetecter.h"
#include "core/modulemanager.h"
/// <summary>
/// LUA状态管理器
/// </summary>
@@ -41,6 +41,8 @@ private:
size_t m_flag = 0;
// LIB变化检测
lualib_detecter m_lib_detecter;
// 模块管理器
module_manager m_module_manager;
private:
// 通过 ithread 继承
bool run() override;

View File

@@ -4,12 +4,12 @@
#include "util/time.h"
#include "core/global.h"
static ylib::counter<uint64> s_counter_guid;
void module::regist_globalfuns(sol::state& lua)
void module::regist_globalfuns(sol::state* lua)
{
lua.set_function("global_get", module::global_get);
lua.set_function("global_set", module::global_set);
lua.set_function("make_software_guid", module::make_software_guid);
lua.set_function("throw_string", module::throw_string);
lua->set_function("global_get", module::global_get);
lua->set_function("global_set", module::global_set);
lua->set_function("make_software_guid", module::make_software_guid);
lua->set_function("throw_string", module::throw_string);
}
std::string module::make_software_guid()
{

View File

@@ -5,7 +5,7 @@
/// </summary>
namespace module
{
void regist_globalfuns(sol::state& lua);
void regist_globalfuns(sol::state* lua);
/// <summary>
/// 生成软件唯一GUID
/// </summary>

View File

@@ -43,9 +43,9 @@ ushort module::httpclient::status()
return m_client.status();
}
void module::httpclient::regist(sol::state& state)
void module::httpclient::regist(sol::state* lua)
{
state.new_usertype<module::httpclient>("httpclient",
lua->new_usertype<module::httpclient>("httpclient",
"new", sol::constructors<module::httpclient()>(),
"get", &module::httpclient::get,
"post", &module::httpclient::post,

View File

@@ -17,7 +17,7 @@ namespace module
std::string response();
ushort status();
static void regist(sol::state& state);
static void regist(sol::state* lua);
private:
network::http::client_plus m_client;
};

View File

@@ -45,10 +45,10 @@ void* module::request::website()
{
return m_request->website();
}
void module::request::regist(sol::state& state)
void module::request::regist(sol::state* lua)
{
// 绑定 Request 类到 Lua
state.new_usertype<module::request>("module_request",
lua->new_usertype<module::request>("module_request",
"header", &module::request::header,
"method", &module::request::method,
"filepath", &module::request::filepath,
@@ -62,11 +62,11 @@ void module::request::regist(sol::state& state)
"url_param", &module::request::url_param,
"body", &module::request::body
);
state["GET"] = (int)network::http::GET;
state["POST"] = (int)network::http::POST;
state["DEL"] = (int)network::http::DEL;
state["HEAD"] = (int)network::http::HEAD;
state["PUT"] = (int)network::http::PUT;
(*lua)["GET"] = (int)network::http::GET;
(*lua)["POST"] = (int)network::http::POST;
(*lua)["DEL"] = (int)network::http::DEL;
(*lua)["HEAD"] = (int)network::http::HEAD;
(*lua)["PUT"] = (int)network::http::PUT;
}

View File

@@ -30,7 +30,7 @@ namespace module
std::string body();
void* website();
static void regist(sol::state& state);
static void regist(sol::state* lua);
private:
bool request_param(const std::string& name, std::string& value);
private:

View File

@@ -10,10 +10,10 @@ module::response::~response()
{
}
void module::response::regist(sol::state& state)
void module::response::regist(sol::state* lua)
{
// 绑定 Request 类到 Lua
state.new_usertype<module::response>("module_response",
lua->new_usertype<module::response>("module_response",
"send_data", &module::response::send_data,
"send", &module::response::send,
"send_file", &module::response::send_file,

View File

@@ -18,7 +18,7 @@ namespace module
bool redirect(const std::string& filepath, bool MovedPermanently = false);
bool forward(const std::string& filepath);
void header(const std::string& name, const std::string& value);
static void regist(sol::state& state);
static void regist(sol::state* lua);
private:
network::http::response* m_response = nullptr;
};

View File

@@ -38,9 +38,9 @@ bool module::session::check()
return m_session->check();
}
void module::session::regist(sol::state& state)
void module::session::regist(sol::state* lua)
{
state.new_usertype<module::session>("module_session",
lua->new_usertype<module::session>("module_session",
"check", &module::session::check,
"get", &module::session::get,
"id", &module::session::id,

View File

@@ -16,7 +16,7 @@ namespace module
void set(const std::string& name, const std::string& value);
std::string get(const std::string& name);
bool check();
static void regist(sol::state& state);
static void regist(sol::state* lua);
private:
network::http::session* m_session = nullptr;
};

View File

@@ -91,9 +91,9 @@ bool module::mssql::next()
}
void module::mssql::regist(sol::state& lua)
void module::mssql::regist(sol::state* lua)
{
lua.new_usertype<module::mssql>("mssql",
lua->new_usertype<module::mssql>("mssql",
"new", sol::constructors<module::mssql(const std::string&)>(),
"get_dob", &module::mssql::get_dob,
"get_i32", &module::mssql::get_i32,

View File

@@ -34,7 +34,7 @@ namespace module
/// 注册
/// </summary>
/// <param name="lua"></param>
static void regist(sol::state& lua);
static void regist(sol::state* lua);
private:
std::shared_ptr<soci::session> m_session;
//std::shared_ptr<soci::statement> m_st;

View File

@@ -98,9 +98,9 @@ uint64 module::select::count()
return m_select->count();
}
void module::select::regist(sol::state& lua)
void module::select::regist(sol::state* lua)
{
lua.new_usertype<module::select>("mysql_builder_select",
lua->new_usertype<module::select>("mysql_builder_select",
"new", sol::constructors<module::select(ylib::mysql::conn*)>(),
"count", &module::select::count,
"field", &module::select::field,
@@ -223,9 +223,9 @@ void module::update::clear()
m_update->clear();
}
void module::update::regist(sol::state& lua)
void module::update::regist(sol::state* lua)
{
lua.new_usertype<module::update>("mysql_builder_update",
lua->new_usertype<module::update>("mysql_builder_update",
"new", sol::constructors<module::update(ylib::mysql::conn*)>(),
"exec", &module::update::exec,
"limit", &module::update::limit,
@@ -301,9 +301,9 @@ void module::insert::clear()
m_insert->clear();
}
void module::insert::regist(sol::state& lua)
void module::insert::regist(sol::state* lua)
{
lua.new_usertype<module::insert>("mysql_builder_insert",
lua->new_usertype<module::insert>("mysql_builder_insert",
"new", sol::constructors<module::insert(ylib::mysql::conn*)>(),
"exec", &module::insert::exec,
"table", &module::insert::table,
@@ -390,9 +390,9 @@ void module::delete_::clear()
m_delete->clear();
}
void module::delete_::regist(sol::state& lua)
void module::delete_::regist(sol::state* lua)
{
lua.new_usertype<module::delete_>("mysql_builder_delete",
lua->new_usertype<module::delete_>("mysql_builder_delete",
"new", sol::constructors<module::delete_(ylib::mysql::conn*)>(),
"exec", &module::delete_::exec,
"limit", &module::delete_::limit,
@@ -408,12 +408,12 @@ void module::delete_::regist(sol::state& lua)
);
}
void module::mysql_regist(sol::state& lua)
void module::mysql_regist(sol::state* lua)
{
lua["DESC"] = ylib::sort::DESC;
lua["ASC"] = ylib::sort::ASC;
(*lua)["DESC"] = ylib::sort::DESC;
(*lua)["ASC"] = ylib::sort::ASC;
lua.new_usertype<ylib::mysql::conn>("mysql_conn",
lua->new_usertype<ylib::mysql::conn>("mysql_conn",
"clear", &ylib::mysql::conn::clear,
"close", &ylib::mysql::conn::close,
"commit", &ylib::mysql::conn::commit,
@@ -423,7 +423,7 @@ void module::mysql_regist(sol::state& lua)
"rollback", &ylib::mysql::conn::rollback,
"setsql", &ylib::mysql::conn::setsql
);
lua.new_usertype<module::mysql>("mysql_pool",
lua->new_usertype<module::mysql>("mysql_pool",
"new", sol::constructors<module::mysql()>(),
"start", &module::mysql::start,
"close", &module::mysql::close,
@@ -589,9 +589,9 @@ sol::table module::mysql_result::table(sol::this_state s)
return result_table;
}
void module::mysql_result::regist(sol::state& lua)
void module::mysql_result::regist(sol::state* lua)
{
lua.new_usertype<module::mysql_result>("mysql_result",
lua->new_usertype<module::mysql_result>("mysql_result",
"field_name", &module::mysql_result::field_name,
"get", &module::mysql_result::get,
"next", &module::mysql_result::next,

View File

@@ -9,7 +9,7 @@ namespace module
/// 注册
/// </summary>
/// <param name="lua"></param>
void mysql_regist(sol::state& lua);
void mysql_regist(sol::state* lua);
/// <summary>
/// 结果集
/// </summary>
@@ -61,7 +61,7 @@ namespace module
/// 注册
/// </summary>
/// <param name="lua"></param>
static void regist(sol::state& lua);
static void regist(sol::state* lua);
private:
ylib::mysql::result* m_result = nullptr;
};
@@ -85,7 +85,7 @@ namespace module
void clear();
std::shared_ptr<module::mysql_result> query();
uint64 count();
static void regist(sol::state& lua);
static void regist(sol::state* lua);
private:
std::shared_ptr<ylib::select> m_select;
};
@@ -109,7 +109,7 @@ namespace module
module::update& orderby(const std::string& field, int sort);
uint64 exec();
void clear();
static void regist(sol::state& lua);
static void regist(sol::state* lua);
private:
std::shared_ptr<ylib::update> m_update;
};
@@ -125,7 +125,7 @@ namespace module
module::insert& set_not_ppst(const std::string& name, const std::string& value);
uint64 exec();
void clear();
static void regist(sol::state& lua);
static void regist(sol::state* lua);
private:
std::shared_ptr<ylib::insert> m_insert;
};
@@ -144,7 +144,7 @@ namespace module
module::delete_& orderby(const std::string& field, int sort);
uint64 exec();
void clear();
static void regist(sol::state& lua);
static void regist(sol::state* lua);
private:
std::shared_ptr <ylib::delete_> m_delete;
};