Skip to content

Commit

Permalink
fix some api
Browse files Browse the repository at this point in the history
  • Loading branch information
CppCXY committed Sep 13, 2024
1 parent b87374a commit e08fb73
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
/dist
/resources/log
/resources/log
/log
8 changes: 6 additions & 2 deletions src/bee/lua_filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ fn symlink_status(_: &Lua, path: LuaFilePath) -> LuaResult<SymlinkStatus> {

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

fn exe_path(_: &Lua, (): ()) -> LuaResult<LuaFilePath> {
Ok(LuaFilePath::new(std::env::current_exe().unwrap().to_str().unwrap().to_string()))
}

pub fn bee_filesystem(lua: &Lua) -> LuaResult<Table> {
let exports = lua.create_table()?;

Expand Down Expand Up @@ -429,6 +433,6 @@ pub fn bee_filesystem(lua: &Lua) -> LuaResult<Table> {
)?;
exports.set("fullpath", lua.create_function(full_path)?)?;
exports.set("symlink_status", lua.create_function(symlink_status)?)?;

exports.set("exe_path", lua.create_function(exe_path)?)?;
Ok(exports)
}
26 changes: 0 additions & 26 deletions src/bee/lua_platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,6 @@ pub fn bee_platform(lua: &Lua) -> LuaResult<LuaTable> {
};
exports.set("os", os_name)?;

// // 设置编译器信息
// let (compiler, compiler_version) = if cfg!(target_env = "msvc") {
// ("msvc", format!("MSVC {}", env!("VC_REVISION")))
// } else if cfg!(target_env = "gnu") {
// ("gcc", format!("GCC {}.{}.{}", env!("CARGO_CFG_GNUC_VERSION_MAJOR"), env!("CARGO_CFG_GNUC_VERSION_MINOR"), env!("CARGO_CFG_GNUC_VERSION_PATCH")))
// } else if cfg!(target_env = "clang") {
// ("clang", format!("Clang {}.{}.{}", env!("CARGO_CFG_CLANG_VERSION_MAJOR"), env!("CARGO_CFG_CLANG_VERSION_MINOR"), env!("CARGO_CFG_CLANG_VERSION_PATCH")))
// } else {
// ("unknown", "unknown".to_string())
// };
// exports.set("Compiler", compiler)?;
// exports.set("CompilerVersion", compiler_version)?;

// // 设置 C 运行时库信息
// let (crt, crt_version) = if cfg!(target_env = "msvc") {
// ("msvc", format!("MSVC STL {}", env!("CARGO_CFG_MSC_VER")))
// } else if cfg!(target_env = "gnu") {
// ("libstdc++", format!("libstdc++ {}", env!("CARGO_CFG_GLIBCXX_VERSION")))
// } else if cfg!(target_env = "musl") {
// ("musl", format!("musl {}", env!("CARGO_CFG_MUSL_VERSION")))
// } else {
// ("unknown", "unknown".to_string())
// };
// exports.set("CRT", crt)?;
// exports.set("CRTVersion", crt_version)?;

// 设置架构信息
let arch = if cfg!(target_arch = "x86") {
"x86"
Expand Down
25 changes: 22 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
mod bee;
mod codestyle;
mod lua_preload;
mod lua_seri;
mod override_lua;
mod codestyle;


#[macro_use]
extern crate lazy_static;
use std::{env, path};
use mlua::prelude::*;
use std::{env, path};

#[tokio::main(flavor = "current_thread")]
async fn main() -> LuaResult<()> {
Expand Down Expand Up @@ -38,3 +37,23 @@ fn build_args(lua: &Lua) {
table.set(-1, exe_path.to_str().unwrap()).unwrap();
lua.globals().set("arg", table).unwrap();
}

#[cfg(test)]
mod tests {
use tokio::runtime::Builder;

use super::*;
#[test]
fn test_main() {
let rt = Builder::new_current_thread().enable_all().build().unwrap();
rt.block_on(async move {
let lua = unsafe { Lua::unsafe_new() };
if let Err(e) = lua_preload::lua_preload(&lua) {
eprintln!("Error during lua_preload: {:?}", e);
return;
}
let main = lua.load(path::Path::new("resources/test.lua"));
main.call_async::<()>(()).await.unwrap();
});
}
}

0 comments on commit e08fb73

Please sign in to comment.