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-15 16:43:58 +00:00
|
|
|
fn make_dt<F>(lua: &Lua, f: F) -> LuaResult<LuaValue>
|
2023-03-10 10:07:03 +00:00
|
|
|
where
|
|
|
|
F: Fn(&Lua, &LuaTable) -> LuaResult<()>,
|
|
|
|
{
|
|
|
|
let tab = lua.create_table()?;
|
|
|
|
f(lua, &tab)?;
|
|
|
|
tab.set_readonly(true);
|
2023-03-15 16:43:58 +00:00
|
|
|
Ok(LuaValue::Table(tab))
|
2023-03-10 10:07:03 +00:00
|
|
|
}
|
2023-03-09 11:17:25 +00:00
|
|
|
|
2023-03-11 09:26:33 +00:00
|
|
|
#[rustfmt::skip]
|
2023-03-15 16:43:58 +00:00
|
|
|
fn make_all_datatypes(lua: &Lua) -> LuaResult<Vec<(&'static str, LuaValue)>> {
|
2023-03-11 16:42:16 +00:00
|
|
|
use datatypes::types::*;
|
2023-03-11 10:21:34 +00:00
|
|
|
Ok(vec![
|
2023-03-15 16:43:58 +00:00
|
|
|
// Classes
|
2023-03-17 07:54:57 +00:00
|
|
|
("Axes", make_dt(lua, Axes::make_table)?),
|
|
|
|
("BrickColor", make_dt(lua, BrickColor::make_table)?),
|
|
|
|
("CFrame", make_dt(lua, CFrame::make_table)?),
|
|
|
|
("Color3", make_dt(lua, Color3::make_table)?),
|
|
|
|
("ColorSequence", make_dt(lua, ColorSequence::make_table)?),
|
|
|
|
("ColorSequenceKeypoint", make_dt(lua, ColorSequenceKeypoint::make_table)?),
|
|
|
|
("Faces", make_dt(lua, Faces::make_table)?),
|
2023-03-17 14:05:10 +00:00
|
|
|
("Font", make_dt(lua, Font::make_table)?),
|
2023-03-17 07:54:57 +00:00
|
|
|
("NumberRange", make_dt(lua, NumberRange::make_table)?),
|
|
|
|
("NumberSequence", make_dt(lua, NumberSequence::make_table)?),
|
|
|
|
("NumberSequenceKeypoint", make_dt(lua, NumberSequenceKeypoint::make_table)?),
|
2023-03-17 12:23:52 +00:00
|
|
|
("PhysicalProperties", make_dt(lua, PhysicalProperties::make_table)?),
|
2023-03-17 09:18:05 +00:00
|
|
|
("Ray", make_dt(lua, Ray::make_table)?),
|
2023-03-17 07:54:57 +00:00
|
|
|
("Rect", make_dt(lua, Rect::make_table)?),
|
|
|
|
("UDim", make_dt(lua, UDim::make_table)?),
|
|
|
|
("UDim2", make_dt(lua, UDim2::make_table)?),
|
2023-03-17 08:50:30 +00:00
|
|
|
("Region3", make_dt(lua, Region3::make_table)?),
|
|
|
|
("Region3int16", make_dt(lua, Region3int16::make_table)?),
|
2023-03-17 07:54:57 +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-15 16:43:58 +00:00
|
|
|
// Singletons
|
|
|
|
("Enum", LuaValue::UserData(Enums::make_singleton(lua)?)),
|
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)
|
|
|
|
}
|