Add LuaJIT support
This commit is contained in:
parent
29aa25a48b
commit
6f42a6cca9
|
@ -3,7 +3,7 @@ name = "mlua"
|
|||
version = "0.1.0"
|
||||
authors = ["Aleksandr Orlenko <zxteam@pm.me>", "kyren <catherine@chucklefish.org>"]
|
||||
edition = "2018"
|
||||
description = "High level bindings to Lua 5.3/5.1 for writing modules"
|
||||
description = "High level bindings to Lua 5.1 / LuaJIT / Lua 5.3"
|
||||
repository = "https://github.com/khvzak/mlua"
|
||||
documentation = "https://docs.rs/mlua"
|
||||
readme = "README.md"
|
||||
|
@ -21,6 +21,7 @@ members = [
|
|||
[features]
|
||||
default = ["lua53"]
|
||||
lua53 = []
|
||||
luajit = []
|
||||
|
||||
[dependencies]
|
||||
num-traits = { version = "0.2.6" }
|
||||
|
|
17
build.rs
17
build.rs
|
@ -107,6 +107,9 @@ fn main() {
|
|||
|
||||
// Find lua via pkg-config
|
||||
|
||||
#[cfg(all(feature = "lua53", feature = "luajit"))]
|
||||
panic!("Cannot enable lua53 and luajit simultaneously");
|
||||
|
||||
#[cfg(feature = "lua53")]
|
||||
{
|
||||
let mut lua = pkg_config::Config::new()
|
||||
|
@ -123,7 +126,7 @@ fn main() {
|
|||
};
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "lua53"))]
|
||||
#[cfg(all(not(feature = "lua53"), not(feature = "luajit")))]
|
||||
{
|
||||
let mut lua = pkg_config::Config::new()
|
||||
.range_version((Bound::Included("5.1"), Bound::Excluded("5.2")))
|
||||
|
@ -138,4 +141,16 @@ fn main() {
|
|||
Err(err) => panic!(err),
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(feature = "luajit")]
|
||||
{
|
||||
let lua = pkg_config::Config::new()
|
||||
.range_version((Bound::Included("2.0.5"), Bound::Excluded("2.1.0")))
|
||||
.probe("luajit");
|
||||
|
||||
match lua {
|
||||
Ok(lua) => build_glue(&lua.include_paths),
|
||||
Err(err) => panic!(err),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
#![cfg_attr(
|
||||
all(feature = "luajit", target_os = "macos", target_arch = "x86_64"),
|
||||
feature(link_args)
|
||||
)]
|
||||
|
||||
#[cfg_attr(
|
||||
all(feature = "luajit", target_os = "macos", target_arch = "x86_64"),
|
||||
link_args = "-pagezero_size 10000 -image_base 100000000"
|
||||
)]
|
||||
extern "system" {}
|
||||
|
||||
use bstr::{BStr, BString};
|
||||
use mlua::{Lua, Result};
|
||||
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
#![cfg_attr(
|
||||
all(feature = "luajit", target_os = "macos", target_arch = "x86_64"),
|
||||
feature(link_args)
|
||||
)]
|
||||
|
||||
#[cfg_attr(
|
||||
all(feature = "luajit", target_os = "macos", target_arch = "x86_64"),
|
||||
link_args = "-pagezero_size 10000 -image_base 100000000"
|
||||
)]
|
||||
extern "system" {}
|
||||
|
||||
use mlua::{Function, Lua, Result, String};
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
#![cfg_attr(
|
||||
all(feature = "luajit", target_os = "macos", target_arch = "x86_64"),
|
||||
feature(link_args)
|
||||
)]
|
||||
|
||||
#[cfg_attr(
|
||||
all(feature = "luajit", target_os = "macos", target_arch = "x86_64"),
|
||||
link_args = "-pagezero_size 10000 -image_base 100000000"
|
||||
)]
|
||||
extern "system" {}
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use mlua::{Lua, Result, UserData};
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
#![cfg_attr(
|
||||
all(feature = "luajit", target_os = "macos", target_arch = "x86_64"),
|
||||
feature(link_args)
|
||||
)]
|
||||
|
||||
#[cfg_attr(
|
||||
all(feature = "luajit", target_os = "macos", target_arch = "x86_64"),
|
||||
link_args = "-pagezero_size 10000 -image_base 100000000"
|
||||
)]
|
||||
extern "system" {}
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
#![cfg_attr(
|
||||
all(feature = "luajit", target_os = "macos", target_arch = "x86_64"),
|
||||
feature(link_args)
|
||||
)]
|
||||
|
||||
#[cfg_attr(
|
||||
all(feature = "luajit", target_os = "macos", target_arch = "x86_64"),
|
||||
link_args = "-pagezero_size 10000 -image_base 100000000"
|
||||
)]
|
||||
extern "system" {}
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
use mlua::{Lua, Result, String};
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
#![cfg_attr(
|
||||
all(feature = "luajit", target_os = "macos", target_arch = "x86_64"),
|
||||
feature(link_args)
|
||||
)]
|
||||
|
||||
#[cfg_attr(
|
||||
all(feature = "luajit", target_os = "macos", target_arch = "x86_64"),
|
||||
link_args = "-pagezero_size 10000 -image_base 100000000"
|
||||
)]
|
||||
extern "system" {}
|
||||
|
||||
use mlua::{Lua, Nil, Result, Table, Value};
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
#![cfg_attr(
|
||||
all(feature = "luajit", target_os = "macos", target_arch = "x86_64"),
|
||||
feature(link_args)
|
||||
)]
|
||||
|
||||
#[cfg_attr(
|
||||
all(feature = "luajit", target_os = "macos", target_arch = "x86_64"),
|
||||
link_args = "-pagezero_size 10000 -image_base 100000000"
|
||||
)]
|
||||
extern "system" {}
|
||||
|
||||
use std::iter::FromIterator;
|
||||
use std::panic::catch_unwind;
|
||||
use std::sync::Arc;
|
||||
|
@ -226,12 +237,12 @@ fn test_error() -> Result<()> {
|
|||
assert!(no_error.call::<_, ()>(()).is_ok());
|
||||
match lua_error.call::<_, ()>(()) {
|
||||
Err(Error::RuntimeError(_)) => {}
|
||||
Err(_) => panic!("error is not RuntimeError kind"),
|
||||
Err(e) => panic!("error is not RuntimeError kind, got {:?}", e),
|
||||
_ => panic!("error not returned"),
|
||||
}
|
||||
match rust_error.call::<_, ()>(()) {
|
||||
Err(Error::CallbackError { .. }) => {}
|
||||
Err(_) => panic!("error is not CallbackError kind"),
|
||||
Err(e) => panic!("error is not CallbackError kind, got {:?}", e),
|
||||
_ => panic!("error not returned"),
|
||||
}
|
||||
|
||||
|
@ -423,8 +434,8 @@ fn test_pcall_xpcall() -> Result<()> {
|
|||
assert!(lua.load("xpcall()").exec().is_err());
|
||||
assert!(lua.load("xpcall(function() end)").exec().is_err());
|
||||
|
||||
// Lua5.3 compatible version of xpcall
|
||||
#[cfg(not(feature = "lua53"))]
|
||||
// Lua 5.3 / LuaJIT compatible version of xpcall
|
||||
#[cfg(all(not(feature = "lua53"), not(feature = "luajit")))]
|
||||
lua.load(
|
||||
r#"
|
||||
local xpcall_orig = xpcall
|
||||
|
@ -466,9 +477,12 @@ fn test_pcall_xpcall() -> Result<()> {
|
|||
assert_eq!(globals.get::<_, String>("pcall_error")?, "testerror");
|
||||
|
||||
assert_eq!(globals.get::<_, bool>("xpcall_statusr")?, false);
|
||||
#[cfg(feature = "lua53")]
|
||||
assert_eq!(globals.get::<_, String>("xpcall_error")?, "testerror");
|
||||
#[cfg(not(feature = "lua53"))]
|
||||
#[cfg(any(feature = "lua53", feature = "luajit"))]
|
||||
assert_eq!(
|
||||
globals.get::<_, std::string::String>("xpcall_error")?,
|
||||
"testerror"
|
||||
);
|
||||
#[cfg(all(not(feature = "lua53"), not(feature = "luajit")))]
|
||||
assert!(globals
|
||||
.get::<_, String>("xpcall_error")?
|
||||
.to_str()?
|
||||
|
@ -653,6 +667,7 @@ fn too_many_arguments() -> Result<()> {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(feature = "luajit"))]
|
||||
fn too_many_recursions() -> Result<()> {
|
||||
let lua = Lua::new();
|
||||
let f = lua
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
#![cfg_attr(
|
||||
all(feature = "luajit", target_os = "macos", target_arch = "x86_64"),
|
||||
feature(link_args)
|
||||
)]
|
||||
|
||||
#[cfg_attr(
|
||||
all(feature = "luajit", target_os = "macos", target_arch = "x86_64"),
|
||||
link_args = "-pagezero_size 10000 -image_base 100000000"
|
||||
)]
|
||||
extern "system" {}
|
||||
|
||||
use std::panic::catch_unwind;
|
||||
|
||||
use mlua::{Error, Function, Lua, Result, Thread, ThreadStatus};
|
||||
|
@ -100,9 +111,9 @@ fn coroutine_from_closure() -> Result<()> {
|
|||
let thrd_main = lua.create_function(|_, ()| Ok(()))?;
|
||||
lua.globals().set("main", thrd_main)?;
|
||||
|
||||
#[cfg(feature = "lua53")]
|
||||
#[cfg(any(feature = "lua53", feature = "luajit"))]
|
||||
let thrd: Thread = lua.load("coroutine.create(main)").eval()?;
|
||||
#[cfg(not(feature = "lua53"))]
|
||||
#[cfg(all(not(feature = "lua53"), not(feature = "luajit")))]
|
||||
let thrd: Thread = lua
|
||||
.load("coroutine.create(function(...) return main(unpack(arg)) end)")
|
||||
.eval()?;
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
#![cfg_attr(
|
||||
all(feature = "luajit", target_os = "macos", target_arch = "x86_64"),
|
||||
feature(link_args)
|
||||
)]
|
||||
|
||||
#[cfg_attr(
|
||||
all(feature = "luajit", target_os = "macos", target_arch = "x86_64"),
|
||||
link_args = "-pagezero_size 10000 -image_base 100000000"
|
||||
)]
|
||||
extern "system" {}
|
||||
|
||||
use std::os::raw::c_void;
|
||||
|
||||
use mlua::{Function, LightUserData, Lua, Result};
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
#![cfg_attr(
|
||||
all(feature = "luajit", target_os = "macos", target_arch = "x86_64"),
|
||||
feature(link_args)
|
||||
)]
|
||||
|
||||
#[cfg_attr(
|
||||
all(feature = "luajit", target_os = "macos", target_arch = "x86_64"),
|
||||
link_args = "-pagezero_size 10000 -image_base 100000000"
|
||||
)]
|
||||
extern "system" {}
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use mlua::{
|
||||
|
|
Loading…
Reference in New Issue