xx 2 rokov pred
rodič
commit
31b2247a44
6 zmenil súbory, kde vykonal 216 pridanie a 0 odobranie
  1. 33 0
      .gitignore
  2. 78 0
      CMakeLists.txt
  3. 21 0
      LICENSE
  4. 3 0
      README.md
  5. 54 0
      src/localstorage.cpp
  6. 27 0
      src/localstorage.h

+ 33 - 0
.gitignore

@@ -0,0 +1,33 @@
+# Prerequisites
+*.d
+
+# Compiled Object files
+*.slo
+*.lo
+*.o
+*.obj
+
+# Precompiled Headers
+*.gch
+*.pch
+
+# Compiled Dynamic libraries
+*.so
+*.dylib
+*.dll
+
+# Fortran module files
+*.mod
+*.smod
+
+# Compiled Static libraries
+*.lai
+*.la
+*.a
+*.lib
+
+# Executables
+*.exe
+*.out
+*.app
+/build

+ 78 - 0
CMakeLists.txt

@@ -0,0 +1,78 @@
+cmake_minimum_required(VERSION 3.5)
+
+set(MODULE_NAME "localstorage")
+# 设置项目名为当前目录名
+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)
+
+# 包含路径
+include_directories(
+	${YLIB}/include
+	${FASTWEB}/include
+	${FASTWEB}/include/lua
+)
+
+# 添加共享库
+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:Debug>:${YLIB}/lib/leveldb_d.lib>
+
+			$<$<CONFIG:Release>:${FASTWEB}/bin/release/3rdparty/lib/lua.lib>
+			$<$<CONFIG:Release>:${YLIB}/lib/ylib.lib>
+			$<$<CONFIG:Release>:${YLIB}/lib/leveldb.lib>
+	)
+else()
+	target_link_libraries(${MODULE_NAME} 
+			hpsocket
+			ylib
+			crypto
+			lua5.3
+			mysqlcppconn
+			pthread
+	)
+
+endif()
+
+
+install(TARGETS ${MODULE_NAME} DESTINATION $<IF:$<CONFIG:Debug>,${FASTWEB}/bin/debug/module/${MODULE_NAME},${FASTWEB}/bin/release/module/${MODULE_NAME}>)

+ 21 - 0
LICENSE

@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2024 nianhua
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, 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.

+ 3 - 0
README.md

@@ -1,2 +1,5 @@
 # module-localstorage
+
 FastWeb - 本地缓存模块
+
+文档:<a href="http://fw.newobj.org/doc/module/database/">点击访问</a>

+ 54 - 0
src/localstorage.cpp

@@ -0,0 +1,54 @@
+#include "localstorage.h"
+#include "util/localstorage.h"
+#include "dll_interface.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::local_storage::regist(state);
+        return 0;
+    }
+}
+
+module::local_storage::local_storage()
+{
+}
+
+module::local_storage::~local_storage()
+{
+    ::ylib::local_storage::close();
+}
+
+sol::optional<std::string> module::local_storage::readex(const std::string& name)
+{
+    std::string value;
+    if (this->read(name, value) == false)
+        return sol::nullopt;
+    return value;
+}
+
+void module::local_storage::regist(sol::state* lua)
+{
+    lua->new_usertype<module::local_storage>("local_storage",
+        "new", sol::constructors<module::local_storage()>(),
+        "clear", &module::local_storage::clear,
+        "close", &module::local_storage::close,
+        "del", &module::local_storage::del,
+        "exist", &module::local_storage::exist,
+        "open", &module::local_storage::open,
+        "read", &module::local_storage::readex,
+        "write", &module::local_storage::write,
+        "self", &module::local_storage::self,
+        "last_error", &module::local_storage::last_error
+    );
+}
+
+void module::local_storage::regist_global(const std::string& name, sol::state* lua)
+{
+    lua->registry()[name] = this;
+    (*lua)[name] = this;
+}

+ 27 - 0
src/localstorage.h

@@ -0,0 +1,27 @@
+#pragma once
+#include "util/localstorage.h"
+#include "basemodule.h"
+namespace module
+{
+	/// <summary>
+	/// 本地缓存(leveldb)
+	/// </summary>
+	class local_storage : public ylib::local_storage,public module::base {
+	public:
+		local_storage();
+		~local_storage() override;
+		/// <summary>
+		/// 取数据
+		/// </summary>
+		/// <param name="name"></param>
+		/// <returns></returns>
+		sol::optional<std::string> readex(const std::string& name);
+
+		static void regist(sol::state* lua);
+	private:
+		// 通过 imodule 继承
+		virtual void regist_global(const std::string& name, sol::state* lua);
+		virtual void delete_global() { delete this; }
+	};
+}
+