35 lines
733 B
Rust
35 lines
733 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 extern "Lua" fn read(&self, path: string) -> string {
|
|
self.__read(path)
|
|
}
|
|
|
|
async extern "Lua-C" fn __read(&self, path: &str) -> io::Result<Vec<u8>> {
|
|
fs::read(path).await
|
|
}
|
|
}
|