@@ -162,30 +162,30 @@ fn path_constructor(_: &Lua, path: String) -> LuaResult<LuaFilePath> {
162162 Ok ( LuaFilePath :: new ( path) )
163163}
164164
165- fn status ( _: & Lua , path : String ) -> LuaResult < ( ) > {
165+ fn status ( _: & Lua , path : LuaFilePath ) -> LuaResult < ( ) > {
166166 let _ = path;
167167 // Implementation for status function
168168 Ok ( ( ) )
169169}
170170
171- fn exists ( _: & Lua , path : String ) -> LuaResult < bool > {
172- Ok ( std:: path:: Path :: new ( & path) . exists ( ) )
171+ fn exists ( _: & Lua , path : LuaFilePath ) -> LuaResult < bool > {
172+ Ok ( std:: path:: Path :: new ( & path. path ) . exists ( ) )
173173}
174174
175- fn is_directory ( _: & Lua , path : String ) -> LuaResult < bool > {
176- Ok ( std:: path:: Path :: new ( & path) . is_dir ( ) )
175+ fn is_directory ( _: & Lua , path : LuaFilePath ) -> LuaResult < bool > {
176+ Ok ( std:: path:: Path :: new ( & path. path ) . is_dir ( ) )
177177}
178178
179- fn is_regular_file ( _: & Lua , path : String ) -> LuaResult < bool > {
180- Ok ( std:: path:: Path :: new ( & path) . is_file ( ) )
179+ fn is_regular_file ( _: & Lua , path : LuaFilePath ) -> LuaResult < bool > {
180+ Ok ( std:: path:: Path :: new ( & path. path ) . is_file ( ) )
181181}
182182
183- fn file_size ( _: & Lua , path : String ) -> LuaResult < u64 > {
184- Ok ( std:: fs:: metadata ( & path) . map ( |m| m. len ( ) ) . unwrap_or ( 0 ) )
183+ fn file_size ( _: & Lua , path : LuaFilePath ) -> LuaResult < u64 > {
184+ Ok ( std:: fs:: metadata ( & path. path ) . map ( |m| m. len ( ) ) . unwrap_or ( 0 ) )
185185}
186186
187- fn create_directory ( _: & Lua , path : String ) -> LuaResult < ( ) > {
188- std:: fs:: create_dir ( & path) ?;
187+ fn create_directory ( _: & Lua , path : LuaFilePath ) -> LuaResult < ( ) > {
188+ std:: fs:: create_dir ( & path. path ) ?;
189189 Ok ( ( ) )
190190}
191191
@@ -354,7 +354,17 @@ pub fn bee_filesystem(lua: &Lua) -> LuaResult<Table> {
354354 "temp_directory_path" ,
355355 lua. create_function ( temp_directory_path) ?,
356356 ) ?;
357- // exports.set("pairs", lua.create_function(pairs_ctor)?)?;
357+ exports. set ( "pairs" , lua. create_function ( |lua, path : LuaFilePath | -> LuaResult < _ > {
358+ let table = lua. create_table ( ) ?;
359+ for entry in std:: fs:: read_dir ( & path. path ) ? {
360+ let entry = entry?;
361+ let path = entry. path ( ) ;
362+ let path = LuaFilePath :: new ( path. to_str ( ) . unwrap_or ( "" ) . to_string ( ) ) ;
363+ table. set ( path. clone ( ) , true ) ?;
364+ }
365+ let next = lua. globals ( ) . get :: < mlua:: Function > ( "next" ) . unwrap ( ) ;
366+ Ok ( ( next, table, mlua:: Nil ) )
367+ } ) ?) ?;
358368 // exports.set("pairs_r", lua.create_function(pairs_r_ctor)?)?;
359369
360370 Ok ( exports)
0 commit comments