Skip to content

Commit 7087ada

Browse files
author
Kingfree
committed
add feature ucid for lua54 unicode identifiers
1 parent 60ec5f1 commit 7087ada

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ description = """
1111
Sources of Lua 5.1/5.2/5.3/5.4 and logic to build them.
1212
"""
1313

14+
[features]
15+
ucid = [] # accept UniCode IDentifiers
16+
1417
[workspace]
1518
members = ["testcrate"]
1619

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ impl Build {
108108

109109
if let Lua54 = version {
110110
config.define("LUA_COMPAT_5_3", None);
111+
#[cfg(feature = "ucid")]
112+
config.define("LUA_UCID", None);
111113
}
112114

113115
if cfg!(debug_assertions) {

testcrate/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ lua53 = []
1010
lua52 = []
1111
lua51 = []
1212

13-
[build-dependencies]
14-
lua-src = { path = ".." }
13+
[build-dependencies.lua-src]
14+
path = ".."
15+
features = ["ucid"]

testcrate/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ extern "C" {
55
pub fn luaL_openlibs(state: *mut c_void);
66
pub fn lua_getfield(state: *mut c_void, index: c_int, k: *const c_char);
77
pub fn lua_tolstring(state: *mut c_void, index: c_int, len: *mut c_long) -> *const c_char;
8+
pub fn luaL_loadstring(state: *mut c_void, s: *const c_char) -> c_int;
89

910
#[cfg(any(feature = "lua52", feature = "lua53", feature = "lua54"))]
1011
pub fn lua_getglobal(state: *mut c_void, k: *const c_char);
@@ -41,3 +42,16 @@ fn lua_works() {
4142
assert_eq!(version, "Lua 5.4".as_bytes());
4243
}
4344
}
45+
46+
#[test]
47+
fn unicode_identifiers() {
48+
unsafe {
49+
let state = luaL_newstate();
50+
let code = "local 😀 = 0\n";
51+
let ret = luaL_loadstring(state, code.as_ptr().cast());
52+
#[cfg(feature = "lua54")]
53+
assert_eq!(0, ret);
54+
#[cfg(not(feature = "lua54"))]
55+
assert_ne!(0, ret);
56+
}
57+
}

0 commit comments

Comments
 (0)