lua_assembler/formats/luac/
mod.rs1use crate::program::{LuaProgram, LuaVersion};
2use gaia_types::{
3 helpers::{open_file, Url},
4 GaiaError,
5};
6use std::{fmt::Debug, io::BufReader, path::Path};
7
8pub mod reader;
9pub mod view;
10pub mod writer;
11
12#[derive(Clone, Debug, PartialEq, Eq)]
13pub struct LuacReadConfig {
14 pub url: Option<Url>,
15 pub version: LuaVersion,
16 pub check_magic_head: bool,
17}
18
19#[derive(Copy, Clone, Debug, PartialEq, Eq)]
20pub struct LuacWriteConfig {}
21
22impl Default for LuacReadConfig {
23 fn default() -> Self {
24 Self { url: None, version: LuaVersion::Unknown, check_magic_head: true }
25 }
26}
27
28pub fn luac_read_path(path: &Path) -> Result<LuaProgram, GaiaError> {
29 let (file, url) = open_file(path)?;
30 let mut config = LuacReadConfig::default();
31 config.url = Some(url);
32 let reader = config.as_reader(BufReader::new(file));
33 let result = reader.finish();
34 result.result
35}
36
37pub fn read_luac_file(path: &Path) -> Result<LuaProgram, GaiaError> {
39 luac_read_path(path)
40}
41
42pub fn write_luac_file(_path: &Path, _program: &LuaProgram) -> Result<(), GaiaError> {
43 Err(GaiaError::custom_error("write_luac_file not implemented yet"))
45}