From 0b9a85e1838bed67ae69f11b42de84bcf19da80c Mon Sep 17 00:00:00 2001 From: ByteDream <63594396+ByteDream@users.noreply.github.com> Date: Thu, 14 Dec 2023 14:54:57 +0000 Subject: [PATCH] Add lua emscripten support (#338) --- Cargo.toml | 12 +++++++++--- examples/async_http_client.rs | 3 +++ examples/async_http_reqwest.rs | 2 +- examples/async_http_server.rs | 3 +++ examples/async_tcp_server.rs | 3 +++ examples/repl.rs | 2 ++ mlua-sys/src/lua51/lauxlib.rs | 2 +- mlua-sys/src/lua52/lauxlib.rs | 2 +- tests/chunk.rs | 3 +++ 9 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4750c95..3c72e1d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,20 +60,26 @@ ffi = { package = "mlua-sys", version = "0.4.0", path = "mlua-sys" } [target.'cfg(unix)'.dependencies] libloading = { version = "0.8", optional = true } +[target.'cfg(target_arch = "wasm32")'.dependencies] +ffi = { package = "mlua-sys", version = "0.4.0", path = "mlua-sys", features = ["vendored"] } + [dev-dependencies] -rustyline = "12.0" -criterion = { version = "0.5", features = ["async_tokio"] } trybuild = "1.0" futures = "0.3.5" hyper = { version = "0.14", features = ["client", "server"] } reqwest = { version = "0.11", features = ["json"] } -tokio = { version = "1.0", features = ["full"] } +tokio = { version = "1.0", features = ["macros", "rt", "time"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" maplit = "1.0" tempfile = "3" static_assertions = "1.0" +[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] +criterion = { version = "0.5", features = ["async_tokio"] } +rustyline = "12.0" +tokio = { version = "1.0", features = ["full"] } + [[bench]] name = "benchmark" harness = false diff --git a/examples/async_http_client.rs b/examples/async_http_client.rs index bdd9dbc..1424a62 100644 --- a/examples/async_http_client.rs +++ b/examples/async_http_client.rs @@ -1,3 +1,6 @@ +#[cfg(target_arch = "wasm32")] +compile_error!("Not available for wasm"); + use std::collections::HashMap; use hyper::body::{Body as HyperBody, HttpBody as _}; diff --git a/examples/async_http_reqwest.rs b/examples/async_http_reqwest.rs index cd67748..4d67564 100644 --- a/examples/async_http_reqwest.rs +++ b/examples/async_http_reqwest.rs @@ -1,6 +1,6 @@ use mlua::{chunk, ExternalResult, Lua, LuaSerdeExt, Result}; -#[tokio::main] +#[tokio::main(flavor = "current_thread")] async fn main() -> Result<()> { let lua = Lua::new(); diff --git a/examples/async_http_server.rs b/examples/async_http_server.rs index 43ae7a9..159622b 100644 --- a/examples/async_http_server.rs +++ b/examples/async_http_server.rs @@ -1,3 +1,6 @@ +#[cfg(target_arch = "wasm32")] +compile_error!("Not available for wasm"); + use std::future::Future; use std::net::SocketAddr; use std::pin::Pin; diff --git a/examples/async_tcp_server.rs b/examples/async_tcp_server.rs index edc4149..1b312fe 100644 --- a/examples/async_tcp_server.rs +++ b/examples/async_tcp_server.rs @@ -1,3 +1,6 @@ +#[cfg(target_arch = "wasm32")] +compile_error!("Not available for wasm"); + use std::io; use std::net::SocketAddr; use std::rc::Rc; diff --git a/examples/repl.rs b/examples/repl.rs index c0a34a6..35a7d0d 100644 --- a/examples/repl.rs +++ b/examples/repl.rs @@ -1,4 +1,6 @@ //! This example shows a simple read-evaluate-print-loop (REPL). +#[cfg(target_arch = "wasm32")] +compile_error!("Not available for wasm"); use mlua::{Error, Lua, MultiValue}; use rustyline::DefaultEditor; diff --git a/mlua-sys/src/lua51/lauxlib.rs b/mlua-sys/src/lua51/lauxlib.rs index b05b583..1565d3f 100644 --- a/mlua-sys/src/lua51/lauxlib.rs +++ b/mlua-sys/src/lua51/lauxlib.rs @@ -43,7 +43,7 @@ extern "C-unwind" { pub fn luaL_checkudata(L: *mut lua_State, ud: c_int, tname: *const c_char) -> *mut c_void; pub fn luaL_where(L: *mut lua_State, lvl: c_int); - pub fn luaL_error(L: *mut lua_State, fmt: *const c_char, ...) -> !; + pub fn luaL_error(L: *mut lua_State, fmt: *const c_char, ...) -> c_int; pub fn luaL_checkoption( L: *mut lua_State, diff --git a/mlua-sys/src/lua52/lauxlib.rs b/mlua-sys/src/lua52/lauxlib.rs index 51da767..570023d 100644 --- a/mlua-sys/src/lua52/lauxlib.rs +++ b/mlua-sys/src/lua52/lauxlib.rs @@ -49,7 +49,7 @@ extern "C-unwind" { pub fn luaL_checkudata(L: *mut lua_State, ud: c_int, tname: *const c_char) -> *mut c_void; pub fn luaL_where(L: *mut lua_State, lvl: c_int); - pub fn luaL_error(L: *mut lua_State, fmt: *const c_char, ...) -> !; + pub fn luaL_error(L: *mut lua_State, fmt: *const c_char, ...) -> c_int; pub fn luaL_checkoption( L: *mut lua_State, diff --git a/tests/chunk.rs b/tests/chunk.rs index 8cab671..714e887 100644 --- a/tests/chunk.rs +++ b/tests/chunk.rs @@ -1,9 +1,12 @@ +#![allow(unused_imports)] + use std::fs; use std::io; use mlua::{Lua, Result}; #[test] +#[cfg(not(target_arch = "wasm32"))] fn test_chunk_path() -> Result<()> { let lua = Lua::new();