Skip to content

Commit b3fc3cc

Browse files
committed
refactor project
1 parent c98e63d commit b3fc3cc

File tree

1,020 files changed

+69
-44
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,020 files changed

+69
-44
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/dist
33
/resources/log
44
/log
5+
/bin
File renamed without changes.

.vscode/launch.json

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
"type": "lldb",
99
"request": "launch",
10-
"name": "Debug executable 'luals-rust'",
10+
"name": "Debug executable 'luals' rust part",
1111
"cargo": {
1212
"args": [
1313
"build",
@@ -25,23 +25,27 @@
2525
"cwd": "${workspaceFolder}"
2626
},
2727
{
28-
"type": "lldb",
29-
"request": "launch",
30-
"name": "Debug unit tests in executable 'luals-rust'",
31-
"cargo": {
32-
"args": [
33-
"test",
34-
"--no-run",
35-
"--bin=luals-rust",
36-
"--package=luals-rust"
28+
"name": "🍄attach",
29+
"type": "lua",
30+
"request": "attach",
31+
"stopOnEntry": false,
32+
"address": "127.0.0.1:11428",
33+
"outputCapture": [],
34+
"sourceFormat": "string",
35+
"sourceMaps": [
36+
[
37+
"script/*",
38+
"${workspaceFolder}/script/*"
39+
]
40+
],
41+
"windows": {
42+
"sourceMaps": [
43+
[
44+
"script\\*",
45+
"${workspaceFolder}/script/*"
46+
]
3747
],
38-
"filter": {
39-
"name": "luals-rust",
40-
"kind": "bin"
41-
}
4248
},
43-
"args": [],
44-
"cwd": "${workspaceFolder}"
45-
}
49+
},
4650
]
4751
}

README.md

Lines changed: 4 additions & 4 deletions

crates/basic/src/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,19 @@ pub fn lua_preload(lua: &Lua) -> LuaResult<()> {
2222
codestyle::register_code_format_module(lua)?;
2323

2424
parser::register_parser_module(lua)?;
25-
25+
// Get current environment path
26+
let current_path = std::env::current_dir()?;
27+
let base_require_path = current_path.join("?.lua");
28+
let base_require_path_init = current_path.join("?/init.lua");
29+
let require_path = current_path.join("script/?.lua");
30+
let require_path_init = current_path.join("script/?/init.lua");
2631
add_package_path(
2732
&lua,
2833
vec![
29-
"resources/?.lua;resources/?/init.lua;",
30-
"resources/script/?.lua;resources/script/?/init.lua",
34+
base_require_path.to_str().unwrap(),
35+
base_require_path_init.to_str().unwrap(),
36+
require_path.to_str().unwrap(),
37+
require_path_init.to_str().unwrap(),
3138
],
3239
)?;
3340

crates/basic/src/parser/lua_node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl LuaUserData for LuaNodeWrapper {
7777
table.set("end", col)?;
7878
Ok(table)
7979
});
80-
methods.add_method("getChildren", |lua, this, ()| {
80+
methods.add_method("getChildren", |_, this, ()| {
8181
let children = match this {
8282
LuaNodeWrapper::Node(node) => node
8383
.children_with_tokens()

crates/luals/src/main.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
use mlua::prelude::*;
2-
use std::{env, path};
2+
use std::env;
33

44
#[tokio::main(flavor = "current_thread")]
55
async fn main() -> LuaResult<()> {
6+
dynamic_set_root();
7+
68
let lua = unsafe { Lua::unsafe_new() };
79
luals_basic::lua_preload(&lua)?;
810

9-
#[cfg(not(debug_assertions))]
10-
{
11-
let exe_path = env::current_exe().unwrap();
12-
let exe_dir = exe_path.parent().unwrap();
13-
std::env::set_current_dir(exe_dir)?;
14-
}
15-
1611
build_args(&lua);
17-
let main = lua.load(path::Path::new("resources/main.lua"));
12+
let current_path = std::env::current_dir()?;
13+
let main_path = current_path.join("main.lua");
14+
let main = lua.load(main_path);
1815
main.call_async(()).await?;
1916
Ok(())
2017
}
@@ -30,8 +27,25 @@ fn build_args(lua: &Lua) {
3027
lua.globals().set("arg", table).unwrap();
3128
}
3229

30+
fn dynamic_set_root() {
31+
let exe_path = env::current_exe().unwrap();
32+
let mut current_dir = exe_path.parent().unwrap();
33+
34+
while !current_dir.join("main.lua").exists() {
35+
if let Some(parent) = current_dir.parent() {
36+
current_dir = parent;
37+
} else {
38+
break;
39+
}
40+
}
41+
42+
std::env::set_current_dir(current_dir).unwrap();
43+
}
44+
3345
#[cfg(test)]
3446
mod tests {
47+
use std::path;
48+
3549
use tokio::runtime::Builder;
3650

3751
use super::*;
@@ -44,7 +58,7 @@ mod tests {
4458
eprintln!("Error during lua_preload: {:?}", e);
4559
return;
4660
}
47-
let main = lua.load(path::Path::new("resources/test.lua"));
61+
let main = lua.load(path::Path::new("test.lua"));
4862
main.call_async::<()>(()).await.unwrap();
4963
});
5064
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)