diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..ef3c061 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,84 @@ +cmake_minimum_required(VERSION 3.5) + +set(MODULE_NAME "captcha") +# 设置项目名为当前目录名 +project(${MODULE_NAME}) + +# 搜索源文件和头文件 +file(GLOB_RECURSE SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/*.cpp") +file(GLOB_RECURSE HEADER_FILES + "${PROJECT_SOURCE_DIR}/src/*.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() + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) +# 安装复制 +set(CMAKE_INSTALL_ALWAYS_COPY TRUE) + +set(YLIB ${CMAKE_INSTALL_PREFIX}/../ylib) +set(FASTWEB ${CMAKE_INSTALL_PREFIX}/../fastweb) + +# 包含路径 +if(MSVC) + include_directories( + ${YLIB}/include + ${FASTWEB}/include + ${FASTWEB}/include/lua + ) + add_definitions(/bigobj) +else() + include_directories( + /usr/local/include/ylib + /usr/local/include/fastweb + /opt/lua54/include + /usr/local/include) + add_definitions(-DfPIC) +endif() + +# 添加共享库 +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 + $<$:${FASTWEB}/bin/debug/3rdparty/lib/lua.lib> + $<$:${YLIB}/lib/ylib_d.lib> + $<$:${FASTWEB}/bin/release/3rdparty/lib/lua.lib> + $<$:${YLIB}/lib/ylib.lib> + ) +else() + target_link_libraries(${MODULE_NAME} + hpsocket + ylib + crypto + /opt/lua54/lib/liblua.a + pthread + ) + +endif() + + +install(TARGETS ${MODULE_NAME} DESTINATION $,${FASTWEB}/bin/debug/module/${MODULE_NAME},${FASTWEB}/bin/release/module/${MODULE_NAME}>) \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..381c62f --- /dev/null +++ b/build.sh @@ -0,0 +1,9 @@ +#!/bin/bash +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +cd "$SCRIPT_DIR" + +mkdir build +cd build +cmake .. +make +cp -f liblocalstorage.so ../target diff --git a/src/captcha.cpp b/src/captcha.cpp new file mode 100644 index 0000000..88982de --- /dev/null +++ b/src/captcha.cpp @@ -0,0 +1,50 @@ +#include "captcha.h" +#include "dll_interface.h" +#include +#include +#include "util/img.h" +#include "util/file.h" +extern "C" { +#ifdef _WIN32 + DLL_EXPORT +#endif + int fastweb_module_regist(void* sol2, void* lua) + { + sol::state* state = static_cast(sol2); + module::captcha::regist(state); + return 0; + } + + void *mimic_set_lang_list(void); +} + +module::captcha::captcha() +{ +} + +module::captcha::~captcha() +{ +} + +std::string module::captcha::make(int width,int height,int length,const std::string& filepath) +{ + ylib::buffer data; + std::string code; + data = ylib::util::img::make_code(width,height,length,code); + ylib::file::write(filepath,data); + return code; +} + +void module::captcha::regist(sol::state* lua) +{ + lua->new_usertype("fw_captcha", + "new", sol::constructors(), + "make", &module::captcha::make + ); +} + +void module::captcha::regist_global(const char* name, sol::state* lua) +{ + lua->registry()[name] = this; + (*lua)[name] = this; +} diff --git a/src/captcha.h b/src/captcha.h new file mode 100644 index 0000000..43e8a50 --- /dev/null +++ b/src/captcha.h @@ -0,0 +1,32 @@ +#pragma once +#include "basemodule.h" +namespace module +{ + /// + /// 验证码 + /// + class captcha : public module::base { + public: + captcha(); + ~captcha() override; + + + /// + /// 生成验证码 + /// + /// + /// + /// + /// + std::string make(int width,int height,int length,const std::string& filepath); + + + static void regist(sol::state* lua); + private: + // 通过 imodule 继承 + virtual void regist_global(const char* name, sol::state* lua); + virtual void delete_global() { delete this; } + virtual void self_free() {} + }; +} + diff --git a/target/captcha.lua b/target/captcha.lua new file mode 100644 index 0000000..d464fdf --- /dev/null +++ b/target/captcha.lua @@ -0,0 +1,34 @@ +-- tts.lua +local tts = {} +tts.__index = tts + +--[[ + 创建一个新的 fw_tts 对象 + @return 返回一个新的 fw_tts 对象 +]] +function tts.new(db) + local instance = setmetatable({}, tts) + if db == nil then + instance.module = fw_tts.new() + else + instance.module = db + end + + return instance +end + +--[[ + 说话 + @param voice 声音 + @param output 输出文件 + @param model 模型 + @param faster 速度 + @param pitch 音调 + @return 是否成功说话 +]] +function tts:speak(voice, output, model, faster, pitch) + return self.module:speak(voice, output, model, faster, pitch) +end + + +return tts