Mercurial > touhou
view python/src/lib.rs @ 776:94033091458b
formats: Update to ${concat(…)} to build on current nightly
${concat(…)} replaces the removed concat_idents!() macro, but doesn’t support
being used in nested repetitions for now. We can remove the gen_match!() macro
once this is supported again.
| author | Link Mauve <linkmauve@linkmauve.fr> |
|---|---|
| date | Tue, 14 Oct 2025 12:41:29 +0000 |
| parents | 28d8b892fd06 |
| children | 816e1f01d650 |
line wrap: on
line source
use pyo3::prelude::*; use pyo3::types::PyBytes; use touhou_formats::th06::pbg3; use std::fs::File; use std::io::BufReader; #[cfg(feature = "glide")] mod glide; #[pyclass] struct PBG3 { inner: pbg3::PBG3<BufReader<File>>, } #[pymethods] impl PBG3 { #[staticmethod] fn from_filename(filename: &str) -> PyResult<PBG3> { let inner = pbg3::from_path_buffered(filename)?; Ok(PBG3 { inner }) } #[getter] fn file_list(&self) -> Vec<String> { self.inner.list_files().cloned().collect() } fn list_files(&self) -> Vec<String> { self.inner.list_files().cloned().collect() } fn get_file(&mut self, py: Python, name: &str) -> Py<PyAny> { let data = self.inner.get_file(name, true).unwrap(); PyBytes::new(py, &data).into() } } #[pymodule] mod libtouhou { #[pymodule_export] use super::PBG3; #[cfg(feature = "glide")] #[pymodule_export] use super::glide::module; }
