2023-03-09 11:17:25 +00:00
|
|
|
use mlua::prelude::*;
|
2023-03-19 12:23:25 +00:00
|
|
|
|
|
|
|
use crate::instance::Instance;
|
2023-03-09 11:17:25 +00:00
|
|
|
|
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-19 12:23:25 +00:00
|
|
|
pub(crate) mod shared;
|
|
|
|
|
|
|
|
fn make<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-19 12:23:25 +00:00
|
|
|
// Datatypes
|
|
|
|
("Axes", make(lua, Axes::make_table)?),
|
|
|
|
("BrickColor", make(lua, BrickColor::make_table)?),
|
|
|
|
("CFrame", make(lua, CFrame::make_table)?),
|
|
|
|
("Color3", make(lua, Color3::make_table)?),
|
|
|
|
("ColorSequence", make(lua, ColorSequence::make_table)?),
|
|
|
|
("ColorSequenceKeypoint", make(lua, ColorSequenceKeypoint::make_table)?),
|
|
|
|
("Faces", make(lua, Faces::make_table)?),
|
|
|
|
("Font", make(lua, Font::make_table)?),
|
|
|
|
("NumberRange", make(lua, NumberRange::make_table)?),
|
|
|
|
("NumberSequence", make(lua, NumberSequence::make_table)?),
|
|
|
|
("NumberSequenceKeypoint", make(lua, NumberSequenceKeypoint::make_table)?),
|
|
|
|
("PhysicalProperties", make(lua, PhysicalProperties::make_table)?),
|
|
|
|
("Ray", make(lua, Ray::make_table)?),
|
|
|
|
("Rect", make(lua, Rect::make_table)?),
|
|
|
|
("UDim", make(lua, UDim::make_table)?),
|
|
|
|
("UDim2", make(lua, UDim2::make_table)?),
|
|
|
|
("Region3", make(lua, Region3::make_table)?),
|
|
|
|
("Region3int16", make(lua, Region3int16::make_table)?),
|
|
|
|
("Vector2", make(lua, Vector2::make_table)?),
|
|
|
|
("Vector2int16", make(lua, Vector2int16::make_table)?),
|
|
|
|
("Vector3", make(lua, Vector3::make_table)?),
|
|
|
|
("Vector3int16", make(lua, Vector3int16::make_table)?),
|
2023-03-15 16:43:58 +00:00
|
|
|
// Classes
|
2023-03-19 12:23:25 +00:00
|
|
|
("Instance", make(lua, Instance::make_table)?),
|
2023-03-15 16:43:58 +00:00
|
|
|
// Singletons
|
2023-03-19 12:23:25 +00:00
|
|
|
("Enum", Enums.to_lua(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-21 18:13:41 +00:00
|
|
|
exports.set_readonly(true);
|
2023-03-09 11:17:25 +00:00
|
|
|
Ok(exports)
|
|
|
|
}
|