xx hace 2 años
padre
commit
f46246e7d7
Se han modificado 4 ficheros con 112 adiciones y 3 borrados
  1. 53 2
      src/module/file.cpp
  2. 10 0
      src/module/file.h
  3. 41 1
      src/module/sys.cpp
  4. 8 0
      src/module/sys.h

+ 53 - 2
src/module/file.cpp

@@ -25,15 +25,66 @@ bool module::file::create_dir(const std::string& dirpath)
 {
     return ylib::file::create_dir(dirpath,true);
 }
+sol::object module::file::read(const std::string& filepath, sol::this_state s)
+{
+    sol::object result;
+    ylib::buffer data;
+    if (ylib::file::read(filepath, data) == false)
+        result = sol::make_object(s,data.to_string());
+    else
+        result = sol::make_object(s, sol::nil);
+    return result;
+}
+bool module::file::write(const std::string& filepath, const std::string& data)
+{
+    return ylib::file::write(filepath, data);
+}
+bool module::file::remove(const std::string& filepath)
+{
+    return ylib::file::remove(filepath);
+}
+bool module::file::remove_dir(const std::string& dirpath, bool recycle)
+{
+    return ylib::file::remove_dir(dirpath,recycle);
+}
+bool module::file::exist(const std::string& filepath)
+{
+    return ylib::file::exist(filepath);
+}
+bool module::file::exist_dir(const std::string& dirpath)
+{
+    return ylib::file::exist_dir(dirpath);
+}
+int64 module::file::size(const std::string& filepath)
+{
+    return ylib::file::size(filepath);
+}
+bool module::file::copy(const std::string& src, const std::string& dst)
+{
+    return ylib::file::copy(src,dst);
+}
+timestamp module::file::last_write_time(const std::string& filepath)
+{
+    return ylib::file::last_write_time(filepath);
+}
 void module::file::regist(sol::state* lua)
 {
     (*lua)["IS_FILE"] = (int)ylib::FileType::IS_FILE;
     (*lua)["IS_DIRECTORY"] = (int)ylib::FileType::IS_DIRECTORY;
 
 
-    lua->new_usertype<module::file>("file",
+    lua->new_usertype<module::file>("fs",
         "list", &module::file::list,
         "copy_dir", &module::file::copy_dir,
-        "create_dir", &module::file::create_dir
+        "create_dir", &module::file::create_dir,
+        "read",module::file::read,
+        "write",module::file::write,
+        "remove",module::file::remove,
+        "remove_dir",module::file::remove_dir,
+        "exist",module::file::exist,
+        "exist_dir",module::file::exist_dir,
+        "size",module::file::size,
+        "copy",module::file::copy,
+        "last_write_time",module::file::last_write_time
     );
 }

+ 10 - 0
src/module/file.h

@@ -12,6 +12,16 @@ namespace module
 		static sol::table list(const std::string& dirpath,const std::string& regex,sol::this_state s);
 		static void copy_dir(const std::string& src_dir,const std::string& dst_dir);
 		static bool create_dir(const std::string& dirpath);
+		static sol::object read(const std::string& filepath,sol::this_state s);
+		static bool write(const std::string& filepath,const std::string& data);
+		static bool remove(const std::string& filepath);
+		static bool remove_dir(const std::string& dirpath, bool recycle);
+		static bool exist(const std::string& filepath);
+		static bool exist_dir(const std::string& dirpath);
+		static int64 size(const std::string& filepath);
+		static bool copy(const std::string& src, const std::string& dst);
+		static timestamp last_write_time(const std::string& filepath);
+
 		static void regist(sol::state* lua);
 	};
 

+ 41 - 1
src/module/sys.cpp

@@ -4,9 +4,49 @@ std::string module::sys::current_dir()
 {
     return system::current_dir();
 }
+void module::sys::sleep_msec(uint32 msec)
+{
+    system::sleep_msec(msec);
+}
+int64 module::sys::random(int64 min, int64 max)
+{
+    return system::random(min, max);
+}
+std::string module::sys::current_filepath()
+{
+    return system::current_filepath();
+}
+std::string module::sys::temp_path()
+{
+    return system::temp_path();
+}
+std::string module::sys::desktop_path()
+{
+    return system::desktop_path();
+}
+std::string module::sys::currentuser_path()
+{
+    return system::currentuser_path();
+}
+sol::table module::sys::mac(sol::this_state s)
+{
+    sol::state_view lua(s);
+    sol::table result_table = lua.create_table();
+    auto macs = system::mac();
+    for(size_t i=0;i<macs.size();i++)
+        result_table[i+1] = macs[i];
+    return result_table;
+}
 void module::sys::regist(sol::state* lua)
 {
     lua->new_usertype<module::sys>("sys",
-        "current_dir", &module::sys::current_dir
+        "current_dir", &module::sys::current_dir,
+        "sleep_msec", &module::sys::sleep_msec,
+        "random", &module::sys::random,
+        "current_filepath", &module::sys::current_filepath,
+        "temp_path", &module::sys::temp_path,
+        "desktop_path", &module::sys::desktop_path,
+        "currentuser_path", &module::sys::currentuser_path,
+        "mac", &module::sys::mac,
     );
 }

+ 8 - 0
src/module/sys.h

@@ -10,6 +10,14 @@ namespace module
 	class sys:public module::imodule {
 	public:
 		static std::string current_dir();
+		static void sleep_msec(uint32 msec);
+		static int64 random(int64 min, int64 max);
+		static std::string current_filepath();
+		static std::string temp_path();
+		static std::string desktop_path();
+		static std::string currentuser_path();
+		static sol::table mac(sol::this_state s);
+
 		static void regist(sol::state* lua);
 	};