localstorage.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "localstorage.h"
  2. #include "util/localstorage.h"
  3. module::local_storage::local_storage()
  4. {
  5. }
  6. module::local_storage::~local_storage()
  7. {
  8. ::ylib::local_storage::close();
  9. }
  10. sol::optional<std::string> module::local_storage::readex(const std::string& name)
  11. {
  12. std::string value;
  13. if (this->read(name, value) == false)
  14. return sol::nullopt;
  15. return value;
  16. }
  17. void module::local_storage::regist(sol::state* lua)
  18. {
  19. lua->new_usertype<module::local_storage>("local_storage",
  20. "new", sol::constructors<module::local_storage()>(),
  21. "clear", &module::local_storage::clear,
  22. "close", &module::local_storage::close,
  23. "del", &module::local_storage::del,
  24. "exist", &module::local_storage::exist,
  25. "open", &module::local_storage::open,
  26. "read", &module::local_storage::readex,
  27. "write", &module::local_storage::write,
  28. "self", &module::local_storage::self,
  29. "last_error", &module::local_storage::last_error
  30. );
  31. }
  32. void module::local_storage::regist_global(const std::string& name, sol::state* lua)
  33. {
  34. lua->registry()[name] = this;
  35. (*lua)[name] = this;
  36. }