diff --git a/CMakeLists.txt b/CMakeLists.txt index b5b9d1c..0e41c8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 $,bin/debug,bin/release>) install(TARGETS ${PROJECT_NAME} DESTINATION $,bin/debug,bin/release>) diff --git a/config.ini b/config.ini index c2cda5d..4202db5 100644 --- a/config.ini +++ b/config.ini @@ -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 diff --git a/module/hello/CMakeLists.txt b/module/hello/CMakeLists.txt new file mode 100644 index 0000000..071d2b9 --- /dev/null +++ b/module/hello/CMakeLists.txt @@ -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 + $<$:${ROOT_DIR}/3rdparty/HP-Socket/Lib/HPSocket_D.lib> + $<$:${ROOT_DIR}/3rdparty/mysql/lib/Debug/mysqlcppconn.lib> + $<$:${YLIB}/lib/leveldb_d.lib> + $<$:${YLIB}/lib/libzip_d.lib> + $<$:${YLIB}/lib/lua_d.lib> + $<$:${YLIB}/lib/sqlite3_d.lib> + $<$:${YLIB}/lib/ylib_d.lib> + $<$:${YLIB}/lib/zlib_d.lib> + $<$:${ROOT_DIR}/3rdparty/soci/lib/Debug/libsoci_core_4_1.lib> + $<$:${ROOT_DIR}/3rdparty/soci/lib/Debug/libsoci_empty_4_1.lib> + $<$:${ROOT_DIR}/3rdparty/soci/lib/Debug/libsoci_odbc_4_1.lib> + $<$:${ROOT_DIR}/3rdparty/soci/lib/Debug/soci_core_4_1.lib> + $<$:${ROOT_DIR}/3rdparty/soci/lib/Debug/soci_empty_4_1.lib> + $<$:${ROOT_DIR}/3rdparty/soci/lib/Debug/soci_odbc_4_1.lib> + $<$:${ROOT_DIR}/3rdparty/HP-Socket/Lib/HPSocket.lib> + $<$:${ROOT_DIR}/3rdparty/mysql/lib/Release/mysqlcppconn.lib> + $<$:${YLIB}/lib/leveldb.lib> + $<$:${YLIB}/lib/libzip.lib> + $<$:${YLIB}/lib/lua.lib> + $<$:${YLIB}/lib/sqlite3.lib> + $<$:${YLIB}/lib/ylib.lib> + $<$:${YLIB}/lib/zlib.lib> + $<$:${ROOT_DIR}/3rdparty/soci/lib/Release/libsoci_core_4_1.lib> + $<$:${ROOT_DIR}/3rdparty/soci/lib/Release/libsoci_empty_4_1.lib> + $<$:${ROOT_DIR}/3rdparty/soci/lib/Release/libsoci_odbc_4_1.lib> + $<$:${ROOT_DIR}/3rdparty/soci/lib/Release/soci_core_4_1.lib> + $<$:${ROOT_DIR}/3rdparty/soci/lib/Release/soci_empty_4_1.lib> + $<$:${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 $,bin/debug/module,bin/release/module>) \ No newline at end of file diff --git a/module/hello/hello.cpp b/module/hello/hello.cpp new file mode 100644 index 0000000..bdd93ea --- /dev/null +++ b/module/hello/hello.cpp @@ -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(sol2); + state->new_usertype("hello", + "name", &hello::name + ); + // 返回成功 + return 0; + } +} + + diff --git a/module/hello/hello.h b/module/hello/hello.h new file mode 100644 index 0000000..f22e62f --- /dev/null +++ b/module/hello/hello.h @@ -0,0 +1,9 @@ +#pragma once +#include +class hello +{ +public: + hello(); + ~hello(); + static std::string name(); +}; \ No newline at end of file diff --git a/module/module.h b/module/module.h new file mode 100644 index 0000000..7e480dc --- /dev/null +++ b/module/module.h @@ -0,0 +1,18 @@ +#if defined(_WIN32) || defined(_WIN64) +#define DLL_EXPORT __declspec(dllexport) +#else +#define DLL_EXPORT __attribute__((visibility("default"))) +#endif +extern "C" { + /// + /// 注册模块入口 + /// + /// + /// + /// + /// 0=成功 + /// 1=失败 + /// + DLL_EXPORT int fastweb_module_regist(void* sol2,void* lua); +} + \ No newline at end of file diff --git a/src/core/config.cpp b/src/core/config.cpp index ae4e8ad..cab91a1 100644 --- a/src/core/config.cpp +++ b/src/core/config.cpp @@ -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")); diff --git a/src/core/config.h b/src/core/config.h index 1179b3a..65f3f38 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -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; diff --git a/src/core/modulemanager.cpp b/src/core/modulemanager.cpp new file mode 100644 index 0000000..72fb268 --- /dev/null +++ b/src/core/modulemanager.cpp @@ -0,0 +1,161 @@ +#include "modulemanager.h" + +#include "util/file.h" + +#include "core/config.h" +#include "core/global.h" +#ifdef _WIN32 +#include +#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 module_manager::modules() +{ + std::vector 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; +} \ No newline at end of file diff --git a/src/core/modulemanager.h b/src/core/modulemanager.h new file mode 100644 index 0000000..4c44189 --- /dev/null +++ b/src/core/modulemanager.h @@ -0,0 +1,48 @@ +#pragma once +#include +#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; +}; + +/// +/// 模块管理器 +/// +class module_manager{ +public: + module_manager(); + ~module_manager(); + + void start(); + void close(); + /// + /// 创建虚拟机 + /// + /// + void load(sol::state* lua); +private: + /// + /// 加载核心库 + /// + /// + void load_core(sol::state* lua); + /// + /// 加载三方库 + /// + void load_3rdparty(sol::state* lua); + /// + /// 加载LUA库 + /// + /// + void load_lualib(sol::state* lua); + /// + /// 取模块文件列表 + /// + /// + std::vector modules(); +private: + std::map m_modules; +}; \ No newline at end of file diff --git a/src/core/statemanager.cpp b/src/core/statemanager.cpp index 66b9d01..9607877 100644 --- a/src/core/statemanager.cpp +++ b/src/core/statemanager.cpp @@ -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; } diff --git a/src/core/statemanager.h b/src/core/statemanager.h index 2f55d60..0630b85 100644 --- a/src/core/statemanager.h +++ b/src/core/statemanager.h @@ -11,7 +11,7 @@ #include "core/structs.h" #include "core/lualibdetecter.h" - +#include "core/modulemanager.h" /// /// LUA状态管理器 /// @@ -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; diff --git a/src/module/globalfuns.cpp b/src/module/globalfuns.cpp index 3621f03..da9dac4 100644 --- a/src/module/globalfuns.cpp +++ b/src/module/globalfuns.cpp @@ -4,12 +4,12 @@ #include "util/time.h" #include "core/global.h" static ylib::counter 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() { diff --git a/src/module/globalfuns.h b/src/module/globalfuns.h index b48eb1a..ade6275 100644 --- a/src/module/globalfuns.h +++ b/src/module/globalfuns.h @@ -5,7 +5,7 @@ /// namespace module { - void regist_globalfuns(sol::state& lua); + void regist_globalfuns(sol::state* lua); /// /// 生成软件唯一GUID /// diff --git a/src/module/http/httpclient.cpp b/src/module/http/httpclient.cpp index bb55294..592efbd 100644 --- a/src/module/http/httpclient.cpp +++ b/src/module/http/httpclient.cpp @@ -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("httpclient", + lua->new_usertype("httpclient", "new", sol::constructors(), "get", &module::httpclient::get, "post", &module::httpclient::post, diff --git a/src/module/http/httpclient.h b/src/module/http/httpclient.h index b92c646..902149e 100644 --- a/src/module/http/httpclient.h +++ b/src/module/http/httpclient.h @@ -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; }; diff --git a/src/module/http/request.cpp b/src/module/http/request.cpp index b13f14f..abbd3fd 100644 --- a/src/module/http/request.cpp +++ b/src/module/http/request.cpp @@ -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", + lua->new_usertype("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; } diff --git a/src/module/http/request.h b/src/module/http/request.h index 5b1bf20..1e2c860 100644 --- a/src/module/http/request.h +++ b/src/module/http/request.h @@ -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: diff --git a/src/module/http/response.cpp b/src/module/http/response.cpp index 43d0e65..cc6932e 100644 --- a/src/module/http/response.cpp +++ b/src/module/http/response.cpp @@ -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", + lua->new_usertype("module_response", "send_data", &module::response::send_data, "send", &module::response::send, "send_file", &module::response::send_file, diff --git a/src/module/http/response.h b/src/module/http/response.h index 3511924..bc022a7 100644 --- a/src/module/http/response.h +++ b/src/module/http/response.h @@ -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; }; diff --git a/src/module/http/session.cpp b/src/module/http/session.cpp index 6913ace..2f42252 100644 --- a/src/module/http/session.cpp +++ b/src/module/http/session.cpp @@ -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", + lua->new_usertype("module_session", "check", &module::session::check, "get", &module::session::get, "id", &module::session::id, diff --git a/src/module/http/session.h b/src/module/http/session.h index 468cad1..e09acc3 100644 --- a/src/module/http/session.h +++ b/src/module/http/session.h @@ -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; }; diff --git a/src/module/mssql.cpp b/src/module/mssql.cpp index e85f21f..716bb57 100644 --- a/src/module/mssql.cpp +++ b/src/module/mssql.cpp @@ -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("mssql", + lua->new_usertype("mssql", "new", sol::constructors(), "get_dob", &module::mssql::get_dob, "get_i32", &module::mssql::get_i32, diff --git a/src/module/mssql.h b/src/module/mssql.h index 4806046..2701ecd 100644 --- a/src/module/mssql.h +++ b/src/module/mssql.h @@ -34,7 +34,7 @@ namespace module /// 注册 /// /// - static void regist(sol::state& lua); + static void regist(sol::state* lua); private: std::shared_ptr m_session; //std::shared_ptr m_st; diff --git a/src/module/mysql.cpp b/src/module/mysql.cpp index 09e7295..5223201 100644 --- a/src/module/mysql.cpp +++ b/src/module/mysql.cpp @@ -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("mysql_builder_select", + lua->new_usertype("mysql_builder_select", "new", sol::constructors(), "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("mysql_builder_update", + lua->new_usertype("mysql_builder_update", "new", sol::constructors(), "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("mysql_builder_insert", + lua->new_usertype("mysql_builder_insert", "new", sol::constructors(), "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("mysql_builder_delete", + lua->new_usertype("mysql_builder_delete", "new", sol::constructors(), "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("mysql_conn", + lua->new_usertype("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("mysql_pool", + lua->new_usertype("mysql_pool", "new", sol::constructors(), "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("mysql_result", + lua->new_usertype("mysql_result", "field_name", &module::mysql_result::field_name, "get", &module::mysql_result::get, "next", &module::mysql_result::next, diff --git a/src/module/mysql.h b/src/module/mysql.h index d5c5630..ac0a1e6 100644 --- a/src/module/mysql.h +++ b/src/module/mysql.h @@ -9,7 +9,7 @@ namespace module /// 注册 /// /// - void mysql_regist(sol::state& lua); + void mysql_regist(sol::state* lua); /// /// 结果集 /// @@ -61,7 +61,7 @@ namespace module /// 注册 /// /// - 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 query(); uint64 count(); - static void regist(sol::state& lua); + static void regist(sol::state* lua); private: std::shared_ptr 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 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 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 m_delete; };