Skip to content

Commit 0ed11e4

Browse files
committed
Add initial pluto support
Pluto is a superset of Lua 5.4 with a focus on general-purpose programming. `pluto` feature also enables `lua54` feature since they are compatible and share the same API.
1 parent 0ce599a commit 0ed11e4

File tree

18 files changed

+251
-102
lines changed

18 files changed

+251
-102
lines changed

.github/workflows/main.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
matrix:
1010
os: [ubuntu-latest, macos-latest, windows-latest]
1111
rust: [stable]
12-
lua: [lua54, lua53, lua52, lua51, luajit, luau, luau-jit, luau-vector4]
12+
lua: [lua54, lua53, lua52, lua51, luajit, luau, luau-jit, luau-vector4, pluto]
1313
include:
1414
- os: ubuntu-latest
1515
target: x86_64-unknown-linux-gnu
@@ -105,7 +105,7 @@ jobs:
105105
matrix:
106106
os: [ubuntu-latest, macos-latest, windows-latest]
107107
rust: [stable, nightly]
108-
lua: [lua54, lua53, lua52, lua51, luajit, luajit52, luau, luau-jit, luau-vector4]
108+
lua: [lua54, lua53, lua52, lua51, luajit, luajit52, luau, luau-jit, luau-vector4, pluto]
109109
include:
110110
- os: ubuntu-latest
111111
target: x86_64-unknown-linux-gnu
@@ -141,7 +141,7 @@ jobs:
141141
matrix:
142142
os: [ubuntu-latest]
143143
rust: [nightly]
144-
lua: [lua54, lua53, lua52, lua51, luajit, luau, luau-jit, luau-vector4]
144+
lua: [lua54, lua53, lua52, lua51, luajit, luau, luau-jit, luau-vector4, pluto]
145145
include:
146146
- os: ubuntu-latest
147147
target: x86_64-unknown-linux-gnu
@@ -168,7 +168,7 @@ jobs:
168168
matrix:
169169
os: [ubuntu-latest]
170170
rust: [nightly]
171-
lua: [lua54, lua53, lua52, lua51, luajit, luau, luau-jit, luau-vector4]
171+
lua: [lua54, lua53, lua52, lua51, luajit, luau, luau-jit, luau-vector4, pluto]
172172
include:
173173
- os: ubuntu-latest
174174
target: x86_64-unknown-linux-gnu
@@ -271,7 +271,7 @@ jobs:
271271
runs-on: ubuntu-latest
272272
strategy:
273273
matrix:
274-
lua: [lua54, lua53, lua52, lua51, luajit, luau, luau-jit, luau-vector4]
274+
lua: [lua54, lua53, lua52, lua51, luajit, luau, luau-jit, luau-vector4, pluto]
275275
steps:
276276
- uses: actions/checkout@main
277277
- uses: dtolnay/rust-toolchain@stable

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ luajit52 = ["luajit", "ffi/luajit52"]
3535
luau = ["ffi/luau", "dep:libloading"]
3636
luau-jit = ["luau", "ffi/luau-codegen"]
3737
luau-vector4 = ["luau", "ffi/luau-vector4"]
38+
pluto = ["lua54", "ffi/pluto"]
3839
vendored = ["ffi/vendored"]
3940
module = ["dep:mlua_derive", "ffi/module"]
4041
async = ["dep:futures-util"]

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Below is a list of the available feature flags. By default `mlua` does not enabl
5151
* `luau`: enable [Luau] support (auto vendored mode)
5252
* `luau-jit`: enable [Luau] support with JIT backend.
5353
* `luau-vector4`: enable [Luau] support with 4-dimensional vector.
54+
* `pluto`: enable [Pluto] support (Lua 5.4 dialect, auto vendored mode)
5455
* `vendored`: build static Lua(JIT) library from sources during `mlua` compilation using [lua-src] or [luajit-src] crates
5556
* `module`: enable module mode (building loadable `cdylib` library for Lua)
5657
* `async`: enable async/await support (any executor can be used, eg. [tokio] or [async-std])
@@ -67,6 +68,7 @@ Below is a list of the available feature flags. By default `mlua` does not enabl
6768
[5.1]: https://www.lua.org/manual/5.1/manual.html
6869
[LuaJIT]: https://luajit.org/
6970
[Luau]: https://github.com/luau-lang/luau
71+
[Pluto]: https://github.com/PlutoLang/Pluto
7072
[lua-src]: https://github.com/khvzak/lua-src-rs
7173
[luajit-src]: https://github.com/khvzak/luajit-src-rs
7274
[tokio]: https://github.com/tokio-rs/tokio

mlua-sys/Cargo.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ lua52 = []
2626
lua51 = []
2727
luajit = []
2828
luajit52 = ["luajit"]
29-
luau = ["luau0-src"]
29+
luau = ["dep:luau0-src"]
3030
luau-codegen = ["luau"]
3131
luau-vector4 = ["luau"]
32-
vendored = ["lua-src", "luajit-src"]
32+
pluto = ["lua54", "dep:pluto-src"]
33+
vendored = ["dep:lua-src", "dep:luajit-src"]
3334
module = []
3435

3536
[dependencies]
@@ -41,6 +42,7 @@ pkg-config = "0.3.17"
4142
lua-src = { version = ">= 547.0.0, < 547.1.0", optional = true }
4243
luajit-src = { version = ">= 210.5.0, < 210.6.0", optional = true }
4344
luau0-src = { version = "0.12.0", optional = true }
45+
pluto-src = { version = "0.1.1", optional = true }
4446

4547
[lints.rust]
4648
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(raw_dylib)'] }

mlua-sys/build/find_vendored.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(dead_code)]
22

33
pub fn probe_lua() {
4-
#[cfg(feature = "lua54")]
4+
#[cfg(all(feature = "lua54", not(feature = "pluto")))]
55
let artifacts = lua_src::Build::new().build(lua_src::Lua54);
66

77
#[cfg(feature = "lua53")]
@@ -25,5 +25,8 @@ pub fn probe_lua() {
2525
.set_vector_size(if cfg!(feature = "luau-vector4") { 4 } else { 3 })
2626
.build();
2727

28+
#[cfg(feature = "pluto")]
29+
let artifacts = pluto_src::Build::new().use_longjmp(true).build();
30+
2831
artifacts.print_cargo_metadata();
2932
}

mlua-sys/build/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ cfg_if::cfg_if! {
1313
include!("main_inner.rs");
1414
} else {
1515
fn main() {
16-
compile_error!("You can enable only one of the features: lua54, lua53, lua52, lua51, luajit, luajit52, luau");
16+
compile_error!("You can enable only one of the features: lua54, lua53, lua52, lua51, luajit, luajit52, luau, pluto");
1717
}
1818
}
1919
}

mlua-sys/build/main_inner.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::env;
22

33
cfg_if::cfg_if! {
4-
if #[cfg(any(feature = "luau", feature = "vendored"))] {
4+
if #[cfg(any(feature = "luau", feature = "pluto", feature = "vendored"))] {
55
#[path = "find_vendored.rs"]
66
mod find;
77
} else {

mlua-sys/src/lua51/lualib.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
//! Contains definitions from `lualib.h`.
22
3-
use std::os::raw::c_int;
3+
use std::os::raw::{c_char, c_int};
44

55
use super::lua::lua_State;
66

7-
pub const LUA_COLIBNAME: &str = "coroutine";
8-
pub const LUA_TABLIBNAME: &str = "table";
9-
pub const LUA_IOLIBNAME: &str = "io";
10-
pub const LUA_OSLIBNAME: &str = "os";
11-
pub const LUA_STRLIBNAME: &str = "string";
12-
pub const LUA_MATHLIBNAME: &str = "math";
13-
pub const LUA_DBLIBNAME: &str = "debug";
14-
pub const LUA_LOADLIBNAME: &str = "package";
7+
pub const LUA_COLIBNAME: *const c_char = cstr!("coroutine");
8+
pub const LUA_TABLIBNAME: *const c_char = cstr!("table");
9+
pub const LUA_IOLIBNAME: *const c_char = cstr!("io");
10+
pub const LUA_OSLIBNAME: *const c_char = cstr!("os");
11+
pub const LUA_STRLIBNAME: *const c_char = cstr!("string");
12+
pub const LUA_MATHLIBNAME: *const c_char = cstr!("math");
13+
pub const LUA_DBLIBNAME: *const c_char = cstr!("debug");
14+
pub const LUA_LOADLIBNAME: *const c_char = cstr!("package");
1515

1616
#[cfg(feature = "luajit")]
17-
pub const LUA_BITLIBNAME: &str = "bit";
17+
pub const LUA_BITLIBNAME: *const c_char = cstr!("bit");
1818
#[cfg(feature = "luajit")]
19-
pub const LUA_JITLIBNAME: &str = "jit";
19+
pub const LUA_JITLIBNAME: *const c_char = cstr!("jit");
2020
#[cfg(feature = "luajit")]
21-
pub const LUA_FFILIBNAME: &str = "ffi";
21+
pub const LUA_FFILIBNAME: *const c_char = cstr!("ffi");
2222

2323
#[cfg_attr(all(windows, raw_dylib), link(name = "lua51", kind = "raw-dylib"))]
2424
extern "C-unwind" {

mlua-sys/src/lua52/lualib.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
//! Contains definitions from `lualib.h`.
22
3-
use std::os::raw::c_int;
3+
use std::os::raw::{c_char, c_int};
44

55
use super::lua::lua_State;
66

7-
pub const LUA_COLIBNAME: &str = "coroutine";
8-
pub const LUA_TABLIBNAME: &str = "table";
9-
pub const LUA_IOLIBNAME: &str = "io";
10-
pub const LUA_OSLIBNAME: &str = "os";
11-
pub const LUA_STRLIBNAME: &str = "string";
12-
pub const LUA_BITLIBNAME: &str = "bit32";
13-
pub const LUA_MATHLIBNAME: &str = "math";
14-
pub const LUA_DBLIBNAME: &str = "debug";
15-
pub const LUA_LOADLIBNAME: &str = "package";
7+
pub const LUA_COLIBNAME: *const c_char = cstr!("coroutine");
8+
pub const LUA_TABLIBNAME: *const c_char = cstr!("table");
9+
pub const LUA_IOLIBNAME: *const c_char = cstr!("io");
10+
pub const LUA_OSLIBNAME: *const c_char = cstr!("os");
11+
pub const LUA_STRLIBNAME: *const c_char = cstr!("string");
12+
pub const LUA_BITLIBNAME: *const c_char = cstr!("bit32");
13+
pub const LUA_MATHLIBNAME: *const c_char = cstr!("math");
14+
pub const LUA_DBLIBNAME: *const c_char = cstr!("debug");
15+
pub const LUA_LOADLIBNAME: *const c_char = cstr!("package");
1616

1717
#[cfg_attr(all(windows, raw_dylib), link(name = "lua52", kind = "raw-dylib"))]
1818
extern "C-unwind" {

mlua-sys/src/lua53/lauxlib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use super::lua::{self, lua_CFunction, lua_Integer, lua_Number, lua_State};
99
pub const LUA_ERRFILE: c_int = lua::LUA_ERRERR + 1;
1010

1111
// Key, in the registry, for table of loaded modules
12-
pub const LUA_LOADED_TABLE: &str = "_LOADED";
12+
pub const LUA_LOADED_TABLE: *const c_char = cstr!("_LOADED");
1313

1414
// Key, in the registry, for table of preloaded loaders
15-
pub const LUA_PRELOAD_TABLE: &str = "_PRELOAD";
15+
pub const LUA_PRELOAD_TABLE: *const c_char = cstr!("_PRELOAD");
1616

1717
#[repr(C)]
1818
pub struct luaL_Reg {

mlua-sys/src/lua53/lualib.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
//! Contains definitions from `lualib.h`.
22
3-
use std::os::raw::c_int;
3+
use std::os::raw::{c_char, c_int};
44

55
use super::lua::lua_State;
66

7-
pub const LUA_COLIBNAME: &str = "coroutine";
8-
pub const LUA_TABLIBNAME: &str = "table";
9-
pub const LUA_IOLIBNAME: &str = "io";
10-
pub const LUA_OSLIBNAME: &str = "os";
11-
pub const LUA_STRLIBNAME: &str = "string";
12-
pub const LUA_UTF8LIBNAME: &str = "utf8";
13-
pub const LUA_BITLIBNAME: &str = "bit32";
14-
pub const LUA_MATHLIBNAME: &str = "math";
15-
pub const LUA_DBLIBNAME: &str = "debug";
16-
pub const LUA_LOADLIBNAME: &str = "package";
7+
pub const LUA_COLIBNAME: *const c_char = cstr!("coroutine");
8+
pub const LUA_TABLIBNAME: *const c_char = cstr!("table");
9+
pub const LUA_IOLIBNAME: *const c_char = cstr!("io");
10+
pub const LUA_OSLIBNAME: *const c_char = cstr!("os");
11+
pub const LUA_STRLIBNAME: *const c_char = cstr!("string");
12+
pub const LUA_UTF8LIBNAME: *const c_char = cstr!("utf8");
13+
pub const LUA_BITLIBNAME: *const c_char = cstr!("bit32");
14+
pub const LUA_MATHLIBNAME: *const c_char = cstr!("math");
15+
pub const LUA_DBLIBNAME: *const c_char = cstr!("debug");
16+
pub const LUA_LOADLIBNAME: *const c_char = cstr!("package");
1717

1818
#[cfg_attr(all(windows, raw_dylib), link(name = "lua53", kind = "raw-dylib"))]
1919
extern "C-unwind" {

mlua-sys/src/lua54/lauxlib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use super::lua::{self, lua_CFunction, lua_Integer, lua_Number, lua_State};
99
pub const LUA_ERRFILE: c_int = lua::LUA_ERRERR + 1;
1010

1111
// Key, in the registry, for table of loaded modules
12-
pub const LUA_LOADED_TABLE: &str = "_LOADED";
12+
pub const LUA_LOADED_TABLE: *const c_char = cstr!("_LOADED");
1313

1414
// Key, in the registry, for table of preloaded loaders
15-
pub const LUA_PRELOAD_TABLE: &str = "_PRELOAD";
15+
pub const LUA_PRELOAD_TABLE: *const c_char = cstr!("_PRELOAD");
1616

1717
#[repr(C)]
1818
pub struct luaL_Reg {

mlua-sys/src/lua54/lualib.rs

+30-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
//! Contains definitions from `lualib.h`.
22
3-
use std::os::raw::c_int;
3+
use std::os::raw::{c_char, c_int};
44

55
use super::lua::lua_State;
66

7-
pub const LUA_COLIBNAME: &str = "coroutine";
8-
pub const LUA_TABLIBNAME: &str = "table";
9-
pub const LUA_IOLIBNAME: &str = "io";
10-
pub const LUA_OSLIBNAME: &str = "os";
11-
pub const LUA_STRLIBNAME: &str = "string";
12-
pub const LUA_UTF8LIBNAME: &str = "utf8";
13-
pub const LUA_MATHLIBNAME: &str = "math";
14-
pub const LUA_DBLIBNAME: &str = "debug";
15-
pub const LUA_LOADLIBNAME: &str = "package";
7+
pub const LUA_COLIBNAME: *const c_char = cstr!("coroutine");
8+
pub const LUA_TABLIBNAME: *const c_char = cstr!("table");
9+
pub const LUA_IOLIBNAME: *const c_char = cstr!("io");
10+
pub const LUA_OSLIBNAME: *const c_char = cstr!("os");
11+
pub const LUA_STRLIBNAME: *const c_char = cstr!("string");
12+
pub const LUA_UTF8LIBNAME: *const c_char = cstr!("utf8");
13+
pub const LUA_MATHLIBNAME: *const c_char = cstr!("math");
14+
pub const LUA_DBLIBNAME: *const c_char = cstr!("debug");
15+
pub const LUA_LOADLIBNAME: *const c_char = cstr!("package");
1616

1717
#[cfg_attr(all(windows, raw_dylib), link(name = "lua54", kind = "raw-dylib"))]
1818
extern "C-unwind" {
@@ -30,3 +30,23 @@ extern "C-unwind" {
3030
// open all builtin libraries
3131
pub fn luaL_openlibs(L: *mut lua_State);
3232
}
33+
34+
#[cfg(feature = "pluto")]
35+
extern "C-unwind" {
36+
pub fn luaopen_assert(L: *mut lua_State) -> c_int;
37+
pub fn luaopen_base32(L: *mut lua_State) -> c_int;
38+
pub fn luaopen_base64(L: *mut lua_State) -> c_int;
39+
pub fn luaopen_bigint(L: *mut lua_State) -> c_int;
40+
pub fn luaopen_cat(L: *mut lua_State) -> c_int;
41+
pub fn luaopen_canvas(L: *mut lua_State) -> c_int;
42+
pub fn luaopen_crypto(L: *mut lua_State) -> c_int;
43+
pub fn luaopen_ffi(L: *mut lua_State) -> c_int;
44+
pub fn luaopen_http(L: *mut lua_State) -> c_int;
45+
pub fn luaopen_json(L: *mut lua_State) -> c_int;
46+
pub fn luaopen_regex(L: *mut lua_State) -> c_int;
47+
pub fn luaopen_scheduler(L: *mut lua_State) -> c_int;
48+
pub fn luaopen_socket(L: *mut lua_State) -> c_int;
49+
pub fn luaopen_url(L: *mut lua_State) -> c_int;
50+
pub fn luaopen_vector3(L: *mut lua_State) -> c_int;
51+
pub fn luaopen_xml(L: *mut lua_State) -> c_int;
52+
}

mlua-sys/src/luau/lualib.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
//! Contains definitions from `lualib.h`.
22
3-
use std::os::raw::c_int;
3+
use std::os::raw::{c_char, c_int};
44

55
use super::lua::lua_State;
66

7-
pub const LUA_COLIBNAME: &str = "coroutine";
8-
pub const LUA_TABLIBNAME: &str = "table";
9-
pub const LUA_OSLIBNAME: &str = "os";
10-
pub const LUA_STRLIBNAME: &str = "string";
11-
pub const LUA_BITLIBNAME: &str = "bit32";
12-
pub const LUA_BUFFERLIBNAME: &str = "buffer";
13-
pub const LUA_UTF8LIBNAME: &str = "utf8";
14-
pub const LUA_MATHLIBNAME: &str = "math";
15-
pub const LUA_DBLIBNAME: &str = "debug";
16-
pub const LUA_VECLIBNAME: &str = "vector";
7+
pub const LUA_COLIBNAME: *const c_char = cstr!("coroutine");
8+
pub const LUA_TABLIBNAME: *const c_char = cstr!("table");
9+
pub const LUA_OSLIBNAME: *const c_char = cstr!("os");
10+
pub const LUA_STRLIBNAME: *const c_char = cstr!("string");
11+
pub const LUA_BITLIBNAME: *const c_char = cstr!("bit32");
12+
pub const LUA_BUFFERLIBNAME: *const c_char = cstr!("buffer");
13+
pub const LUA_UTF8LIBNAME: *const c_char = cstr!("utf8");
14+
pub const LUA_MATHLIBNAME: *const c_char = cstr!("math");
15+
pub const LUA_DBLIBNAME: *const c_char = cstr!("debug");
16+
pub const LUA_VECLIBNAME: *const c_char = cstr!("vector");
1717

1818
extern "C-unwind" {
1919
pub fn luaopen_base(L: *mut lua_State) -> c_int;

0 commit comments

Comments
 (0)