fix: less common name for global console

This commit is contained in:
əlemi 2023-04-06 05:26:57 +02:00
parent 9541172174
commit 9c98e8bd52
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 13 additions and 9 deletions

View file

@ -7,18 +7,19 @@ use tracing::warn;
use crate::helpers::pretty_lua; use crate::helpers::pretty_lua;
use super::{console::Console, HELPTEXT}; use super::{console::Console, HELPTEXT, GLOBAL_CONSOLE};
const SIGSEGV_HOOK : AtomicBool = AtomicBool::new(false); const SIGSEGV_HOOK : AtomicBool = AtomicBool::new(false);
pub fn lua_help(lua: &Lua, _args: ()) -> Result<(), Error> { pub fn lua_help(lua: &Lua, _args: ()) -> Result<(), Error> {
let console : Console = lua.globals().get("console")?; let console : Console = lua.globals().get(GLOBAL_CONSOLE)?;
console.send(HELPTEXT.into()) console.send(HELPTEXT.into())?;
Ok(())
} }
pub fn lua_log(lua: &Lua, values: Variadic<Value>) -> Result<usize, Error> { pub fn lua_log(lua: &Lua, values: Variadic<Value>) -> Result<usize, Error> {
let mut out = String::new(); let mut out = String::new();
let console : Console = lua.globals().get("console")?; let console : Console = lua.globals().get(GLOBAL_CONSOLE)?;
for value in values { for value in values {
out.push_str(&pretty_lua(value)); out.push_str(&pretty_lua(value));
out.push(' '); out.push(' ');
@ -33,8 +34,8 @@ pub fn lua_hexdump(lua: &Lua, (bytes, ret): (Vec<u8>, Option<bool>)) -> Result<V
if ret.unwrap_or(false) { if ret.unwrap_or(false) {
return Ok(pretty_hex::simple_hex(&bytes).to_lua(lua)?); return Ok(pretty_hex::simple_hex(&bytes).to_lua(lua)?);
} }
let console : Console = lua.globals().get("console")?; let console : Console = lua.globals().get(GLOBAL_CONSOLE)?;
console.send(pretty_hex::pretty_hex(&bytes))?; console.send(pretty_hex::pretty_hex(&bytes) + "\n")?;
Ok(Value::Nil) Ok(Value::Nil)
} }
@ -178,7 +179,7 @@ pub fn lua_procmaps(lua: &Lua, ret: Option<bool>) -> Result<Value, Error> {
).as_str() ).as_str()
); );
} }
let console : Console = lua.globals().get("console")?; let console : Console = lua.globals().get(GLOBAL_CONSOLE)?;
console.send(out)?; console.send(out)?;
Ok(Value::Nil) Ok(Value::Nil)
} }
@ -219,7 +220,7 @@ pub fn lua_threads(lua: &Lua, ret: Option<bool>) -> Result<Value, Error> {
} }
} }
let console : Console = lua.globals().get("console")?; let console : Console = lua.globals().get(GLOBAL_CONSOLE)?;
console.send(out)?; console.send(out)?;
Ok(Value::Nil) Ok(Value::Nil)
} }

View file

@ -10,13 +10,16 @@ use tokio::sync::broadcast;
use crate::runtime::console::Console; use crate::runtime::console::Console;
use crate::runtime::builtins::*; use crate::runtime::builtins::*;
pub const GLOBAL_CONSOLE : &str = "GLOBAL_CONSOLE";
pub fn register_builtin_fn(lua: &Lua, console: broadcast::Sender<String>) -> Result<(), Error> { pub fn register_builtin_fn(lua: &Lua, console: broadcast::Sender<String>) -> Result<(), Error> {
lua.globals().set("console", Console::from(console))?; // TODO passing it this way makes clones lua.globals().set(GLOBAL_CONSOLE, Console::from(console))?; // TODO passing it this way makes clones
lua.globals().set("PROT_NONE", ProtFlags::PROT_NONE.bits())?; lua.globals().set("PROT_NONE", ProtFlags::PROT_NONE.bits())?;
lua.globals().set("PROT_READ", ProtFlags::PROT_READ.bits())?; lua.globals().set("PROT_READ", ProtFlags::PROT_READ.bits())?;
lua.globals().set("PROT_WRITE", ProtFlags::PROT_WRITE.bits())?; lua.globals().set("PROT_WRITE", ProtFlags::PROT_WRITE.bits())?;
lua.globals().set("PROT_EXEC", ProtFlags::PROT_EXEC.bits())?; lua.globals().set("PROT_EXEC", ProtFlags::PROT_EXEC.bits())?;
lua.globals().set("PROT_ALL", (ProtFlags::PROT_EXEC | ProtFlags::PROT_WRITE | ProtFlags::PROT_READ).bits())?;
lua.globals().set("MAP_ANON", MapFlags::MAP_ANON.bits())?; lua.globals().set("MAP_ANON", MapFlags::MAP_ANON.bits())?;
lua.globals().set("MAP_PRIVATE",MapFlags::MAP_PRIVATE.bits())?; lua.globals().set("MAP_PRIVATE",MapFlags::MAP_PRIVATE.bits())?;