Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- impl<'lua> ToLua<'lua> for MessageListEntry {
- fn to_lua(self, lua: &'lua Lua) -> Result<Value<'lua>, Error> {
- Ok(match self {
- MessageListEntry::I8(int) => Value::Integer(int as i64),
- MessageListEntry::String(text) => Value::String(lua.create_string(&text).unwrap()),
- MessageListEntry::Coord((x,y)) => {
- let mut table = lua.create_table().unwrap();
- table.set("x", x).unwrap();
- table.set("y", y).unwrap();
- Value::Table(table)
- },
- MessageListEntry::U8(int) => Value::Integer(int as i64),
- MessageListEntry::U16(int) => Value::Integer(int as i64),
- MessageListEntry::Color((r, g, b, a)) => {
- let mut table = lua.create_table().unwrap();
- table.set("r", r).unwrap();
- table.set("g", g).unwrap();
- table.set("b", b).unwrap();
- table.set("a", a).unwrap();
- Value::Table(table)
- },
- MessageListEntry::List(list) => return list.to_lua(lua),
- MessageListEntry::I32(int) => Value::Integer(int as i64),
- MessageListEntry::I16(int) => Value::Integer(int as i64),
- MessageListEntry::Null => Value::Nil,
- MessageListEntry::I64(int) => Value::Integer(int as i64),
- MessageListEntry::Bytes(bytes) => {
- let mut table = lua.create_table().unwrap();
- let mut counter = 1;
- for byte in bytes {
- table.set(counter, byte).unwrap();
- counter += 1;
- }
- Value::Table(table)
- },
- MessageListEntry::F32(float) => Value::Number(float as f64),
- MessageListEntry::F64(float) => Value::Number(float as f64),
- MessageListEntry::CoordF32((x, y)) => {
- let mut table = lua.create_table().unwrap();
- table.set("x", x).unwrap();
- table.set("y", y).unwrap();
- Value::Table(table)
- },
- MessageListEntry::CoordF64((x, y)) => {
- let mut table = lua.create_table().unwrap();
- table.set("x", x).unwrap();
- table.set("y", y).unwrap();
- Value::Table(table)
- }
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement