Add basic fs lib
This commit is contained in:
32
crates/lb/src/fs.rs
Normal file
32
crates/lb/src/fs.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
//! The `lb:fs` module provides utilities for interacting with the file system asynchronously.
|
||||
//!
|
||||
//! 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user