lune/packages/lib-roblox/src/lib.rs

56 lines
2.3 KiB
Rust
Raw Normal View History

use mlua::prelude::*;
pub mod datatypes;
pub mod document;
pub mod instance;
2023-03-15 16:43:58 +00:00
fn make_dt<F>(lua: &Lua, f: F) -> LuaResult<LuaValue>
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-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)>> {
use datatypes::types::*;
Ok(vec![
2023-03-15 16:43:58 +00:00
// Classes
("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)?),
("NumberRange", make_dt(lua, NumberRange::make_table)?),
("NumberSequence", make_dt(lua, NumberSequence::make_table)?),
("NumberSequenceKeypoint", make_dt(lua, NumberSequenceKeypoint::make_table)?),
("PhysicalProperties", make_dt(lua, PhysicalProperties::make_table)?),
2023-03-17 09:18:05 +00:00
("Ray", make_dt(lua, Ray::make_table)?),
("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)?),
("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)?)),
])
}
pub fn module(lua: &Lua) -> LuaResult<LuaTable> {
let exports = lua.create_table()?;
for (name, tab) in make_all_datatypes(lua)? {
exports.set(name, tab)?;
}
Ok(exports)
}