summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Orlenko <zxteam@protonmail.com>2019-11-04 16:31:19 +0000
committerAlex Orlenko <zxteam@protonmail.com>2019-11-04 22:23:15 +0000
commitae677b0918179c98ecd747d6fd74f3d3883fc0bc (patch)
tree9ae6ee98c2ec42228c3664d4192a7a1f0ac94186 /src
parent6874c2e004f9fa92add76f1ddb4076bf80fd90ad (diff)
downloadmlua-ae677b0918179c98ecd747d6fd74f3d3883fc0bc.zip
Move lua 5.1 support under new "lua51" feature
Diffstat (limited to 'src')
-rw-r--r--src/ffi/lauxlib.rs10
-rw-r--r--src/ffi/lua.rs52
-rw-r--r--src/ffi/mod.rs6
-rw-r--r--src/lua.rs10
-rw-r--r--src/scope.rs4
-rw-r--r--src/userdata.rs4
-rw-r--r--src/util.rs6
7 files changed, 46 insertions, 46 deletions
diff --git a/src/ffi/lauxlib.rs b/src/ffi/lauxlib.rs
index 941755f..9eb0791 100644
--- a/src/ffi/lauxlib.rs
+++ b/src/ffi/lauxlib.rs
@@ -31,7 +31,7 @@ use super::lua::{self, lua_CFunction, lua_Integer, lua_Number, lua_State};
#[cfg(feature = "lua53")]
pub use super::glue::LUAL_NUMSIZES;
-#[cfg(not(feature = "lua53"))]
+#[cfg(any(feature = "lua51", feature = "luajit"))]
pub use super::compat53::{
luaL_checkversion, luaL_getmetafield, luaL_getsubtable, luaL_len, luaL_loadbufferx,
luaL_newmetatable, luaL_requiref, luaL_setfuncs, luaL_setmetatable, luaL_testudata,
@@ -63,7 +63,7 @@ extern "C" {
#[cfg(feature = "lua53")]
pub fn luaL_getmetafield(L: *mut lua_State, obj: c_int, e: *const c_char) -> c_int;
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
#[link_name = "luaL_getmetafield"]
pub fn luaL_getmetafield_51(L: *mut lua_State, obj: c_int, e: *const c_char) -> c_int;
@@ -89,7 +89,7 @@ extern "C" {
#[cfg(feature = "lua53")]
pub fn luaL_newmetatable(L: *mut lua_State, tname: *const c_char) -> c_int;
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
#[link_name = "luaL_newmetatable"]
pub fn luaL_newmetatable_51(L: *mut lua_State, tname: *const c_char) -> c_int;
@@ -127,7 +127,7 @@ extern "C" {
#[cfg(feature = "lua53")]
pub fn luaL_loadfilex(L: *mut lua_State, filename: *const c_char, mode: *const c_char)
-> c_int;
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
pub fn luaL_loadfile(L: *mut lua_State, filename: *const c_char) -> c_int;
}
@@ -146,7 +146,7 @@ extern "C" {
name: *const c_char,
mode: *const c_char,
) -> c_int;
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
pub fn luaL_loadbuffer(
L: *mut lua_State,
buff: *const c_char,
diff --git a/src/ffi/lua.rs b/src/ffi/lua.rs
index ae14a6b..7286841 100644
--- a/src/ffi/lua.rs
+++ b/src/ffi/lua.rs
@@ -33,7 +33,7 @@ use super::luaconf;
pub use super::glue::{LUA_RELEASE, LUA_VERSION, LUA_VERSION_NUM};
pub use super::glue::LUA_REGISTRYINDEX;
-#[cfg(not(feature = "lua53"))]
+#[cfg(any(feature = "lua51", feature = "luajit"))]
pub use super::glue::{LUA_ENVIRONINDEX, LUA_GLOBALSINDEX};
pub const LUA_SIGNATURE: &'static [u8] = b"\x1bLua";
@@ -41,7 +41,7 @@ pub const LUA_SIGNATURE: &'static [u8] = b"\x1bLua";
// option for multiple returns in 'lua_pcall' and 'lua_call'
pub const LUA_MULTRET: c_int = -1;
-#[cfg(not(feature = "lua53"))]
+#[cfg(any(feature = "lua51", feature = "luajit"))]
pub use super::compat53::{
lua_absindex, lua_compare, lua_copy, lua_getextraspace, lua_getfield, lua_geti, lua_gettable,
lua_getuservalue, lua_isinteger, lua_len, lua_pushglobaltable, lua_pushlstring, lua_pushstring,
@@ -63,7 +63,7 @@ pub const LUA_ERRSYNTAX: c_int = 3;
pub const LUA_ERRMEM: c_int = 4;
#[cfg(feature = "lua53")]
pub const LUA_ERRGCMM: c_int = 5;
-#[cfg(not(feature = "lua53"))]
+#[cfg(any(feature = "lua51", feature = "luajit"))]
pub const LUA_ERRERR: c_int = 5;
#[cfg(feature = "lua53")]
pub const LUA_ERRERR: c_int = 6;
@@ -150,11 +150,11 @@ extern "C" {
pub fn lua_gettop(L: *mut lua_State) -> c_int;
pub fn lua_settop(L: *mut lua_State, idx: c_int);
pub fn lua_pushvalue(L: *mut lua_State, idx: c_int);
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
pub fn lua_remove(L: *mut lua_State, idx: c_int);
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
pub fn lua_insert(L: *mut lua_State, idx: c_int);
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
pub fn lua_replace(L: *mut lua_State, idx: c_int);
#[cfg(feature = "lua53")]
pub fn lua_rotate(L: *mut lua_State, idx: c_int, n: c_int);
@@ -174,17 +174,17 @@ extern "C" {
pub fn lua_type(L: *mut lua_State, idx: c_int) -> c_int;
pub fn lua_typename(L: *mut lua_State, tp: c_int) -> *const c_char;
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
pub fn lua_tonumber(L: *mut lua_State, idx: c_int) -> lua_Number;
#[cfg(feature = "lua53")]
pub fn lua_tonumberx(L: *mut lua_State, idx: c_int, isnum: *mut c_int) -> lua_Number;
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
pub fn lua_tointeger(L: *mut lua_State, idx: c_int) -> lua_Integer;
#[cfg(feature = "lua53")]
pub fn lua_tointegerx(L: *mut lua_State, idx: c_int, isnum: *mut c_int) -> lua_Integer;
pub fn lua_toboolean(L: *mut lua_State, idx: c_int) -> c_int;
pub fn lua_tolstring(L: *mut lua_State, idx: c_int, len: *mut usize) -> *const c_char;
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
pub fn lua_objlen(L: *mut lua_State, idx: c_int) -> usize;
#[cfg(feature = "lua53")]
pub fn lua_rawlen(L: *mut lua_State, idx: c_int) -> usize;
@@ -234,10 +234,10 @@ pub const LUA_OPLT: c_int = 1;
pub const LUA_OPLE: c_int = 2;
extern "C" {
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
pub fn lua_equal(L: *mut lua_State, idx1: c_int, idx2: c_int) -> c_int;
pub fn lua_rawequal(L: *mut lua_State, idx1: c_int, idx2: c_int) -> c_int;
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
pub fn lua_lessthan(L: *mut lua_State, idx1: c_int, idx2: c_int) -> c_int;
#[cfg(feature = "lua53")]
pub fn lua_compare(L: *mut lua_State, idx1: c_int, idx2: c_int, op: c_int) -> c_int;
@@ -251,13 +251,13 @@ extern "C" {
#[cfg(feature = "lua53")]
pub fn lua_pushlstring(L: *mut lua_State, s: *const c_char, l: usize) -> *const c_char;
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
#[link_name = "lua_pushlstring"]
pub fn lua_pushlstring_51(L: *mut lua_State, s: *const c_char, l: usize) -> *const c_char;
#[cfg(feature = "lua53")]
pub fn lua_pushstring(L: *mut lua_State, s: *const c_char) -> *const c_char;
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
#[link_name = "lua_pushstring"]
pub fn lua_pushstring_51(L: *mut lua_State, s: *const c_char) -> *const c_char;
@@ -277,13 +277,13 @@ extern "C" {
#[cfg(feature = "lua53")]
pub fn lua_gettable(L: *mut lua_State, idx: c_int) -> c_int;
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
#[link_name = "lua_gettable"]
pub fn lua_gettable_51(L: *mut lua_State, idx: c_int) -> c_int;
#[cfg(feature = "lua53")]
pub fn lua_getfield(L: *mut lua_State, idx: c_int, k: *const c_char) -> c_int;
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
#[link_name = "lua_getfield"]
pub fn lua_getfield_51(L: *mut lua_State, idx: c_int, k: *const c_char) -> c_int;
@@ -292,13 +292,13 @@ extern "C" {
#[cfg(feature = "lua53")]
pub fn lua_rawget(L: *mut lua_State, idx: c_int) -> c_int;
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
#[link_name = "lua_rawget"]
pub fn lua_rawget_51(L: *mut lua_State, idx: c_int);
#[cfg(feature = "lua53")]
pub fn lua_rawgeti(L: *mut lua_State, idx: c_int, n: lua_Integer) -> c_int;
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
#[link_name = "lua_rawgeti"]
pub fn lua_rawgeti_51(L: *mut lua_State, idx: c_int, n: lua_Integer);
@@ -310,7 +310,7 @@ extern "C" {
pub fn lua_getmetatable(L: *mut lua_State, objindex: c_int) -> c_int;
#[cfg(feature = "lua53")]
pub fn lua_getuservalue(L: *mut lua_State, idx: c_int) -> c_int;
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
pub fn lua_getfenv(L: *mut lua_State, idx: c_int);
}
@@ -329,7 +329,7 @@ extern "C" {
pub fn lua_setmetatable(L: *mut lua_State, objindex: c_int) -> c_int;
#[cfg(feature = "lua53")]
pub fn lua_setuservalue(L: *mut lua_State, idx: c_int);
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
pub fn lua_setfenv(L: *mut lua_State, idx: c_int) -> c_int;
}
@@ -352,9 +352,9 @@ extern "C" {
ctx: lua_KContext,
k: Option<lua_KFunction>,
) -> c_int;
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
pub fn lua_call(L: *mut lua_State, nargs: c_int, nresults: c_int);
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
pub fn lua_pcall(L: *mut lua_State, nargs: c_int, nresults: c_int, errfunc: c_int) -> c_int;
pub fn lua_load(
L: *mut lua_State,
@@ -393,12 +393,12 @@ extern "C" {
ctx: lua_KContext,
k: Option<lua_KFunction>,
) -> c_int;
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
pub fn lua_yield(L: *mut lua_State, nresults: c_int) -> c_int;
#[cfg(feature = "lua53")]
pub fn lua_resume(L: *mut lua_State, from: *mut lua_State, narg: c_int) -> c_int;
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
#[link_name = "lua_resume"]
pub fn lua_resume_51(L: *mut lua_State, narg: c_int) -> c_int;
@@ -530,13 +530,13 @@ pub unsafe fn lua_pushliteral(L: *mut lua_State, s: &'static str) -> *const c_ch
lua_pushlstring(L, c_str.as_ptr(), c_str.as_bytes().len())
}
-#[cfg(not(feature = "lua53"))]
+#[cfg(any(feature = "lua51", feature = "luajit"))]
#[inline(always)]
pub unsafe fn lua_setglobal(L: *mut lua_State, var: *const c_char) {
lua_setfield(L, LUA_GLOBALSINDEX, var)
}
-#[cfg(not(feature = "lua53"))]
+#[cfg(any(feature = "lua51", feature = "luajit"))]
#[inline(always)]
pub unsafe fn lua_getglobal(L: *mut lua_State, var: *const c_char) -> c_int {
lua_getfield(L, LUA_GLOBALSINDEX, var)
@@ -629,7 +629,7 @@ pub struct lua_Debug {
i_ci: *mut c_void,
}
-#[cfg(not(feature = "lua53"))]
+#[cfg(any(feature = "lua51", feature = "luajit"))]
#[repr(C)]
pub struct lua_Debug {
pub event: c_int,
diff --git a/src/ffi/mod.rs b/src/ffi/mod.rs
index 14ac3c0..8a4ecaa 100644
--- a/src/ffi/mod.rs
+++ b/src/ffi/mod.rs
@@ -39,7 +39,7 @@ pub use self::lua::{
#[cfg(feature = "lua53")]
pub use self::lua::{lua_KContext, lua_KFunction, lua_Unsigned};
-#[cfg(not(feature = "lua53"))]
+#[cfg(any(feature = "lua51", feature = "luajit"))]
pub use self::lua::lua_setfenv;
// C API functions
@@ -203,7 +203,7 @@ pub use self::lua::{
LUA_OPUNM, LUA_RIDX_GLOBALS, LUA_RIDX_MAINTHREAD,
};
-#[cfg(not(feature = "lua53"))]
+#[cfg(any(feature = "lua51", feature = "luajit"))]
pub use self::lua::{LUA_ENVIRONINDEX, LUA_GLOBALSINDEX};
// constants from lauxlib.h
@@ -226,7 +226,7 @@ mod glue {
include!(concat!(env!("OUT_DIR"), "/glue.rs"));
}
-#[cfg(not(feature = "lua53"))]
+#[cfg(any(feature = "lua51", feature = "luajit"))]
mod compat53;
mod lauxlib;
diff --git a/src/lua.rs b/src/lua.rs
index 71e131d..9b8d7d4 100644
--- a/src/lua.rs
+++ b/src/lua.rs
@@ -16,7 +16,7 @@ use crate::table::Table;
use crate::thread::Thread;
use crate::types::{Callback, Integer, LightUserData, LuaRef, Number, RegistryKey};
use crate::userdata::{AnyUserData, MetaMethod, UserData, UserDataMethods};
-#[cfg(not(feature = "lua53"))]
+#[cfg(any(feature = "lua51", feature = "luajit"))]
use crate::util::set_main_state;
use crate::util::{
assert_stack, callback_error, check_stack, get_main_state, get_userdata, get_wrapped_error,
@@ -84,7 +84,7 @@ impl Lua {
ffi::luaL_requiref(state, cstr!("package"), ffi::luaopen_package, 1);
#[cfg(feature = "lua53")]
ffi::lua_pop(state, 9);
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
ffi::lua_pop(state, 7);
let mut lua = Lua::init_from_ptr(state);
@@ -97,7 +97,7 @@ impl Lua {
pub unsafe fn init_from_ptr(state: *mut ffi::lua_State) -> Lua {
#[cfg(feature = "lua53")]
let main_state = get_main_state(state);
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
let main_state = {
set_main_state(state);
state
@@ -316,7 +316,7 @@ impl Lua {
self.push_value(env)?;
#[cfg(feature = "lua53")]
ffi::lua_setupvalue(self.state, -2, 1);
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
ffi::lua_setfenv(self.state, -2);
}
Ok(Function(self.pop_ref()))
@@ -507,7 +507,7 @@ impl Lua {
assert_stack(self.state, 2);
#[cfg(feature = "lua53")]
ffi::lua_rawgeti(self.state, ffi::LUA_REGISTRYINDEX, ffi::LUA_RIDX_GLOBALS);
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
ffi::lua_pushvalue(self.state, ffi::LUA_GLOBALSINDEX);
Table(self.pop_ref())
}
diff --git a/src/scope.rs b/src/scope.rs
index 2c88083..aecf38c 100644
--- a/src/scope.rs
+++ b/src/scope.rs
@@ -175,7 +175,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
assert_stack(lua.state, 1);
lua.push_ref(&u.0);
ffi::lua_getuservalue(lua.state, -1);
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
{
ffi::lua_pushinteger(lua.state, 1);
ffi::lua_gettable(lua.state, -2);
@@ -247,7 +247,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
push_userdata(lua.state, ())?;
#[cfg(feature = "lua53")]
ffi::lua_pushlightuserdata(lua.state, data.as_ptr() as *mut c_void);
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
protect_lua_closure(lua.state, 0, 1, |state| {
// Lua 5.1 allows to store only table. Then we will wrap the value.
ffi::lua_createtable(state, 1, 0);
diff --git a/src/userdata.rs b/src/userdata.rs
index bc6b62e..15c200e 100644
--- a/src/userdata.rs
+++ b/src/userdata.rs
@@ -333,7 +333,7 @@ impl<'lua> AnyUserData<'lua> {
/// [`get_user_value`]: #method.get_user_value
pub fn set_user_value<V: ToLua<'lua>>(&self, v: V) -> Result<()> {
let lua = self.0.lua;
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
let v = {
// Lua 5.1 allows to store only table. Then we will wrap the value.
let t = lua.create_table()?;
@@ -364,7 +364,7 @@ impl<'lua> AnyUserData<'lua> {
ffi::lua_getuservalue(lua.state, -1);
lua.pop_value()
};
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
return crate::Table::from_lua(res, lua)?.get(1);
#[cfg(feature = "lua53")]
V::from_lua(res, lua)
diff --git a/src/util.rs b/src/util.rs
index 4e0b64f..d8b9c50 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -444,7 +444,7 @@ pub unsafe extern "C" fn error_traceback(state: *mut ffi::lua_State) -> c_int {
}
// Does not call lua_checkstack, uses 2 stack spaces.
-#[cfg(not(feature = "lua53"))]
+#[cfg(any(feature = "lua51", feature = "luajit"))]
pub unsafe fn set_main_state(state: *mut ffi::lua_State) {
ffi::lua_pushlightuserdata(state, &MAIN_THREAD_REGISTRY_KEY as *const u8 as *mut c_void);
ffi::lua_pushthread(state);
@@ -455,7 +455,7 @@ pub unsafe fn set_main_state(state: *mut ffi::lua_State) {
pub unsafe fn get_main_state(state: *mut ffi::lua_State) -> *mut ffi::lua_State {
#[cfg(feature = "lua53")]
ffi::lua_rawgeti(state, ffi::LUA_REGISTRYINDEX, ffi::LUA_RIDX_MAINTHREAD);
- #[cfg(not(feature = "lua53"))]
+ #[cfg(any(feature = "lua51", feature = "luajit"))]
{
ffi::lua_pushlightuserdata(state, &MAIN_THREAD_REGISTRY_KEY as *const u8 as *mut c_void);
ffi::lua_rawget(state, ffi::LUA_REGISTRYINDEX);
@@ -751,7 +751,7 @@ unsafe fn get_destructed_userdata_metatable(state: *mut ffi::lua_State) {
ffi::lua_rawget(state, ffi::LUA_REGISTRYINDEX);
}
-#[cfg(not(feature = "lua53"))]
+#[cfg(any(feature = "lua51", feature = "luajit"))]
static MAIN_THREAD_REGISTRY_KEY: u8 = 0;
static ERROR_METATABLE_REGISTRY_KEY: u8 = 0;
static PANIC_METATABLE_REGISTRY_KEY: u8 = 0;