refactor(core,shim): 统一基于 thiserror 的错误体系
- 移除 anyhow,使用 thiserror 定义强类型 Error 枚举 - 支持 #[from] 自动转换 mlua::Error,关键路径保留源码与上下文 - LuaRuntimeBuilder 采用惰性错误收集,简化链式初始化调用 - MirrorRegistry 实现规范化 FromLuaConversionError 错误转换
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
use mirror_core::{Error, Result};
|
||||
use mlua::{Lua, Table, Value};
|
||||
|
||||
/// 仅存在于 CLI 侧的 DSL 扩展函数
|
||||
pub fn register_mr_command(lua: &Lua) -> Result<()> {
|
||||
let globals = lua.globals();
|
||||
|
||||
let mr_table: Table = match globals.get("mr")? {
|
||||
Value::Table(tbl) => tbl,
|
||||
_ => {
|
||||
let tbl = lua.create_table()?;
|
||||
globals.set("mr", &tbl)?;
|
||||
tbl
|
||||
}
|
||||
};
|
||||
|
||||
let command_fn = lua.create_function(|_lua, mod_path: String| {
|
||||
let normalized = mod_path.replace(['/', '\\'], ".");
|
||||
Ok(normalized)
|
||||
})?;
|
||||
|
||||
mr_table.set("command", command_fn)?;
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user