35 lines
755 B
Rust
35 lines
755 B
Rust
//! The `lb:fs` module provides utilities for interacting with the file system asynchronously.
|
|
//!
|
|
//! # Exports
|
|
//!
|
|
//! See [`lb_libfs`] for items exported by this module.
|
|
use luaffi::{cdef, metatype};
|
|
use std::io;
|
|
use tokio::fs;
|
|
|
|
/// Items exported by the `lb:fs` module.
|
|
///
|
|
/// This module can be obtained by calling `require` in Lua.
|
|
///
|
|
/// ```lua
|
|
/// local fs = require("lb:fs");
|
|
/// ```
|
|
#[cdef]
|
|
pub struct lb_libfs;
|
|
|
|
#[metatype]
|
|
impl lb_libfs {
|
|
#[new]
|
|
extern "Lua-C" fn new() -> Self {
|
|
Self
|
|
}
|
|
|
|
pub async extern "Lua-C" fn read(&self, path: &str) -> io::Result<Vec<u8>> {
|
|
fs::read(path).await
|
|
}
|
|
|
|
pub extern "Lua-C" fn read_sync(&self, path: &str) -> io::Result<Vec<u8>> {
|
|
std::fs::read(path)
|
|
}
|
|
}
|