Skip to content

Commit 9975ca5

Browse files
committed
support code format
1 parent a3fd6c2 commit 9975ca5

File tree

5 files changed

+62
-15
lines changed

5 files changed

+62
-15
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "3rd/lpeglabel"]
22
path = 3rd/lpeglabel
33
url = https://github.com/sqmedeiros/lpeglabel
4+
[submodule "3rd/EmmyLuaCodeStyle"]
5+
path = 3rd/EmmyLuaCodeStyle
6+
url = https://github.com/CppCXY/EmmyLuaCodeStyle.git

3rd/EmmyLuaCodeStyle

Submodule EmmyLuaCodeStyle added at 996b325

build.rs

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,21 @@ fn main() {
55
build_lua_seri();
66
build_lpeglabel();
77
cfg!(windows).then(|| build_setfilemode());
8+
build_emmyluacodestyle();
89
}
910

1011
fn build_lua() {
1112
cc::Build::new()
1213
.include("3rd/lua")
13-
.files(
14-
std::fs::read_dir("3rd/lua")
15-
.unwrap()
16-
.filter_map(|entry| {
17-
let entry = entry.unwrap();
18-
let path = entry.path();
19-
if path.extension()?.to_str()? == "c" {
20-
Some(path)
21-
} else {
22-
None
23-
}
24-
}),
25-
)
14+
.files(std::fs::read_dir("3rd/lua").unwrap().filter_map(|entry| {
15+
let entry = entry.unwrap();
16+
let path = entry.path();
17+
if path.extension()?.to_str()? == "c" {
18+
Some(path)
19+
} else {
20+
None
21+
}
22+
}))
2623
.compile("lua");
2724
}
2825

@@ -83,4 +80,43 @@ fn build_setfilemode() {
8380
}),
8481
)
8582
.compile("setfilemode");
86-
}
83+
}
84+
85+
fn build_emmyluacodestyle() {
86+
let mut builder = cc::Build::new();
87+
builder.cpp(true);
88+
builder
89+
.include("3rd/EmmyLuaCodeStyle/Util/include")
90+
.include("3rd/EmmyLuaCodeStyle/CodeFormatCore/include")
91+
.include("3rd/EmmyLuaCodeStyle/LuaParser/include")
92+
.include("3rd/EmmyLuaCodeStyle/3rd/wildcards/include")
93+
.include("3rd/lua");
94+
95+
let file_patterns = vec![
96+
"3rd/EmmyLuaCodeStyle/CodeFormatLib/src/*.cpp",
97+
"3rd/EmmyLuaCodeStyle/LuaParser/src/**/*.cpp",
98+
"3rd/EmmyLuaCodeStyle/Util/src/StringUtil.cpp",
99+
"3rd/EmmyLuaCodeStyle/Util/src/Utf8.cpp",
100+
"3rd/EmmyLuaCodeStyle/Util/src/SymSpell/*.cpp",
101+
"3rd/EmmyLuaCodeStyle/Util/src/InfoTree/*.cpp",
102+
"3rd/EmmyLuaCodeStyle/CodeFormatCore/src/**/*.cpp",
103+
];
104+
105+
for pattern in file_patterns {
106+
if pattern.contains("*") {
107+
builder.files(glob::glob(pattern).unwrap().filter_map(|path| path.ok()));
108+
} else {
109+
builder.file(pattern);
110+
}
111+
}
112+
113+
if cfg!(windows) {
114+
builder.flag("/utf-8");
115+
builder.flag("/std:c++17");
116+
}
117+
else {
118+
builder.flag("-std=c++17");
119+
}
120+
121+
builder.compile("EmmyLuaCodeStyle");
122+
}

src/lua_preload.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@ use mlua::{lua_State, prelude::*};
55

66
extern "C-unwind" {
77
fn luaopen_lpeglabel(lua: *mut lua_State) -> i32;
8+
9+
fn luaopen_code_format(lua: *mut lua_State) -> i32;
810
}
911

1012
pub fn lua_preload(lua: &Lua) -> LuaResult<()> {
1113
// lpeglabel
1214
let lpeglabel_loader = unsafe { lua.create_c_function(luaopen_lpeglabel) }.unwrap();
1315
add_preload_module(&lua, "lpeglabel", lpeglabel_loader)?;
16+
// code_format
17+
let code_format_loader = unsafe { lua.create_c_function(luaopen_code_format) }.unwrap();
18+
add_preload_module(&lua, "code_format", code_format_loader)?;
19+
1420
// bee.platform
1521
let bee_platform_loader =
1622
lua.create_function(|lua: &Lua, ()| Ok(bee::lua_platform::bee_platform(lua)))?;
@@ -56,7 +62,7 @@ pub fn lua_preload(lua: &Lua) -> LuaResult<()> {
5662
&lua,
5763
"resources/?.lua;resources/?/init.lua;resources/script/?.lua;resources/script/?/init.lua",
5864
)?;
59-
65+
6066
Ok(())
6167
}
6268

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mod lua_preload;
33
mod lua_seri;
44
mod override_lua;
55

6+
67
#[macro_use]
78
extern crate lazy_static;
89

0 commit comments

Comments
 (0)