Skip to main content

lux_lib/lua_rockspec/build/
rust_mlua.rs

1use std::{collections::HashMap, path::PathBuf};
2
3use mlua::UserData;
4
5#[derive(Debug, PartialEq, Default, Clone)]
6pub struct RustMluaBuildSpec {
7    /// Keys are module names in the format normally used by the `require()` function.
8    /// values are the library names in the target directory (without the `lib` prefix).
9    pub modules: HashMap<String, PathBuf>,
10    /// Set if the cargo `target` directory is not in the source root.
11    pub target_path: PathBuf,
12    /// If set to `false` pass `--no-default-features` to cargo.
13    pub default_features: bool,
14    /// Pass additional features
15    pub features: Vec<String>,
16    /// Additional flags to be passed in the cargo invocation.
17    pub cargo_extra_args: Vec<String>,
18    /// Copy additional files to the `lua` directory.
19    /// Keys are the sources, values the destinations (relative to the `lua` directory).
20    pub include: HashMap<PathBuf, PathBuf>,
21}
22
23impl UserData for RustMluaBuildSpec {
24    fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
25        methods.add_method("modules", |_, this, _: ()| Ok(this.modules.clone()));
26        methods.add_method("target_path", |_, this, _: ()| Ok(this.target_path.clone()));
27        methods.add_method("default_features", |_, this, _: ()| {
28            Ok(this.default_features)
29        });
30        methods.add_method("features", |_, this, _: ()| Ok(this.features.clone()));
31        methods.add_method("cargo_extra_args", |_, this, _: ()| {
32            Ok(this.cargo_extra_args.clone())
33        });
34        methods.add_method("include", |_, this, _: ()| Ok(this.include.clone()));
35    }
36}