mirror of
https://github.com/bytedream/litbwraw.git
synced 2025-05-09 20:25:13 +02:00
update rust crates to 2024 edition
This commit is contained in:
parent
f033739bba
commit
28001a2040
@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "wasm"
|
name = "wasm"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2024"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#![warn(clippy::missing_safety_doc)]
|
#![allow(clippy::missing_safety_doc)]
|
||||||
|
|
||||||
use mlua::Lua;
|
use mlua::Lua;
|
||||||
use std::ffi::{c_char, c_int, CStr};
|
use std::ffi::{CStr, c_char, c_int};
|
||||||
|
|
||||||
#[no_mangle]
|
#[unsafe(no_mangle)]
|
||||||
pub unsafe extern "C" fn execute(program: *const c_char, argc: c_int, argv: *const *const c_char) {
|
pub unsafe extern "C" fn execute(program: *const c_char, argc: c_int, argv: *const *const c_char) {
|
||||||
let lua = Lua::new();
|
let lua = Lua::new();
|
||||||
let lua_globals = lua.globals();
|
let lua_globals = lua.globals();
|
||||||
@ -13,12 +13,12 @@ pub unsafe extern "C" fn execute(program: *const c_char, argc: c_int, argv: *con
|
|||||||
arg.set(-1, "mlua").unwrap();
|
arg.set(-1, "mlua").unwrap();
|
||||||
arg.set(0, "execute").unwrap();
|
arg.set(0, "execute").unwrap();
|
||||||
for i in 0..argc {
|
for i in 0..argc {
|
||||||
let argv_arg = CStr::from_ptr(*argv.offset(i as isize));
|
let argv_arg = unsafe { CStr::from_ptr(*argv.offset(i as isize)) };
|
||||||
arg.push(argv_arg.to_str().unwrap()).unwrap();
|
arg.push(argv_arg.to_str().unwrap()).unwrap();
|
||||||
}
|
}
|
||||||
lua_globals.set("arg", arg).unwrap();
|
lua_globals.set("arg", arg).unwrap();
|
||||||
|
|
||||||
let exec = CStr::from_ptr(program).to_str().unwrap();
|
let exec = unsafe { CStr::from_ptr(program).to_str().unwrap() };
|
||||||
if let Err(err) = lua.load(exec).exec() {
|
if let Err(err) = lua.load(exec).exec() {
|
||||||
eprintln!("{}", err)
|
eprintln!("{}", err)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "example-binary"
|
name = "example-binary"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
mlua = { version = ">=0.9.3", features = ["lua51", "vendored"] }
|
mlua = { version = ">=0.9.3", features = ["lua51", "vendored"] }
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
let lua = mlua::Lua::new();
|
let lua = mlua::Lua::new();
|
||||||
|
|
||||||
lua.load(r#"print("Hello from WebAssembly Lua!")"#).exec().unwrap();
|
lua.load(r#"print("Hello from WebAssembly Lua!")"#)
|
||||||
|
.exec()
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "example-library"
|
name = "example-library"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2024"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
@ -2,7 +2,7 @@ use std::env;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let book_output_path = env::var("BOOK_OUTPUT_PATH").map_or(None, Some);
|
let book_output_path = env::var("BOOK_OUTPUT_PATH").ok();
|
||||||
|
|
||||||
let out_dir = env::var("OUT_DIR").unwrap();
|
let out_dir = env::var("OUT_DIR").unwrap();
|
||||||
let pkg_name = env::var("CARGO_PKG_NAME").unwrap();
|
let pkg_name = env::var("CARGO_PKG_NAME").unwrap();
|
||||||
@ -19,5 +19,12 @@ fn main() {
|
|||||||
println!("cargo:rustc-link-arg=-sEXPORT_ES6=1");
|
println!("cargo:rustc-link-arg=-sEXPORT_ES6=1");
|
||||||
println!("cargo:rustc-link-arg=-sERROR_ON_UNDEFINED_SYMBOLS=0");
|
println!("cargo:rustc-link-arg=-sERROR_ON_UNDEFINED_SYMBOLS=0");
|
||||||
println!("cargo:rustc-link-arg=--no-entry");
|
println!("cargo:rustc-link-arg=--no-entry");
|
||||||
println!("cargo:rustc-link-arg=-o{}.js", book_output_path.map(PathBuf::from).unwrap_or(target_path).join(pkg_name).to_string_lossy());
|
println!(
|
||||||
|
"cargo:rustc-link-arg=-o{}.js",
|
||||||
|
book_output_path
|
||||||
|
.map(PathBuf::from)
|
||||||
|
.unwrap_or(target_path)
|
||||||
|
.join(pkg_name)
|
||||||
|
.to_string_lossy()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,20 @@
|
|||||||
use std::ffi::{c_char, CStr};
|
#![allow(clippy::missing_safety_doc)]
|
||||||
use mlua::Lua;
|
|
||||||
|
|
||||||
#[no_mangle]
|
use mlua::Lua;
|
||||||
pub extern "C" fn lua_new() -> *mut Lua {
|
use std::ffi::{CStr, c_char};
|
||||||
|
|
||||||
|
#[unsafe(no_mangle)]
|
||||||
|
pub unsafe extern "C" fn lua_new() -> *mut Lua {
|
||||||
let lua = Lua::new();
|
let lua = Lua::new();
|
||||||
Box::into_raw(Box::new(lua))
|
Box::into_raw(Box::new(lua))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[unsafe(no_mangle)]
|
||||||
pub unsafe extern "C" fn lua_execute(lua: *mut Lua, to_execute: *const c_char) {
|
pub unsafe extern "C" fn lua_execute(lua: *mut Lua, to_execute: *const c_char) {
|
||||||
let lua: &mut Lua = &mut *lua;
|
let lua: &mut Lua = unsafe { &mut *lua };
|
||||||
let to_execute = CStr::from_ptr(to_execute);
|
let to_execute = unsafe { CStr::from_ptr(to_execute) };
|
||||||
|
|
||||||
if let Err(err) = lua.load(&to_execute.to_string_lossy().to_string()).exec() {
|
if let Err(err) = lua.load(to_execute.to_string_lossy().to_string()).exec() {
|
||||||
eprintln!("{}", err)
|
eprintln!("{}", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "lua-playground"
|
name = "lua-playground"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2024"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
@ -2,7 +2,7 @@ use std::env;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let book_output_path = env::var("BOOK_OUTPUT_PATH").map_or(None, Some);
|
let book_output_path = env::var("BOOK_OUTPUT_PATH").ok();
|
||||||
|
|
||||||
let out_dir = env::var("OUT_DIR").unwrap();
|
let out_dir = env::var("OUT_DIR").unwrap();
|
||||||
let pkg_name = env::var("CARGO_PKG_NAME").unwrap();
|
let pkg_name = env::var("CARGO_PKG_NAME").unwrap();
|
||||||
@ -19,5 +19,12 @@ fn main() {
|
|||||||
println!("cargo:rustc-link-arg=-sEXPORT_ES6=1");
|
println!("cargo:rustc-link-arg=-sEXPORT_ES6=1");
|
||||||
println!("cargo:rustc-link-arg=-sERROR_ON_UNDEFINED_SYMBOLS=0");
|
println!("cargo:rustc-link-arg=-sERROR_ON_UNDEFINED_SYMBOLS=0");
|
||||||
println!("cargo:rustc-link-arg=--no-entry");
|
println!("cargo:rustc-link-arg=--no-entry");
|
||||||
println!("cargo:rustc-link-arg=-o{}.js", book_output_path.map(PathBuf::from).unwrap_or(target_path).join(pkg_name).to_string_lossy());
|
println!(
|
||||||
|
"cargo:rustc-link-arg=-o{}.js",
|
||||||
|
book_output_path
|
||||||
|
.map(PathBuf::from)
|
||||||
|
.unwrap_or(target_path)
|
||||||
|
.join(pkg_name)
|
||||||
|
.to_string_lossy()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,20 @@
|
|||||||
use std::ffi::{c_char, CStr};
|
#![allow(clippy::missing_safety_doc)]
|
||||||
use mlua::Lua;
|
|
||||||
|
|
||||||
#[no_mangle]
|
use mlua::Lua;
|
||||||
pub extern "C" fn lua_new() -> *mut Lua {
|
use std::ffi::{CStr, c_char};
|
||||||
|
|
||||||
|
#[unsafe(no_mangle)]
|
||||||
|
pub unsafe extern "C" fn lua_new() -> *mut Lua {
|
||||||
let lua = Lua::new();
|
let lua = Lua::new();
|
||||||
Box::into_raw(Box::new(lua))
|
Box::into_raw(Box::new(lua))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[unsafe(no_mangle)]
|
||||||
pub unsafe extern "C" fn lua_execute(lua: *mut Lua, to_execute: *const c_char) {
|
pub unsafe extern "C" fn lua_execute(lua: *mut Lua, to_execute: *const c_char) {
|
||||||
let lua: &mut Lua = &mut *lua;
|
let lua: &mut Lua = unsafe { &mut *lua };
|
||||||
let to_execute = CStr::from_ptr(to_execute);
|
let to_execute = unsafe { CStr::from_ptr(to_execute) };
|
||||||
|
|
||||||
if let Err(err) = lua.load(&to_execute.to_string_lossy().to_string()).exec() {
|
if let Err(err) = lua.load(to_execute.to_string_lossy().to_string()).exec() {
|
||||||
eprintln!("{}", err)
|
eprintln!("{}", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user