lua_assembler/formats/luac/
mod.rs

1use 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: false }
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 mut reader = config.as_reader(BufReader::new(file));
33    reader.read_to_end()?;
34    reader.view.to_program().result
35}