mlua icon indicating copy to clipboard operation
mlua copied to clipboard

windows module lua5.1 Compilation fails

Open july0426 opened this issue 5 years ago • 6 comments

MSVC with LUA_INC / LUA_LIB / LUA_LIB_NAME environment variables. Windows 10 ,mlua 5.0.1 I set up,but faild. Can you give a more detailed example or configuration

july0426 avatar Jan 27 '21 05:01 july0426

A first example is from github actions where I test Lua modules on Windows: https://github.com/khvzak/mlua/blob/master/.github/workflows/main.yml#L186

A second example is using Windows + MSVC

  1. Download binary Lua dll & lib (I used the luabinaries project, this file)
  2. Unzip to lua51 folder
  3. Go to mlua/examples/module
  4. From git shell
$ LUA_INC=$HOME/Downloads/lua51/include LUA_LIB=$HOME/Downloads/lua51 LUA_LIB_NAME=lua5.1 cargo build --features lua51

Build ok, we got mlua/target/debug/rust_module.dll

For testing:

  1. Go to mlua/target/debug
  2. Run
$ lua5.1 -e 'print(require("rust_module").sum(2,3))'
5
$ lua5.1 -e 'print(require("rust_module").used_memory())'
35441

Windows 10, Latest MSVC Community, Git, Rust 1.49.0

khvzak avatar Jan 27 '21 11:01 khvzak

Thank you very much for your reply. I succeeded !!! The reason for the failure is that Lua's lib was downloaded incorrectly. I succeeded in both Lua5.1 and Lua5.4

july0426 avatar Jan 28 '21 03:01 july0426

Now I have a new problem. The compiled DLL is required and executed correctly by Lua54.exe, but not by LuaQuire in Rust. Any solution, like this `use mlua::prelude::*;

fn main() -> LuaResult<()> { let lua = unsafe {Lua::new()}; lua.load(r#"print(require("my_module").sum(2,3))"#).exec()?;

Ok(())

}`

july0426 avatar Jan 28 '21 07:01 july0426

The line let lua = unsafe {Lua::new()}; should be replaced with let lua = unsafe { Lua::unsafe_new() }; to allow loading C modules

khvzak avatar Jan 28 '21 09:01 khvzak

DLL is compiled in features=['lua54','module'] mode The rust project is compliated with eatures=['lua54','vendored'] mode

july0426 avatar Jan 28 '21 10:01 july0426

Lua library does not load properly without lua54. DLL, but I cannot find a way to link lua54. DLL to the library

july0426 avatar Jan 28 '21 10:01 july0426