sys.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // MIT License
  2. // Copyright(c) 2024 FastWeb - fwlua.com - nianhua
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files(the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions :
  9. // The above copyright notice and this permission notice shall be included in all
  10. // copies or substantial portions of the Software.
  11. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
  14. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. // SOFTWARE.
  18. // ## Additional Terms for Commercial Use
  19. // This software is licensed for personal, educational, and non - commercial use.
  20. // For commercial use or use within a company, organization, or institution, a
  21. // separate commercial license is required.To obtain a commercial license,
  22. // please contact
  23. // EMail:1585346868@qq.com
  24. // Mobile:17367918735
  25. // QQ:1585346868
  26. #include "sys.h"
  27. #include "util/system.h"
  28. std::string module::sys::current_dir()
  29. {
  30. return system::current_dir();
  31. }
  32. void module::sys::sleep_msec(uint32 msec)
  33. {
  34. system::sleep_msec(msec);
  35. }
  36. int64 module::sys::random(int64 min, int64 max)
  37. {
  38. return system::random(min, max);
  39. }
  40. std::string module::sys::current_filepath()
  41. {
  42. return system::current_filepath();
  43. }
  44. std::string module::sys::temp_path()
  45. {
  46. return system::temp_path();
  47. }
  48. std::string module::sys::desktop_path()
  49. {
  50. return system::desktop_path();
  51. }
  52. std::string module::sys::currentuser_path()
  53. {
  54. return system::currentuser_path();
  55. }
  56. sol::table module::sys::mac(sol::this_state s)
  57. {
  58. sol::state_view lua(s);
  59. sol::table result_table = lua.create_table();
  60. auto macs = system::mac();
  61. for(size_t i=0;i<macs.size();i++)
  62. result_table[i+1] = macs[i];
  63. return result_table;
  64. }
  65. void module::sys::regist(sol::state* lua)
  66. {
  67. lua->new_usertype<module::sys>("sys",
  68. "current_dir", &module::sys::current_dir,
  69. "sleep_msec", &module::sys::sleep_msec,
  70. "random", &module::sys::random,
  71. "current_filepath", &module::sys::current_filepath,
  72. "temp_path", &module::sys::temp_path,
  73. "desktop_path", &module::sys::desktop_path,
  74. "currentuser_path", &module::sys::currentuser_path,
  75. "mac", &module::sys::mac
  76. );
  77. }