Skip to content

Commit 0b9a85e

Browse files
authored
Add lua emscripten support (mlua-rs#338)
1 parent 59974d7 commit 0b9a85e

File tree

9 files changed

+26
-6
lines changed

9 files changed

+26
-6
lines changed

Cargo.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,26 @@ ffi = { package = "mlua-sys", version = "0.4.0", path = "mlua-sys" }
6060
[target.'cfg(unix)'.dependencies]
6161
libloading = { version = "0.8", optional = true }
6262

63+
[target.'cfg(target_arch = "wasm32")'.dependencies]
64+
ffi = { package = "mlua-sys", version = "0.4.0", path = "mlua-sys", features = ["vendored"] }
65+
6366
[dev-dependencies]
64-
rustyline = "12.0"
65-
criterion = { version = "0.5", features = ["async_tokio"] }
6667
trybuild = "1.0"
6768
futures = "0.3.5"
6869
hyper = { version = "0.14", features = ["client", "server"] }
6970
reqwest = { version = "0.11", features = ["json"] }
70-
tokio = { version = "1.0", features = ["full"] }
71+
tokio = { version = "1.0", features = ["macros", "rt", "time"] }
7172
serde = { version = "1.0", features = ["derive"] }
7273
serde_json = "1.0"
7374
maplit = "1.0"
7475
tempfile = "3"
7576
static_assertions = "1.0"
7677

78+
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
79+
criterion = { version = "0.5", features = ["async_tokio"] }
80+
rustyline = "12.0"
81+
tokio = { version = "1.0", features = ["full"] }
82+
7783
[[bench]]
7884
name = "benchmark"
7985
harness = false

examples/async_http_client.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[cfg(target_arch = "wasm32")]
2+
compile_error!("Not available for wasm");
3+
14
use std::collections::HashMap;
25

36
use hyper::body::{Body as HyperBody, HttpBody as _};

examples/async_http_reqwest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use mlua::{chunk, ExternalResult, Lua, LuaSerdeExt, Result};
22

3-
#[tokio::main]
3+
#[tokio::main(flavor = "current_thread")]
44
async fn main() -> Result<()> {
55
let lua = Lua::new();
66

examples/async_http_server.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[cfg(target_arch = "wasm32")]
2+
compile_error!("Not available for wasm");
3+
14
use std::future::Future;
25
use std::net::SocketAddr;
36
use std::pin::Pin;

examples/async_tcp_server.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[cfg(target_arch = "wasm32")]
2+
compile_error!("Not available for wasm");
3+
14
use std::io;
25
use std::net::SocketAddr;
36
use std::rc::Rc;

examples/repl.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//! This example shows a simple read-evaluate-print-loop (REPL).
2+
#[cfg(target_arch = "wasm32")]
3+
compile_error!("Not available for wasm");
24

35
use mlua::{Error, Lua, MultiValue};
46
use rustyline::DefaultEditor;

mlua-sys/src/lua51/lauxlib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extern "C-unwind" {
4343
pub fn luaL_checkudata(L: *mut lua_State, ud: c_int, tname: *const c_char) -> *mut c_void;
4444

4545
pub fn luaL_where(L: *mut lua_State, lvl: c_int);
46-
pub fn luaL_error(L: *mut lua_State, fmt: *const c_char, ...) -> !;
46+
pub fn luaL_error(L: *mut lua_State, fmt: *const c_char, ...) -> c_int;
4747

4848
pub fn luaL_checkoption(
4949
L: *mut lua_State,

mlua-sys/src/lua52/lauxlib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extern "C-unwind" {
4949
pub fn luaL_checkudata(L: *mut lua_State, ud: c_int, tname: *const c_char) -> *mut c_void;
5050

5151
pub fn luaL_where(L: *mut lua_State, lvl: c_int);
52-
pub fn luaL_error(L: *mut lua_State, fmt: *const c_char, ...) -> !;
52+
pub fn luaL_error(L: *mut lua_State, fmt: *const c_char, ...) -> c_int;
5353

5454
pub fn luaL_checkoption(
5555
L: *mut lua_State,

tests/chunk.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
#![allow(unused_imports)]
2+
13
use std::fs;
24
use std::io;
35

46
use mlua::{Lua, Result};
57

68
#[test]
9+
#[cfg(not(target_arch = "wasm32"))]
710
fn test_chunk_path() -> Result<()> {
811
let lua = Lua::new();
912

0 commit comments

Comments
 (0)