1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use crate::errors::*;
use crate::engine::ctx::State;
use crate::engine::structs::byte_array;
use crate::hlua::{self, AnyLuaValue};
use std::sync::Arc;
pub fn hex(lua: &mut hlua::Lua, state: Arc<dyn State>) {
lua.set("hex", hlua::function1(move |bytes: AnyLuaValue| -> Result<String> {
byte_array(bytes)
.map_err(|err| state.set_error(err))
.map(|bytes| {
let mut out = String::new();
for b in bytes {
out += &format!("{:02x}", b);
}
out
})
}))
}