|
1 | 1 | use mlua::{Lua, Table, Value, chunk}; |
2 | | -use omni_led_api::types::Field; |
3 | | -use omni_led_api::types::field::Field as FieldEntry; |
4 | | -use std::hash::{DefaultHasher, Hash, Hasher}; |
5 | | - |
6 | | -use crate::script_handler::script_data_types::ImageData; |
7 | 2 |
|
8 | 3 | #[macro_export] |
9 | 4 | macro_rules! create_table { |
@@ -51,8 +46,6 @@ macro_rules! create_table_with_defaults { |
51 | 46 | }}; |
52 | 47 | } |
53 | 48 |
|
54 | | -pub const KEY_VAL_TABLE: &str = "key-val-table"; |
55 | | - |
56 | 49 | pub fn load_internal_functions(lua: &Lua) { |
57 | 50 | let dump = lua |
58 | 51 | .create_function(|_, value: Value| { |
@@ -90,53 +83,3 @@ pub fn load_internal_functions(lua: &Lua) { |
90 | 83 | ) |
91 | 84 | .unwrap(); |
92 | 85 | } |
93 | | - |
94 | | -pub fn proto_to_lua_value(lua: &Lua, field: Field) -> mlua::Result<Value> { |
95 | | - match field.field { |
96 | | - None => Ok(mlua::Nil), |
97 | | - Some(FieldEntry::FBool(bool)) => Ok(Value::Boolean(bool)), |
98 | | - Some(FieldEntry::FInteger(integer)) => Ok(Value::Integer(integer)), |
99 | | - Some(FieldEntry::FFloat(float)) => Ok(Value::Number(float)), |
100 | | - Some(FieldEntry::FString(string)) => { |
101 | | - let string = lua.create_string(string)?; |
102 | | - Ok(Value::String(string)) |
103 | | - } |
104 | | - Some(FieldEntry::FArray(array)) => { |
105 | | - let size = array.items.len(); |
106 | | - let table = lua.create_table_with_capacity(size, 0)?; |
107 | | - for value in array.items { |
108 | | - table.push(proto_to_lua_value(lua, value)?)?; |
109 | | - } |
110 | | - Ok(Value::Table(table)) |
111 | | - } |
112 | | - Some(FieldEntry::FTable(map)) => { |
113 | | - let size = map.items.len(); |
114 | | - let table = lua.create_table_with_capacity(0, size)?; |
115 | | - for (key, value) in map.items { |
116 | | - table.set(key, proto_to_lua_value(lua, value)?)?; |
117 | | - } |
118 | | - |
119 | | - let meta = lua.create_table_with_capacity(0, 1)?; |
120 | | - meta.set(KEY_VAL_TABLE, true)?; |
121 | | - _ = table.set_metatable(Some(meta)); |
122 | | - |
123 | | - Ok(Value::Table(table)) |
124 | | - } |
125 | | - Some(FieldEntry::FImageData(image)) => { |
126 | | - let hash = hash(&image.data); |
127 | | - let image_data = ImageData { |
128 | | - format: image.format().try_into().map_err(mlua::Error::external)?, |
129 | | - bytes: image.data, |
130 | | - hash: Some(hash), |
131 | | - }; |
132 | | - let user_data = lua.create_any_userdata(image_data)?; |
133 | | - Ok(Value::UserData(user_data)) |
134 | | - } |
135 | | - } |
136 | | -} |
137 | | - |
138 | | -pub fn hash<T: Hash>(t: &T) -> u64 { |
139 | | - let mut s = DefaultHasher::new(); |
140 | | - t.hash(&mut s); |
141 | | - s.finish() |
142 | | -} |
0 commit comments