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. // QQ:1585346868
  25. #include "sys.h"
  26. #include "util/system.h"
  27. std::string module::sys::current_dir()
  28. {
  29. return system::current_dir();
  30. }
  31. void module::sys::sleep_msec(uint32 msec)
  32. {
  33. system::sleep_msec(msec);
  34. }
  35. int64 module::sys::random(int64 min, int64 max)
  36. {
  37. return system::random(min, max);
  38. }
  39. std::string module::sys::current_filepath()
  40. {
  41. return system::current_filepath();
  42. }
  43. std::string module::sys::temp_path()
  44. {
  45. return system::temp_path();
  46. }
  47. std::string module::sys::desktop_path()
  48. {
  49. return system::desktop_path();
  50. }
  51. std::string module::sys::currentuser_path()
  52. {
  53. return system::currentuser_path();
  54. }
  55. sol::table module::sys::mac(sol::this_state s)
  56. {
  57. sol::state_view lua(s);
  58. sol::table result_table = lua.create_table();
  59. auto macs = system::mac();
  60. for(size_t i=0;i<macs.size();i++)
  61. result_table[i+1] = macs[i];
  62. return result_table;
  63. }
  64. void module::sys::regist(sol::state* lua)
  65. {
  66. lua->new_usertype<module::sys>("sys",
  67. "current_dir", &module::sys::current_dir,
  68. "sleep_msec", &module::sys::sleep_msec,
  69. "random", &module::sys::random,
  70. "current_filepath", &module::sys::current_filepath,
  71. "temp_path", &module::sys::temp_path,
  72. "desktop_path", &module::sys::desktop_path,
  73. "currentuser_path", &module::sys::currentuser_path,
  74. "mac", &module::sys::mac
  75. );
  76. }