mirror of
https://github.com/lune-org/lune.git
synced 2025-04-10 21:40:54 +01:00
feat: return buffers for fs too
This commit is contained in:
parent
ef4fe6e1eb
commit
8dbe5325ec
1 changed files with 4 additions and 15 deletions
|
@ -31,10 +31,10 @@ pub fn create(lua: &Lua) -> LuaResult<LuaTable> {
|
||||||
.build_readonly()
|
.build_readonly()
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fs_read_file(lua: &Lua, path: String) -> LuaResult<LuaString> {
|
async fn fs_read_file(lua: &Lua, path: String) -> LuaResult<LuaAnyUserData> {
|
||||||
let bytes = fs::read(&path).await.into_lua_err()?;
|
let bytes = fs::read(&path).await.into_lua_err()?;
|
||||||
|
|
||||||
lua.create_string(bytes)
|
lua.create_buffer(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fs_read_dir(_: &Lua, path: String) -> LuaResult<Vec<String>> {
|
async fn fs_read_dir(_: &Lua, path: String) -> LuaResult<Vec<String>> {
|
||||||
|
@ -66,19 +66,8 @@ async fn fs_read_dir(_: &Lua, path: String) -> LuaResult<Vec<String>> {
|
||||||
Ok(dir_strings_no_prefix)
|
Ok(dir_strings_no_prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fs_write_file(lua: &Lua, (path, contents): (String, LuaValue<'_>)) -> LuaResult<()> {
|
async fn fs_write_file(_: &Lua, (path, contents): (String, BString)) -> LuaResult<()> {
|
||||||
let contents_str = match contents {
|
fs::write(&path, contents.as_bytes()).await.into_lua_err()
|
||||||
LuaValue::String(str) => Ok(BString::from(str.to_str()?)),
|
|
||||||
LuaValue::UserData(inner) => lua.unpack::<BString>(LuaValue::UserData(inner)),
|
|
||||||
other => Err(LuaError::runtime(format!(
|
|
||||||
"Expected type string or buffer, got {}",
|
|
||||||
other.type_name()
|
|
||||||
))),
|
|
||||||
}?;
|
|
||||||
|
|
||||||
fs::write(&path, contents_str.as_bytes())
|
|
||||||
.await
|
|
||||||
.into_lua_err()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fs_write_dir(_: &Lua, path: String) -> LuaResult<()> {
|
async fn fs_write_dir(_: &Lua, path: String) -> LuaResult<()> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue