Provides filesystem access for the Rhai scripting language.

Overview

About rhai-fs

License crates.io crates.io API Docs

This crate provides filesystem access for the Rhai scripting language.

Usage

Cargo.toml

[dependencies]
rhai-fs = "0.1.2"

Rhai script

// Create a file or open and truncate it already created
let file = open_file("example.txt");
let blob_buf = file.read_blob();
print("file contents: " + blob_buf);
blob_buf.write_utf8(0..=0x20, "foobar");
print("new file contents: " + blob_buf);
file.write(blob_buf);

Rust source

use rhai::{Engine, EvalAltResult};
use rhai::packages::Package;
use rhai_fs::FilesystemPackage;

fn main() -> Result<(), Box<EvalAltResult>> {
    // Create Rhai scripting engine
    let mut engine = Engine::new();

    // Create filesystem package and add the package into the engine
    let package = FilesystemPackage::new();
    package.register_into_engine(&mut engine);

    // Print the contents of the file `Cargo.toml`.
    let contents = engine.eval::<String>(r#"open_file("Cargo.toml", "r").read_string()"#)?;
    println!("{}", contents);

    Ok(())
}

Features

Feature Default Description
no_index disabled Enables support for no_index builds of Rhai
metadata disabled Enables support for generating package documentation
Comments
  • Provide sandboxing example

    Provide sandboxing example

    For security and compatibility, it would be a good idea to provide a read-to-go example on how to show how to sandbox rhai-fs.

    This can be done quite seamlessly with overloading the function path(string), as every operation must go through this singular function to create a PathBuf, unless of course you push a rust defined PathBuf to the scope.

    good first issue 
    opened by dankope 7
  • Some minor issues

    Some minor issues

    • for blobs there is max_array_size similar to strings
    • Is it a good idea to read the file and then truncate to max? The file might be deliberately made huge si you crash the engine. Maybe use a read call with length is better ...
    • necessary to introduce the PathBuf type? Or just use string paths... With helpers to manipulate segments
    • max_string_len etc. may be zero to indicate unlimited; you'd need to use >=0
    • The limits are probably not available under unchecked so you may need an additional feature gate... Or maybe I'll make the get calls available all the time but return zero under unchecked EDIT: I've made the max_... calls available even under unchecked so you don't have to include yet another feature flag.
    opened by schungx 3
  • Static namespace support

    Static namespace support

    Unfortunately, while testing I omitted support for static namespace package registration.

    let package = FilesystemPackage::new();
    package.register_into_engine_as(&mut engine, "fs");
    

    then in a rhai script:

    let file = fs::open_file(fs::path("hello.txt")); 
    print(file.read_string());
    

    You will receive the following error: ErrorFunctionNotFound("read_string (SharedFile)", 3:16). This error is due to the method not being added globally, this is a really simple fix.

    bug good first issue 
    opened by dankope 1
  • Blob API revisal

    Blob API revisal

    Currently the Blob API for reading and writing clones on each read and write, this is unneeded and should be fixable by instead of taking a mutable reference to SharedFile, take a mutable reference to a Blob, SharedFile is already behind a reference so cloning that is fine.

    The new API could look like so: file.read_blob() (Kept for convenience) blob.read_from_file(file) blob.read_from_file(file, len) blob.write_to_file(file)

    enhancement 
    opened by dankope 1
  • Use Rust standard doc sections in comments

    Use Rust standard doc sections in comments

    I suggest we standardize on doc-comment sections similar to Rust's to make it easier for other tools to parse the docs in the future.

    /// Main paragraph of comments.
    ///
    /// Secondary info...  multiple lines and/or paragraphs.
    ///
    /// # Parameters
    ///
    /// ... docs on parameters, if needed
    /// ... for simple parameters, the separate section may be omitted
    ///
    /// # Returns
    ///
    /// ... docs on value returned, if any
    /// ... for simple values, the separate section may be omitted
    ///
    /// # Errors
    ///
    /// ... potential errors (if any)
    /// ... always a good idea to make error info explicit
    ///
    /// # Exceptions
    ///
    /// ...  potential exceptions (if any)
    /// ... always a good idea to make error info explicit
    ///
    /// # Example
    ///
    /// ... example code
    ///
    /// # See Also
    ///
    /// ... Rust std links etc. if any
    
    documentation 
    opened by schungx 1
  • Add std implementation links to docs

    Add std implementation links to docs

    It would be nice to have links to every rust std api used directly within the docs for the api.

    For example: https://github.com/rhaiscript/rhai-fs/blob/896ea06cd3480ddc420b7b833dd3b2eb57841300/src/path.rs#L14-L22

    Becomes:

    /// Returns path to current working directory. 
    /// 
    /// Throws an exception when: 
    /// - The current working directory does not exist. 
    /// - The process lacks the permissions to access the current working directory. 
    ///
    /// See [std::env::current_dir](https://doc.rust-lang.org/std/env/fn.current_dir.html) for more information.
    #[rhai_fn(return_raw)] 
    pub fn cwd() -> Result<std::path::PathBuf, Box<EvalAltResult>> { 
       std::env::current_dir().map_err(|e| e.to_string().into()) 
    } 
    
    documentation good first issue 
    opened by dankope 1
Owner
Rhai - Embedded scripting language and engine for Rust
A small, fast, easy-to-use scripting language and evaluation engine that integrates tightly with Rust. Builds for most common targets including no-std and WASM.
Rhai - Embedded scripting language and engine for Rust
Scientific computing for Rhai.

About rhai-sci This crate provides some basic scientific computing utilities for the Rhai scripting language, inspired by languages like MATLAB, Octav

Rhai - Embedded scripting language and engine for Rust 5 Dec 5, 2022
FUSE filesystem that provides FizzBuzz.txt(8 Exabyte)

FizzBuzzFS root@8a2db3fc6292:/# cd /mnt/FizzBuzz/ root@8a2db3fc6292:/mnt/FizzBuzz# ls -l total 9007199254740992 -rw-r--r-- 1 501 dialout 9223372036854

todesking 8 Oct 1, 2023
A simple, human-friendly, embeddable scripting language

Mica Language reference · Rust API A simple, human-friendly scripting language, developed one feature at a time. Human-friendly syntax inspired by Rub

Mica programming language 32 Dec 30, 2022
The GameLisp scripting language

GameLisp GameLisp is a scripting language for Rust game development. To get started, take a look at the homepage. Please note that GameLisp currently

Fleabit 348 Nov 29, 2022
Open-source compiler for the Papyrus scripting language of Bethesda games.

Open Papyrus Compiler This project is still WORK IN PROGRESS. If you have any feature requests, head over to the Issues tab and describe your needs. Y

erri120 22 Dec 5, 2022
A safe, fast, lightweight embeddable scripting language written in Rust.

Bud (budlang) A safe, fast, lightweight embeddable scripting language written in Rust. WARNING: This crate is not anywhere near being ready to publish

Khonsu Labs 13 Dec 27, 2022
YAL is Yet Another scripting Language(but worse)

YAL - Yet Another Language YAL is yet another scripting language(but worse). Syntax Basic syntax fun main() { print("Hello, World!"); } Fibonacci

MD Gaziur Rahman Noor 16 Nov 14, 2022
bevy_scriptum is a a plugin for Bevy that allows you to write some of your game logic in a scripting language

bevy_scriptum is a a plugin for Bevy that allows you to write some of your game logic in a scripting language. Currently, only Rhai is supported, but more languages may be added in the future.

Jarosław Konik 7 Jun 24, 2023
fd is a program to find entries in your filesystem. It is a simple, fast and user-friendly alternative to find

fd is a program to find entries in your filesystem. It is a simple, fast and user-friendly alternative to find. While it does not aim to support all of find's powerful functionality, it provides sensible (opinionated) defaults for a majority of use cases.

David Peter 25.9k Jan 9, 2023
This utility traverses through your filesystem looking for open-source dependencies that are seeking donations by parsing README.md and FUNDING.yml files

This utility traverses through your filesystem looking for open-source dependencies that are seeking donations by parsing README.md and FUNDING.yml files

Mufeed VH 38 Dec 30, 2022
A slightly smart clipboard tool - leverage the filesystem to persist across machines after shutdown.

clipd A slightly smart clipboard using the filesystem under ~/.clipd to persist after shutdown. cowsay "clipd is great" | clipd copy clipd paste ____

null 5 Aug 9, 2022
Quickly find all blackhole directories with a huge amount of filesystem entries in a flat structure

findlargedir About Findlargedir is a tool specifically written to help quickly identify "black hole" directories on an any filesystem having more than

Dinko Korunic 24 Jan 1, 2023
Nimbus - A virtual, networked filesystem with strong upfront safety guarantees

The Nimbus Filesystem Nimbus is a virtual, networked filesystem that provides upfront safety guarantees to a user, intended for personal use. In parti

Max Fan 3 Jan 10, 2023
Async filesystem facade for Rust!

floppy-disk floppy disk is a WIP, async-only filesystem facade for Rust. What? Have you ever worked with std::fs? tokio::fs? Then you've probably real

amy null 8 Apr 2, 2023
A small in-memory filesystem using FUSE.

slabfs A small in-memory filesystem using FUSE. Running Simply run: RUST_LOG="slabfs=trace" cargo r -r -- <mountpoint> To suppress most log messages:

Carlos López 2 Jul 7, 2023
A filesystem driver that allows you to view your Blackboard course contents as if they were normal files and folders on your system!

BlackboardFS Blackboard: noun A website so bad that it might as well be a network drive. BlackboardFS is a filesystem driver that allows you to view y

null 22 Sep 4, 2023
API bindings, CLI client and FUSE filesystem for Wiki.js written in Rust.

wikijs-rs API bindings, CLI client and FUSE filesystem for Wiki.js written in Rust. What's inside? Library: Rust bindings to Wiki.js's entire GraphQL

Sandro-Alessio Gierens 4 Sep 19, 2023
A Rust synchronisation primitive for "Multiplexed Concurrent Single-Threaded Read" access

exit-left verb; 1. To exit or disappear in a quiet, non-dramatic fashion, making way for more interesting events. 2. (imperative) Leave the scene, and

Jonathan de Jong 0 Dec 5, 2021
sg = Steam Guard, access sg verification code locally.

Steam Guard CLI Access your Steam Guard token locally. Credit https://github.com/steevp/UpdogFarmer/blob/master/app/src/main/java/com/steevsapps/idled

Vanilla's Lab 7 Nov 10, 2022