a158 1 месяц назад
Родитель
Сommit
26d3c8f02a
5 измененных файлов с 209 добавлено и 0 удалено
  1. 84 0
      CMakeLists.txt
  2. 9 0
      build.sh
  3. 50 0
      src/captcha.cpp
  4. 32 0
      src/captcha.h
  5. 34 0
      target/captcha.lua

+ 84 - 0
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
+			$<$<CONFIG:Debug>:${FASTWEB}/bin/debug/3rdparty/lib/lua.lib>
+			$<$<CONFIG:Debug>:${YLIB}/lib/ylib_d.lib>
+			$<$<CONFIG:Release>:${FASTWEB}/bin/release/3rdparty/lib/lua.lib>
+			$<$<CONFIG:Release>:${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 $<IF:$<CONFIG:Debug>,${FASTWEB}/bin/debug/module/${MODULE_NAME},${FASTWEB}/bin/release/module/${MODULE_NAME}>)

+ 9 - 0
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

+ 50 - 0
src/captcha.cpp

@@ -0,0 +1,50 @@
+#include "captcha.h"
+#include "dll_interface.h"
+#include <cstdio>
+#include <mimic.h>
+#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<sol::state*>(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<module::captcha>("fw_captcha",
+        "new", sol::constructors<module::captcha()>(),
+        "make", &module::captcha::make
+    );
+}
+
+void module::captcha::regist_global(const char* name, sol::state* lua)
+{
+    lua->registry()[name] = this;
+    (*lua)[name] = this;
+}

+ 32 - 0
src/captcha.h

@@ -0,0 +1,32 @@
+#pragma once
+#include "basemodule.h"
+namespace module
+{
+	/// <summary>
+	/// 验证码
+	/// </summary>
+	class captcha : public module::base {
+	public:
+		captcha();
+		~captcha() override;
+		
+
+		/// <summary>
+		/// 生成验证码
+		/// </summary>
+		/// <param name="width"></param>
+		/// <param name="height"></param>
+		/// <param name="length"></param>
+		/// <returns></returns>
+		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() {}
+	};
+}
+

+ 34 - 0
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