首次更新

This commit is contained in:
xx
2024-06-07 14:33:39 +08:00
parent ce628fcb68
commit 31b2247a44
6 changed files with 216 additions and 0 deletions

54
src/localstorage.cpp Normal file
View File

@@ -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
src/localstorage.h Normal file
View File

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