-
Hey! I am trying to call my Rust code from Lua but having some issues. For whatever reason, Lua returns the following error (I'm using Git Bash): $ lua52 -e "require('target/debug/rustfromlua').hello('Lua')"
C:\Program Files\lua52\lua52.exe: error loading module 'target/debug/rustfromlua' from file '.\target/debug/rustfromlua.dll':
The specified procedure could not be found.
stack traceback:
[C]: in ?
[C]: in function 'require'
(command line):1: in main chunk
[C]: in ? Project FilesThis is [package]
name = "rustfromlua"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib"]
[dependencies]
mlua = { version = "0.10.1", features = ["lua52", "module"] } Here is use mlua::prelude::*;
fn hello(_: &Lua, name: String) -> LuaResult<()> {
println!("Hello, {}!", name);
Ok(())
}
#[mlua::lua_module]
fn rustfromlua(lua: &Lua) -> LuaResult<LuaTable> {
let exports = lua.create_table()?;
exports.set("hello", lua.create_function(hello)?)?;
Ok(exports)
} I am compiling with just |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
@khvzak, can you help, please? I tried to link it properly but is does not see the $ LUA_LIB="/d/Desktop\ Access/Documents/GitHub/rustfromlua/.lua/" LUA_LINK="dylib" cargo build
Compiling mlua-sys v0.6.5
Compiling mlua v0.10.1
Compiling rustfromlua v0.1.0 (D:\Desktop Access\Documents\GitHub\rustfromlua)
error: linking with `link.exe` failed: exit code: 1181
|
= note: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.40.33807\\bin\\HostX64\\x64\\link.exe"...
= note: LINK : fatal error LNK1181: cannot open input file 'lua52.lib'
error: could not compile `rustfromlua` (lib) due to 1 previous error Even though I've downloaded $ ls .lua/
include lua52.dll lua52.lib The Lua version I'm trying to compile for is 5.2.1. |
Beta Was this translation helpful? Give feedback.
-
I successfully resolved the issue by doing exactly what the comment. I assume you cannot call the module if you're not exactly in the CWD with the |
Beta Was this translation helpful? Give feedback.
-
You cannot load module like:
You need to set LUA_CPATH and then load through |
Beta Was this translation helpful? Give feedback.
I successfully resolved the issue by doing exactly what the comment. I assume you cannot call the module if you're not exactly in the CWD with the
*.dll
file. And for whatever reason the module refused to compile unless I put the Lua library files in the$HOME/Downloads
directory. In my opinion this happens due to the linker's inability to see the contents of the disk "D".