2023-03-09 11:17:25 +00:00
|
|
|
use mlua::prelude::*;
|
|
|
|
|
2023-03-10 10:07:03 +00:00
|
|
|
pub mod datatypes;
|
2023-03-09 11:17:25 +00:00
|
|
|
pub mod document;
|
2023-03-10 10:07:03 +00:00
|
|
|
pub mod instance;
|
|
|
|
|
2023-03-11 10:21:34 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests;
|
|
|
|
|
2023-03-10 10:07:03 +00:00
|
|
|
use datatypes::types::*;
|
|
|
|
|
|
|
|
fn make_dt<F>(lua: &Lua, f: F) -> LuaResult<LuaTable>
|
|
|
|
where
|
|
|
|
F: Fn(&Lua, &LuaTable) -> LuaResult<()>,
|
|
|
|
{
|
|
|
|
let tab = lua.create_table()?;
|
|
|
|
f(lua, &tab)?;
|
|
|
|
tab.set_readonly(true);
|
|
|
|
Ok(tab)
|
|
|
|
}
|
2023-03-09 11:17:25 +00:00
|
|
|
|
2023-03-11 09:26:33 +00:00
|
|
|
#[rustfmt::skip]
|
2023-03-11 10:21:34 +00:00
|
|
|
fn make_all_datatypes(lua: &Lua) -> LuaResult<Vec<(&'static str, LuaTable)>> {
|
|
|
|
Ok(vec![
|
2023-03-11 15:39:23 +00:00
|
|
|
("Vector2", make_dt(lua, Vector2::make_table)?),
|
|
|
|
("Vector2int16", make_dt(lua, Vector2int16::make_table)?),
|
|
|
|
("Vector3", make_dt(lua, Vector3::make_table)?),
|
|
|
|
("Vector3int16", make_dt(lua, Vector3int16::make_table)?),
|
2023-03-11 10:21:34 +00:00
|
|
|
])
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn module(lua: &Lua) -> LuaResult<LuaTable> {
|
2023-03-09 11:17:25 +00:00
|
|
|
let exports = lua.create_table()?;
|
2023-03-11 10:21:34 +00:00
|
|
|
for (name, tab) in make_all_datatypes(lua)? {
|
2023-03-10 10:07:03 +00:00
|
|
|
exports.set(name, tab)?;
|
|
|
|
}
|
2023-03-09 11:17:25 +00:00
|
|
|
Ok(exports)
|
|
|
|
}
|