This commit is contained in:
2024-06-19 14:19:46 +08:00
parent 973fc45062
commit dc4c9fb6e3
3 changed files with 106 additions and 7 deletions

View File

@@ -35,11 +35,20 @@ set(YLIB ${CMAKE_INSTALL_PREFIX}/../ylib)
set(FASTWEB ${CMAKE_INSTALL_PREFIX}/../fastweb)
# 包含路径
include_directories(
${YLIB}/include
${FASTWEB}/include
${FASTWEB}/include/lua
)
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
/usr/local/include)
add_definitions(-DfPIC)
endif()
# 添加共享库
add_library(${MODULE_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES})
@@ -67,9 +76,9 @@ else()
hpsocket
ylib
crypto
lua5.3
mysqlcppconn
lua
pthread
leveldb
)
endif()

9
build.sh Executable file
View File

@@ -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

81
target/localstorage.lua Normal file
View File

@@ -0,0 +1,81 @@
-- localstorage.lua
local localstorage = {}
localstorage.__index = localstorage
--[[
创建一个新的 fw_localstorage 对象
@return 返回一个新的 fw_localstorage 对象
]]
function localstorage.new()
local instance = setmetatable({}, localstorage)
instance.module = fw_localstorage.new()
return instance
end
--[[
打开本地存储
@param dirpath 目录路径
@return 是否成功打开
]]
function localstorage:open(dirpath)
return self.module:open(dirpath)
end
--[[
关闭本地存储
]]
function localstorage:close()
self.module:close()
end
--[[
清空数据库
]]
function localstorage:clear()
self.module:clear()
end
--[[
写入数据
@param name 名称
@param value 值
@return 是否成功写入
]]
function localstorage:write(name, value)
return self.module:write(name, value)
end
--[[
读取数据
@param name 名称
]]
function localstorage:read(name)
return self.module:read(name)
end
--[[
删除数据
@param name 名称
@return 是否成功删除
]]
function localstorage:del(name)
return self.module:del(name)
end
--[[
检查数据是否存在
@param name 名称
@return 是否存在
]]
function localstorage:exist(name)
return self.module:exist(name)
end
function localstorage:self()
return self.module:self()
end
function localstorage:last_error()
return self.module:last_error()
end
return localstorage