localstorage.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "localstorage.h"
  2. #include "util/localstorage.h"
  3. #include "dll_interface.h"
  4. extern "C" {
  5. #ifdef _WIN32
  6. DLL_EXPORT
  7. #endif
  8. int fastweb_module_regist(void* sol2, void* lua)
  9. {
  10. sol::state* state = static_cast<sol::state*>(sol2);
  11. module::local_storage::regist(state);
  12. return 0;
  13. }
  14. }
  15. module::local_storage::local_storage()
  16. {
  17. }
  18. module::local_storage::~local_storage()
  19. {
  20. ::ylib::local_storage::close();
  21. }
  22. sol::optional<std::string> module::local_storage::readex(const std::string& name)
  23. {
  24. std::string value;
  25. if (this->read(name, value) == false)
  26. return sol::nullopt;
  27. return value;
  28. }
  29. void module::local_storage::regist(sol::state* lua)
  30. {
  31. lua->new_usertype<module::local_storage>("local_storage",
  32. "new", sol::constructors<module::local_storage()>(),
  33. "clear", &module::local_storage::clear,
  34. "close", &module::local_storage::close,
  35. "del", &module::local_storage::del,
  36. "exist", &module::local_storage::exist,
  37. "open", &module::local_storage::open,
  38. "read", &module::local_storage::readex,
  39. "write", &module::local_storage::write,
  40. "self", &module::local_storage::self,
  41. "last_error", &module::local_storage::last_error
  42. );
  43. }
  44. void module::local_storage::regist_global(const char* name, sol::state* lua)
  45. {
  46. lua->registry()[name] = this;
  47. (*lua)[name] = this;
  48. }