diff --git a/src/shell/plugins/library_iter/mod.rs b/src/shell/plugins/library_iter/mod.rs index f09ab7d394d5c9cab5d0e3b199870bd87fc2d1a6..a5d9420ea86b441d23d3a66f3855a3c5b5e8e41c 100644 --- a/src/shell/plugins/library_iter/mod.rs +++ b/src/shell/plugins/library_iter/mod.rs @@ -1,48 +1,9 @@ -use libloading::Library; -use std::fs::ReadDir; -use types::Identifier; - -/// Grabs all `Library` entries found within a given directory -pub struct LibraryIterator { - directory: ReadDir, -} - -impl LibraryIterator { - pub fn new(directory: ReadDir) -> LibraryIterator { LibraryIterator { directory } } -} - -impl Iterator for LibraryIterator { - // The `Identifier` is the name of the namespace for which values may be pulled. - // The `Library` is a handle to dynamic library loaded into memory. - type Item = (Identifier, Library); - - fn next(&mut self) -> Option<(Identifier, Library)> { - while let Some(entry) = self.directory.next() { - let entry = if let Ok(entry) = entry { entry } else { continue }; - let path = entry.path(); - // An entry is a library if it is a file with a 'so' extension. - if path.is_file() && path.extension().map_or(false, |ext| ext == "so") { - // The identifier will be the file name of that file, without the extension. - let identifier = match path.file_stem().unwrap().to_str() { - Some(filename) => Identifier::from(filename), - None => { - eprintln!("ion: namespace plugin has invalid filename"); - continue; - } - }; - - // This will attempt to load the library into memory. - match Library::new(path.as_os_str()) { - Ok(library) => return Some((identifier, library)), - Err(why) => { - eprintln!("ion: failed to load library: {:?}, {:?}", path, why); - continue; - } - } - } else { - continue; - } - } - None - } -} +#[cfg(target_os = "redox")] +mod redox; +#[cfg(target_os = "redox")] +pub use self::redox::*; + +#[cfg(all(unix, not(target_os = "redox")))] +mod unix; +#[cfg(all(unix, not(target_os = "redox")))] +pub use self::unix::*; diff --git a/src/shell/plugins/library_iter/redox.rs b/src/shell/plugins/library_iter/redox.rs new file mode 100644 index 0000000000000000000000000000000000000000..c8cb256074d78ed76aa41684ed1d8055c4746c2d --- /dev/null +++ b/src/shell/plugins/library_iter/redox.rs @@ -0,0 +1,23 @@ +use std::fs::ReadDir; +use types::Identifier; + +pub struct Library; + +/// Grabs all `Library` entries found within a given directory +pub struct LibraryIterator { + directory: ReadDir, +} + +impl LibraryIterator { + pub fn new(directory: ReadDir) -> LibraryIterator { LibraryIterator { directory } } +} + +impl Iterator for LibraryIterator { + // The `Identifier` is the name of the namespace for which values may be pulled. + // The `Library` is a handle to dynamic library loaded into memory. + type Item = (Identifier, Library); + + fn next(&mut self) -> Option<(Identifier, Library)> { + None + } +} diff --git a/src/shell/plugins/library_iter/unix.rs b/src/shell/plugins/library_iter/unix.rs new file mode 100644 index 0000000000000000000000000000000000000000..f09ab7d394d5c9cab5d0e3b199870bd87fc2d1a6 --- /dev/null +++ b/src/shell/plugins/library_iter/unix.rs @@ -0,0 +1,48 @@ +use libloading::Library; +use std::fs::ReadDir; +use types::Identifier; + +/// Grabs all `Library` entries found within a given directory +pub struct LibraryIterator { + directory: ReadDir, +} + +impl LibraryIterator { + pub fn new(directory: ReadDir) -> LibraryIterator { LibraryIterator { directory } } +} + +impl Iterator for LibraryIterator { + // The `Identifier` is the name of the namespace for which values may be pulled. + // The `Library` is a handle to dynamic library loaded into memory. + type Item = (Identifier, Library); + + fn next(&mut self) -> Option<(Identifier, Library)> { + while let Some(entry) = self.directory.next() { + let entry = if let Ok(entry) = entry { entry } else { continue }; + let path = entry.path(); + // An entry is a library if it is a file with a 'so' extension. + if path.is_file() && path.extension().map_or(false, |ext| ext == "so") { + // The identifier will be the file name of that file, without the extension. + let identifier = match path.file_stem().unwrap().to_str() { + Some(filename) => Identifier::from(filename), + None => { + eprintln!("ion: namespace plugin has invalid filename"); + continue; + } + }; + + // This will attempt to load the library into memory. + match Library::new(path.as_os_str()) { + Ok(library) => return Some((identifier, library)), + Err(why) => { + eprintln!("ion: failed to load library: {:?}, {:?}", path, why); + continue; + } + } + } else { + continue; + } + } + None + } +} diff --git a/src/shell/plugins/methods/redox.rs b/src/shell/plugins/methods/redox.rs index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..80d8e5b320c3e18ac2061fde838cfbfca2fd43ec 100644 --- a/src/shell/plugins/methods/redox.rs +++ b/src/shell/plugins/methods/redox.rs @@ -0,0 +1,35 @@ +use super::super::{LibraryIterator, config_dir, StringError}; +use fnv::FnvHashMap; +use std::ffi::CString; +use std::fs::read_dir; +use std::mem::forget; +use std::ptr; +use std::slice; +use std::str; +use types::Identifier; + +pub enum MethodArguments { + StringArg(String, Vec<String>), + Array(Vec<String>, Vec<String>), + NoArgs +} + +pub struct StringMethodPlugins; + +impl StringMethodPlugins { + pub fn new() -> StringMethodPlugins { + StringMethodPlugins + } + + pub fn execute(&self, function: &str, arguments: MethodArguments) -> Result<Option<String>, StringError> { + Ok(None) + } +} + +/// Collects all dynamically-loaded namespaces and their associated symbols all at once. +/// +/// This function is meant to be called with `lazy_static` to ensure that there isn't a +/// cost to collecting all this information when the shell never uses it in the first place! +pub fn collect() -> StringMethodPlugins { + StringMethodPlugins::new() +} diff --git a/src/shell/plugins/mod.rs b/src/shell/plugins/mod.rs index 4886f93c23bfc24566df12c86df6513c803eab76..eb73623a48966c192f486ea1545b8e86fedc8edf 100644 --- a/src/shell/plugins/mod.rs +++ b/src/shell/plugins/mod.rs @@ -1,11 +1,9 @@ pub mod methods; pub mod namespaces; -#[cfg(all(unix, not(target_os = "redox")))] mod library_iter; -#[cfg(all(unix, not(target_os = "redox")))] -pub use self::library_iter::*; mod string; +pub use self::library_iter::*; pub use self::string::StringError; use app_dirs::{AppDataType, AppInfo, app_root}; diff --git a/src/shell/plugins/namespaces/redox.rs b/src/shell/plugins/namespaces/redox.rs index 2a3c11e26716eee9008d20fbf7059b7528dfe32d..dd492dd5c2a4a2d524eee6c5d35d032a6ffe19d7 100644 --- a/src/shell/plugins/namespaces/redox.rs +++ b/src/shell/plugins/namespaces/redox.rs @@ -6,9 +6,9 @@ use super::super::StringError; pub struct StringNamespace; impl StringNamespace { - pub fn new() -> Result<StringNamespace, NamespaceError> { Ok(StringNamespace) } + pub fn new() -> Result<StringNamespace, StringError> { Ok(StringNamespace) } - pub fn execute(&self, function: Identifier) -> Result<Option<String>, NamespaceError> { Ok(None) } + pub fn execute(&self, function: Identifier) -> Result<Option<String>, StringError> { Ok(None) } } pub fn collect() -> FnvHashMap<Identifier, StringNamespace> {