2023-01-21 03:01:02 +00:00
|
|
|
mod console;
|
|
|
|
mod fs;
|
|
|
|
mod net;
|
|
|
|
mod process;
|
2023-01-24 07:05:54 +00:00
|
|
|
mod require;
|
2023-01-21 18:33:33 +00:00
|
|
|
mod task;
|
2023-01-21 03:01:02 +00:00
|
|
|
|
2023-02-06 03:25:36 +00:00
|
|
|
// Global tables
|
|
|
|
|
2023-01-22 20:23:56 +00:00
|
|
|
pub use console::create as create_console;
|
|
|
|
pub use fs::create as create_fs;
|
|
|
|
pub use net::create as create_net;
|
|
|
|
pub use process::create as create_process;
|
2023-01-24 07:05:54 +00:00
|
|
|
pub use require::create as create_require;
|
2023-01-22 20:23:56 +00:00
|
|
|
pub use task::create as create_task;
|
2023-02-06 03:25:36 +00:00
|
|
|
|
|
|
|
// Individual top-level global values
|
|
|
|
|
|
|
|
use mlua::prelude::*;
|
|
|
|
|
|
|
|
use crate::utils::formatting::pretty_format_multi_value;
|
|
|
|
|
|
|
|
pub fn create_top_level(lua: &Lua) -> LuaResult<()> {
|
|
|
|
let globals = lua.globals();
|
|
|
|
// HACK: We need to preserve the default behavior of the
|
|
|
|
// print and error functions, for pcall and such, which
|
|
|
|
// is really tricky to do from scratch so we will just
|
|
|
|
// proxy the default print and error functions here
|
|
|
|
let print_fn: LuaFunction = globals.raw_get("print")?;
|
|
|
|
let error_fn: LuaFunction = globals.raw_get("error")?;
|
|
|
|
lua.set_named_registry_value("print", print_fn)?;
|
|
|
|
lua.set_named_registry_value("error", error_fn)?;
|
|
|
|
globals.raw_set(
|
|
|
|
"print",
|
|
|
|
lua.create_function(|lua, args: LuaMultiValue| {
|
|
|
|
let formatted = pretty_format_multi_value(&args)?;
|
|
|
|
let print: LuaFunction = lua.named_registry_value("print")?;
|
|
|
|
print.call(formatted)?;
|
|
|
|
Ok(())
|
|
|
|
})?,
|
|
|
|
)?;
|
|
|
|
globals.raw_set(
|
|
|
|
"info",
|
|
|
|
lua.create_function(|lua, args: LuaMultiValue| {
|
|
|
|
let formatted = pretty_format_multi_value(&args)?;
|
|
|
|
let print: LuaFunction = lua.named_registry_value("print")?;
|
|
|
|
print.call(formatted)?;
|
|
|
|
Ok(())
|
|
|
|
})?,
|
|
|
|
)?;
|
|
|
|
globals.raw_set(
|
|
|
|
"warn",
|
|
|
|
lua.create_function(|lua, args: LuaMultiValue| {
|
|
|
|
let formatted = pretty_format_multi_value(&args)?;
|
|
|
|
let print: LuaFunction = lua.named_registry_value("print")?;
|
|
|
|
print.call(formatted)?;
|
|
|
|
Ok(())
|
|
|
|
})?,
|
|
|
|
)?;
|
|
|
|
globals.raw_set(
|
|
|
|
"error",
|
|
|
|
lua.create_function(|lua, (arg, level): (LuaValue, Option<u32>)| {
|
|
|
|
let multi = arg.to_lua_multi(lua)?;
|
|
|
|
let formatted = pretty_format_multi_value(&multi)?;
|
|
|
|
let error: LuaFunction = lua.named_registry_value("error")?;
|
|
|
|
error.call((formatted, level))?;
|
|
|
|
Ok(())
|
|
|
|
})?,
|
|
|
|
)?;
|
|
|
|
Ok(())
|
|
|
|
}
|