Rename lb_core to lb
This commit is contained in:
parent
300b4539bd
commit
ba6cb10a1a
43
Cargo.lock
generated
43
Cargo.lock
generated
@ -210,7 +210,7 @@ dependencies = [
|
||||
"bitflags",
|
||||
"cexpr",
|
||||
"clang-sys",
|
||||
"itertools",
|
||||
"itertools 0.13.0",
|
||||
"log",
|
||||
"prettyplease",
|
||||
"proc-macro2",
|
||||
@ -449,12 +449,12 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.12"
|
||||
version = "0.3.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cea14ef9355e3beab063703aa9dab15afd25f0667c341310c1e5274bb1d0da18"
|
||||
checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.60.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -733,6 +733,15 @@ dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.15"
|
||||
@ -746,12 +755,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
||||
|
||||
[[package]]
|
||||
name = "lb_core"
|
||||
name = "lb"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"luaffi",
|
||||
"luaify",
|
||||
"luajit",
|
||||
"owo-colors",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
@ -859,8 +868,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"console-subscriber",
|
||||
"lb_core",
|
||||
"luaffi",
|
||||
"lb",
|
||||
"luajit",
|
||||
"mimalloc",
|
||||
"owo-colors",
|
||||
@ -1065,9 +1073,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "prettyplease"
|
||||
version = "0.2.34"
|
||||
version = "0.2.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6837b9e10d61f45f987d50808f83d1ee3d206c66acf650c3e4ae2e1f6ddedf55"
|
||||
checksum = "061c1221631e079b26479d25bbf2275bfe5917ae8419cd7e34f13bfc2aa7539a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"syn",
|
||||
@ -1099,7 +1107,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a56d757972c98b346a9b766e3f02746cde6dd1cd1d1d563472929fdd74bec4d"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"itertools",
|
||||
"itertools 0.14.0",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
@ -1341,9 +1349,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.103"
|
||||
version = "2.0.104"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e4307e30089d6fd6aff212f2da3a1f9e32f3223b1f010fb09b7c95f90f3ca1e8"
|
||||
checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -1666,6 +1674,15 @@ dependencies = [
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.60.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb"
|
||||
dependencies = [
|
||||
"windows-targets 0.53.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.6"
|
||||
|
@ -1,6 +1,6 @@
|
||||
[workspace]
|
||||
members = [
|
||||
"crates/lb_core",
|
||||
"crates/lb",
|
||||
"crates/luaffi",
|
||||
"crates/luaffi_impl",
|
||||
"crates/luaify",
|
||||
@ -20,8 +20,7 @@ edition = "2024"
|
||||
[dependencies]
|
||||
clap = { version = "4.5.40", features = ["derive"] }
|
||||
console-subscriber = "0.4.1"
|
||||
lb_core = { version = "0.1.0", path = "crates/lb_core" }
|
||||
luaffi = { version = "0.1.0", path = "crates/luaffi" }
|
||||
lb = { version = "0.1.0", path = "crates/lb" }
|
||||
luajit = { version = "0.1.0", path = "crates/luajit", features = ["runtime"] }
|
||||
mimalloc = "0.1.47"
|
||||
owo-colors = "4.2.1"
|
||||
|
@ -1,10 +1,13 @@
|
||||
[package]
|
||||
name = "lb_core"
|
||||
name = "lb"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
luaffi = { version = "0.1.0", path = "../luaffi" }
|
||||
luajit = { version = "0.1.0", path = "../luajit" }
|
||||
owo-colors = "4.2.1"
|
||||
tokio = { version = "1.45.1", features = ["rt", "time", "fs"] }
|
||||
|
||||
[dev-dependencies]
|
||||
luaify = { path = "../luaify" }
|
||||
tokio = { version = "1.45.1", features = ["full"] }
|
2
crates/lb/src/lib.rs
Normal file
2
crates/lb/src/lib.rs
Normal file
@ -0,0 +1,2 @@
|
||||
pub mod rt;
|
||||
pub mod task;
|
@ -1,91 +0,0 @@
|
||||
use luaffi::{cdef, metatype};
|
||||
use owo_colors::OwoColorize;
|
||||
use std::{cell::RefCell, fmt, process};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GlobalState(luajit::State);
|
||||
|
||||
impl GlobalState {
|
||||
thread_local! {
|
||||
static STATE: RefCell<Option<GlobalState>> = RefCell::new(None);
|
||||
}
|
||||
|
||||
pub fn set(state: luajit::State) -> Option<luajit::State> {
|
||||
Self::STATE.with_borrow_mut(|s| s.replace(Self(state)).map(|s| s.0))
|
||||
}
|
||||
|
||||
pub fn with_current<T>(f: impl FnOnce(&luajit::State) -> T) -> T {
|
||||
Self::STATE.with_borrow(|s| f(&s.as_ref().expect("lua state not initialised").0))
|
||||
}
|
||||
|
||||
pub fn with_current_mut<T>(f: impl FnOnce(&mut luajit::State) -> T) -> T {
|
||||
Self::STATE.with_borrow_mut(|s| f(&mut s.as_mut().expect("lua state not initialised").0))
|
||||
}
|
||||
|
||||
pub fn new_thread() -> luajit::State {
|
||||
Self::with_current(|s| s.new_thread())
|
||||
}
|
||||
|
||||
pub fn uncaught_error(err: luajit::Error) {
|
||||
let mut err = PrettyError::from(err);
|
||||
if let Some(task) = tokio::task::try_id() {
|
||||
err.prepend(format_args!("uncaught error in task {task}"));
|
||||
}
|
||||
|
||||
eprintln!("{err}");
|
||||
process::abort()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PrettyError {
|
||||
msg: String,
|
||||
trace: Option<String>,
|
||||
}
|
||||
|
||||
impl PrettyError {
|
||||
pub fn new(msg: impl fmt::Display) -> Self {
|
||||
Self {
|
||||
msg: format!("{msg}"),
|
||||
trace: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_trace(mut self, trace: impl fmt::Display) -> Self {
|
||||
self.trace = Some(format!("{trace}"));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn prepend(&mut self, msg: impl fmt::Display) -> &mut Self {
|
||||
if self.msg.is_empty() {
|
||||
self.msg = format!("{msg}");
|
||||
} else {
|
||||
self.msg = format!("{msg}:\n{}", self.msg);
|
||||
}
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl From<luajit::Error> for PrettyError {
|
||||
fn from(value: luajit::Error) -> Self {
|
||||
match value {
|
||||
luajit::Error::Resume { msg, trace } => Self::new(msg).with_trace(trace),
|
||||
err => Self::new(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for PrettyError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self.trace {
|
||||
Some(ref trace) => write!(f, "{}\n{trace}", self.msg.red()),
|
||||
None => write!(f, "{}", self.msg.red()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cdef]
|
||||
pub struct lb_core;
|
||||
|
||||
#[metatype]
|
||||
impl lb_core {}
|
Loading…
x
Reference in New Issue
Block a user