Skip to content

Commit e08fb73

Browse files
committed
fix some api
1 parent b87374a commit e08fb73

File tree

4 files changed

+30
-32
lines changed

4 files changed

+30
-32
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/target
22
/dist
3-
/resources/log
3+
/resources/log
4+
/log

src/bee/lua_filesystem.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ fn symlink_status(_: &Lua, path: LuaFilePath) -> LuaResult<SymlinkStatus> {
361361

362362
fn pairs(lua: &Lua, path: LuaFilePath) -> LuaResult<(mlua::Function, mlua::Table, mlua::Value)> {
363363
let table = lua.create_table()?;
364-
if let Ok(_) = std::fs::exists(&path.path) {
364+
if let Ok(true) = std::fs::exists(&path.path) {
365365
for entry in std::fs::read_dir(&path.path)? {
366366
let entry = entry?;
367367
let path = entry.path();
@@ -388,6 +388,10 @@ fn pairs(lua: &Lua, path: LuaFilePath) -> LuaResult<(mlua::Function, mlua::Table
388388
Ok((next, table, mlua::Nil))
389389
}
390390

391+
fn exe_path(_: &Lua, (): ()) -> LuaResult<LuaFilePath> {
392+
Ok(LuaFilePath::new(std::env::current_exe().unwrap().to_str().unwrap().to_string()))
393+
}
394+
391395
pub fn bee_filesystem(lua: &Lua) -> LuaResult<Table> {
392396
let exports = lua.create_table()?;
393397

@@ -429,6 +433,6 @@ pub fn bee_filesystem(lua: &Lua) -> LuaResult<Table> {
429433
)?;
430434
exports.set("fullpath", lua.create_function(full_path)?)?;
431435
exports.set("symlink_status", lua.create_function(symlink_status)?)?;
432-
436+
exports.set("exe_path", lua.create_function(exe_path)?)?;
433437
Ok(exports)
434438
}

src/bee/lua_platform.rs

-26
Original file line numberDiff line numberDiff line change
@@ -35,32 +35,6 @@ pub fn bee_platform(lua: &Lua) -> LuaResult<LuaTable> {
3535
};
3636
exports.set("os", os_name)?;
3737

38-
// // 设置编译器信息
39-
// let (compiler, compiler_version) = if cfg!(target_env = "msvc") {
40-
// ("msvc", format!("MSVC {}", env!("VC_REVISION")))
41-
// } else if cfg!(target_env = "gnu") {
42-
// ("gcc", format!("GCC {}.{}.{}", env!("CARGO_CFG_GNUC_VERSION_MAJOR"), env!("CARGO_CFG_GNUC_VERSION_MINOR"), env!("CARGO_CFG_GNUC_VERSION_PATCH")))
43-
// } else if cfg!(target_env = "clang") {
44-
// ("clang", format!("Clang {}.{}.{}", env!("CARGO_CFG_CLANG_VERSION_MAJOR"), env!("CARGO_CFG_CLANG_VERSION_MINOR"), env!("CARGO_CFG_CLANG_VERSION_PATCH")))
45-
// } else {
46-
// ("unknown", "unknown".to_string())
47-
// };
48-
// exports.set("Compiler", compiler)?;
49-
// exports.set("CompilerVersion", compiler_version)?;
50-
51-
// // 设置 C 运行时库信息
52-
// let (crt, crt_version) = if cfg!(target_env = "msvc") {
53-
// ("msvc", format!("MSVC STL {}", env!("CARGO_CFG_MSC_VER")))
54-
// } else if cfg!(target_env = "gnu") {
55-
// ("libstdc++", format!("libstdc++ {}", env!("CARGO_CFG_GLIBCXX_VERSION")))
56-
// } else if cfg!(target_env = "musl") {
57-
// ("musl", format!("musl {}", env!("CARGO_CFG_MUSL_VERSION")))
58-
// } else {
59-
// ("unknown", "unknown".to_string())
60-
// };
61-
// exports.set("CRT", crt)?;
62-
// exports.set("CRTVersion", crt_version)?;
63-
6438
// 设置架构信息
6539
let arch = if cfg!(target_arch = "x86") {
6640
"x86"

src/main.rs

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
mod bee;
2+
mod codestyle;
23
mod lua_preload;
34
mod lua_seri;
45
mod override_lua;
5-
mod codestyle;
6-
76

87
#[macro_use]
98
extern crate lazy_static;
10-
use std::{env, path};
119
use mlua::prelude::*;
10+
use std::{env, path};
1211

1312
#[tokio::main(flavor = "current_thread")]
1413
async fn main() -> LuaResult<()> {
@@ -38,3 +37,23 @@ fn build_args(lua: &Lua) {
3837
table.set(-1, exe_path.to_str().unwrap()).unwrap();
3938
lua.globals().set("arg", table).unwrap();
4039
}
40+
41+
#[cfg(test)]
42+
mod tests {
43+
use tokio::runtime::Builder;
44+
45+
use super::*;
46+
#[test]
47+
fn test_main() {
48+
let rt = Builder::new_current_thread().enable_all().build().unwrap();
49+
rt.block_on(async move {
50+
let lua = unsafe { Lua::unsafe_new() };
51+
if let Err(e) = lua_preload::lua_preload(&lua) {
52+
eprintln!("Error during lua_preload: {:?}", e);
53+
return;
54+
}
55+
let main = lua.load(path::Path::new("resources/test.lua"));
56+
main.call_async::<()>(()).await.unwrap();
57+
});
58+
}
59+
}

0 commit comments

Comments
 (0)