Skip to content

Commit e62fd40

Browse files
committed
Remove unused exports from glue.{c,rs} && Fix some clippy warnings
1 parent 1c79f64 commit e62fd40

File tree

4 files changed

+26
-58
lines changed

4 files changed

+26
-58
lines changed

build/main.rs

Lines changed: 25 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#![allow(unreachable_code)]
22

33
use std::env;
4-
use std::io::{Error, ErrorKind, Result};
4+
use std::fs::File;
5+
use std::io::{Error, ErrorKind, Result, Write};
56
use std::path::{Path, PathBuf};
67
use std::process::Command;
78

@@ -96,51 +97,36 @@ fn build_glue<P: AsRef<Path> + std::fmt::Debug>(include_path: &P) {
9697
// If you're cross-compiling and using a non-vendored library then there is a chance
9798
// that the values selected here may be incorrect, but we have no way to determine
9899
// that here.
99-
fn generate_glue() -> std::io::Result<()> {
100-
use std::io::Write;
100+
fn generate_glue() -> Result<()> {
101101
let build_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
102-
let mut glue = std::fs::File::create(build_dir.join("glue.rs"))?;
103-
write!(
102+
let mut glue = File::create(build_dir.join("glue.rs"))?;
103+
writeln!(
104104
glue,
105-
"/* This file was generated by build/main.rs; do not modify by hand */\n"
105+
"/* This file was generated by build/main.rs; do not modify by hand */"
106106
)?;
107-
write!(glue, "use std::os::raw::*;\n")?;
108-
109-
// We can't statically determine the default paths.
110-
// It is possible though to use something like lazy_static! to create a new
111-
// lua context and extract that information.
112-
// For my (@wez) purposes, I actually don't want there to be a default path,
113-
// so I'm just leaving this blank for the moment.
114-
write!(glue, "pub const LUA_PATH_DEFAULT: &str = \"\";\n")?;
115-
write!(glue, "pub const LUA_CPATH_DEFAULT: &str = \"\";\n")?;
116-
117-
write!(
118-
glue,
119-
"#[cfg(windows)] pub const LUA_DIRSEP: &str = \"\\\\\";\n"
120-
)?;
121-
write!(glue, "#[cfg(unix)] pub const LUA_DIRSEP: &str = \"/\";\n")?;
107+
writeln!(glue, "use std::os::raw::*;")?;
122108

109+
writeln!(glue, "/* luaconf.h */")?;
123110
let pointer_bit_width: usize = env::var("CARGO_CFG_TARGET_POINTER_WIDTH")
124111
.unwrap()
125112
.parse()
126113
.unwrap();
127-
write!(
114+
writeln!(
128115
glue,
129-
"pub const LUA_EXTRASPACE: c_int = {} / 8;\n",
116+
"pub const LUA_EXTRASPACE: c_int = {} / 8;",
130117
pointer_bit_width
131118
)?;
132119

133120
// This is generally hardcoded to this size
134-
write!(glue, "pub const LUA_IDSIZE: c_int = 60;\n")?;
135-
136-
write!(glue, "pub const LUAL_BUFFERSIZE: c_int = 16 * ({} / 8) * std::mem::size_of::<LUA_NUMBER>() as c_int;\n", pointer_bit_width)?;
121+
writeln!(glue, "pub const LUA_IDSIZE: c_int = 60;")?;
137122

138123
// Unless the target is restricted, the defaults are 64 bit
139-
write!(glue, "pub type LUA_NUMBER = c_double;\n")?;
140-
write!(glue, "pub type LUA_INTEGER = i64;\n")?;
141-
write!(glue, "pub type LUA_UNSIGNED = u64;\n")?;
124+
writeln!(glue, "pub type LUA_NUMBER = c_double;")?;
125+
writeln!(glue, "pub type LUA_INTEGER = i64;")?;
126+
writeln!(glue, "pub type LUA_UNSIGNED = u64;")?;
142127

143-
let version = if cfg!(feature = "luajit") || cfg!(feature = "lua51") {
128+
writeln!(glue, "/* lua.h */")?;
129+
let version = if cfg!(any(feature = "luajit", feature = "lua51")) {
144130
(5, 1, 0)
145131
} else if cfg!(feature = "lua52") {
146132
(5, 2, 0)
@@ -151,43 +137,34 @@ fn generate_glue() -> std::io::Result<()> {
151137
} else {
152138
unreachable!();
153139
};
154-
155-
write!(
140+
writeln!(
156141
glue,
157-
"pub const LUA_VERSION_NUM: c_int = {};\n",
142+
"pub const LUA_VERSION_NUM: c_int = {};",
158143
(version.0 * 100) + version.1
159144
)?;
160-
write!(
161-
glue,
162-
"pub const LUA_VERSION: &str = \"Lua {}.{}\";\n",
163-
version.0, version.1
164-
)?;
165-
write!(
166-
glue,
167-
"pub const LUA_RELEASE: &str = \"Lua {}.{}.{}\";\n",
168-
version.0, version.1, version.2
169-
)?;
170145

171146
let max_stack = if pointer_bit_width >= 32 {
172147
1_000_000
173148
} else {
174149
15_000
175150
};
176-
write!(
151+
writeln!(
177152
glue,
178-
"pub const LUA_REGISTRYINDEX: c_int = -{} - 1000;\n",
153+
"pub const LUA_REGISTRYINDEX: c_int = -{} - 1000;",
179154
max_stack
180155
)?;
181156

182157
// These two are only defined in lua 5.1
183-
write!(glue, "pub const LUA_ENVIRONINDEX: c_int = -10001;\n")?;
184-
write!(glue, "pub const LUA_GLOBALSINDEX: c_int = -10002;\n")?;
158+
writeln!(glue, "pub const LUA_ENVIRONINDEX: c_int = -10001;")?;
159+
writeln!(glue, "pub const LUA_GLOBALSINDEX: c_int = -10002;")?;
185160

161+
writeln!(glue, "/* lauxlib.h */")?;
186162
// This is only defined in lua 5.3 and up, but we can always generate its value here,
187163
// even if we don't use it.
188164
// This matches the default definition in lauxlib.h
189-
write!(glue, "pub const LUAL_NUMSIZES: c_int = std::mem::size_of::<LUA_INTEGER>() as c_int * 16 + std::mem::size_of::<LUA_NUMBER>() as c_int;\n")?;
165+
writeln!(glue, "pub const LUAL_NUMSIZES: c_int = std::mem::size_of::<LUA_INTEGER>() as c_int * 16 + std::mem::size_of::<LUA_NUMBER>() as c_int;")?;
190166

167+
writeln!(glue, "/* lualib.h */")?;
191168
write!(
192169
glue,
193170
r#"

src/ffi/glue/glue.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,8 @@ int main(int argc, const char **argv) {
225225
// == luaconf.h ==========================================================
226226

227227
RS_COMMENT("luaconf.h"),
228-
RS_STR("LUA_PATH_DEFAULT", LUA_PATH_DEFAULT),
229-
RS_STR("LUA_CPATH_DEFAULT", LUA_CPATH_DEFAULT),
230-
RS_STR("LUA_DIRSEP", LUA_DIRSEP),
231228
RS_INT("LUA_EXTRASPACE", LUA_EXTRASPACE),
232229
RS_INT("LUA_IDSIZE", LUA_IDSIZE),
233-
RS_INT("LUAL_BUFFERSIZE", LUAL_BUFFERSIZE),
234230
RS_TYPE("LUA_NUMBER",
235231
sizeof(LUA_NUMBER) > sizeof(float) ? "c_double" : "c_float"),
236232
RS_TYPE("LUA_INTEGER", rs_int_type(sizeof(LUA_INTEGER))),
@@ -244,8 +240,6 @@ int main(int argc, const char **argv) {
244240

245241
RS_COMMENT("lua.h"),
246242
RS_INT("LUA_VERSION_NUM", LUA_VERSION_NUM),
247-
RS_STR("LUA_VERSION", LUA_VERSION),
248-
RS_STR("LUA_RELEASE", LUA_RELEASE),
249243
RS_INT("LUA_REGISTRYINDEX", LUA_REGISTRYINDEX),
250244
#if LUA_VERSION_NUM == 501
251245
RS_INT("LUA_ENVIRONINDEX", LUA_ENVIRONINDEX),

src/ffi/lua.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ use std::ptr;
3232

3333
use super::luaconf;
3434

35-
pub use super::glue::{LUA_RELEASE, LUA_VERSION, LUA_VERSION_NUM};
36-
37-
pub use super::glue::LUA_REGISTRYINDEX;
3835
#[cfg(any(feature = "lua51", feature = "luajit"))]
3936
pub use super::glue::{LUA_ENVIRONINDEX, LUA_GLOBALSINDEX};
37+
pub use super::glue::{LUA_REGISTRYINDEX, LUA_VERSION_NUM};
4038

4139
#[cfg(not(feature = "luajit"))]
4240
pub const LUA_SIGNATURE: &[u8] = b"\x1bLua";

src/ffi/luaconf.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
//! Contains definitions from `luaconf.h`.
2525
26-
pub use super::glue::LUAL_BUFFERSIZE;
2726
pub use super::glue::LUA_INTEGER;
2827
pub use super::glue::LUA_NUMBER;
2928
pub use super::glue::LUA_UNSIGNED;

0 commit comments

Comments
 (0)