Skip to content

Commit

Permalink
refactor project
Browse files Browse the repository at this point in the history
  • Loading branch information
CppCXY committed Oct 31, 2024
1 parent c98e63d commit b3fc3cc
Show file tree
Hide file tree
Showing 1,020 changed files with 69 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/dist
/resources/log
/log
/bin
File renamed without changes.
38 changes: 21 additions & 17 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'luals-rust'",
"name": "Debug executable 'luals' rust part",
"cargo": {
"args": [
"build",
Expand All @@ -25,23 +25,27 @@
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'luals-rust'",
"cargo": {
"args": [
"test",
"--no-run",
"--bin=luals-rust",
"--package=luals-rust"
"name": "🍄attach",
"type": "lua",
"request": "attach",
"stopOnEntry": false,
"address": "127.0.0.1:11428",
"outputCapture": [],
"sourceFormat": "string",
"sourceMaps": [
[
"script/*",
"${workspaceFolder}/script/*"
]
],
"windows": {
"sourceMaps": [
[
"script\\*",
"${workspaceFolder}/script/*"
]
],
"filter": {
"name": "luals-rust",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
}
},
]
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ cargo build --release -p luals

# Publish

To publish the project, run:
To build the project, run:

On Windows:
```bash
./publish/WinPublish.ps1
./publish/WinBuild.ps1
```

On other systems:
```bash
./publish/UnixPublish.sh
./publish/UnixBuild.sh
```
will package the compiled files and related resource files into the `dist` directory

File renamed without changes.
13 changes: 10 additions & 3 deletions crates/basic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@ pub fn lua_preload(lua: &Lua) -> LuaResult<()> {
codestyle::register_code_format_module(lua)?;

parser::register_parser_module(lua)?;

// Get current environment path
let current_path = std::env::current_dir()?;
let base_require_path = current_path.join("?.lua");
let base_require_path_init = current_path.join("?/init.lua");
let require_path = current_path.join("script/?.lua");
let require_path_init = current_path.join("script/?/init.lua");
add_package_path(
&lua,
vec![
"resources/?.lua;resources/?/init.lua;",
"resources/script/?.lua;resources/script/?/init.lua",
base_require_path.to_str().unwrap(),
base_require_path_init.to_str().unwrap(),
require_path.to_str().unwrap(),
require_path_init.to_str().unwrap(),
],
)?;

Expand Down
2 changes: 1 addition & 1 deletion crates/basic/src/parser/lua_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl LuaUserData for LuaNodeWrapper {
table.set("end", col)?;
Ok(table)
});
methods.add_method("getChildren", |lua, this, ()| {
methods.add_method("getChildren", |_, this, ()| {
let children = match this {
LuaNodeWrapper::Node(node) => node
.children_with_tokens()
Expand Down
34 changes: 24 additions & 10 deletions crates/luals/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
use mlua::prelude::*;
use std::{env, path};
use std::env;

#[tokio::main(flavor = "current_thread")]
async fn main() -> LuaResult<()> {
dynamic_set_root();

let lua = unsafe { Lua::unsafe_new() };
luals_basic::lua_preload(&lua)?;

#[cfg(not(debug_assertions))]
{
let exe_path = env::current_exe().unwrap();
let exe_dir = exe_path.parent().unwrap();
std::env::set_current_dir(exe_dir)?;
}

build_args(&lua);
let main = lua.load(path::Path::new("resources/main.lua"));
let current_path = std::env::current_dir()?;
let main_path = current_path.join("main.lua");
let main = lua.load(main_path);
main.call_async(()).await?;
Ok(())
}
Expand All @@ -30,8 +27,25 @@ fn build_args(lua: &Lua) {
lua.globals().set("arg", table).unwrap();
}

fn dynamic_set_root() {
let exe_path = env::current_exe().unwrap();
let mut current_dir = exe_path.parent().unwrap();

while !current_dir.join("main.lua").exists() {
if let Some(parent) = current_dir.parent() {
current_dir = parent;
} else {
break;
}
}

std::env::set_current_dir(current_dir).unwrap();
}

#[cfg(test)]
mod tests {
use std::path;

use tokio::runtime::Builder;

use super::*;
Expand All @@ -44,7 +58,7 @@ mod tests {
eprintln!("Error during lua_preload: {:?}", e);
return;
}
let main = lua.load(path::Path::new("resources/test.lua"));
let main = lua.load(path::Path::new("test.lua"));
main.call_async::<()>(()).await.unwrap();
});
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 5 additions & 1 deletion resources/main.lua → main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local fs = require 'bee.filesystem'
local util = require 'utility'
local version = require 'version'
require 'config.env'
require 'test'

local function getValue(value)
if value == 'true' or value == nil then
value = true
Expand Down Expand Up @@ -77,6 +77,10 @@ xpcall(dofile, log.debug, (ROOT / 'debugger.lua'):string())

require 'cli'

if TEST then
require 'test'
return
end
local _, service = xpcall(require, log.error, 'service')

service.start()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit b3fc3cc

Please sign in to comment.