add walkdir source

develop
Kinch 2023-09-19 22:30:26 +02:00
parent b9b9fc393c
commit 98565b175c
4 changed files with 21 additions and 8 deletions

View File

@ -2,6 +2,12 @@ local fs = require("filesystem")
local root = fs.directory(".") local root = fs.directory(".")
for entry in root do string.starts_with = function(self, str)
print(entry) return self:find('^' .. str) ~= nil
end
for entry in root do
if not entry.rel_path:starts_with("%.") then
print(entry.rel_path)
end
end end

View File

@ -1,6 +1,7 @@
use crate::driver_filesystem::filesystem_resource::FilesystemResourceLocation; use crate::driver_filesystem::filesystem_resource::FilesystemResourceLocation;
use crate::resource::{DynResource, DynResourceLocation, Resource, ResourceLocation}; use crate::resource::{DynResource, DynResourceLocation, Resource, ResourceLocation};
use crate::source::ResourceSource; use crate::source::ResourceSource;
use std::fs::rename;
use std::io::Sink; use std::io::Sink;
use std::path::PathBuf; use std::path::PathBuf;
use walkdir::WalkDir; use walkdir::WalkDir;
@ -31,7 +32,7 @@ impl Iterator for DirectorySource {
self.iter self.iter
.next() .next()
.map(|entry| entry.unwrap()) .map(|entry| entry.unwrap())
.map(|entry| entry.path().to_path_buf()) .map(|entry| entry.path().strip_prefix("./").unwrap().to_path_buf())
.map(|entry| { .map(|entry| {
let loc = FilesystemResourceLocation::from(entry); let loc = FilesystemResourceLocation::from(entry);
Box::new(loc) as Box<dyn ResourceLocation> Box::new(loc) as Box<dyn ResourceLocation>

View File

@ -3,9 +3,3 @@ use mlua::{MetaMethod, UserData, UserDataFields, UserDataMethods};
mod resource_bindings; mod resource_bindings;
mod source_bindings; mod source_bindings;
impl UserData for DynResourceLocation {
fn add_methods<'lua, M: UserDataMethods<'lua, Self>>(methods: &mut M) {
methods.add_meta_method_mut(MetaMethod::ToString, |lua, this, _: ()| Ok(this.location()));
}
}

View File

@ -0,0 +1,12 @@
use crate::resource::DynResourceLocation;
use mlua::{MetaMethod, UserData, UserDataFields, UserDataMethods};
impl UserData for DynResourceLocation {
fn add_fields<'lua, F: UserDataFields<'lua, Self>>(fields: &mut F) {
fields.add_field_method_get("rel_path", |lua, this| Ok(this.location()))
}
fn add_methods<'lua, M: UserDataMethods<'lua, Self>>(methods: &mut M) {
methods.add_meta_method_mut(MetaMethod::ToString, |lua, this, _: ()| Ok(this.location()));
}
}