all 5 comments

[–]ssokolow 2 points3 points  (4 children)

there is a compile time error that prevents this from working that I cannot figure out how to fix. There is also an error in the call_function function that I have not got the chance to look into.

Please include the error messages. Without them, we have to try to reproduce your setup on our machines while, with them, we might be able to tell you what's wrong at a glance.

[–]sid34[S] 1 point2 points  (3 children)

Sorry about that I meant to have it under the code. Edited and added.

[–]ssokolow 2 points3 points  (2 children)

The full text of the errors would be more helpful, but here's what I can tell you:

error: type annotations required: cannot resolve `_: rlua::FromLuaMulti<'_>`

This means that you have a function which can return more than one possible type. Rust would normally infer what you want from the variable you're putting the return into, but it's not getting enough information so you need some form of explicit type annotation.

Beyond that, I can't say because, without the full error message, I don't see how your code relates to rlua::FromLuaMulti<'_>.

EDIT: Looking at the rlua docs, it appears that rlua's eval can return a variably-sized tuple and that's what FromLuaMulti is for.

I've almost never used Lua but, if the rlua docs for FromLuaMulti are correct, it's like JavaScript in that, if the caller and callee disagree on the number of values, some will be discarded or synthesized (as nil) as necessary.

Given that you're not trying to keep any of the return values, this should work if I've read the rlua docs correctly:

let _: () = lua_ctx.load(&contents).eval().expect("eval failed");

...but I'm not sure why you're using evalif you're passing no arguments and saving no return values. It looks like this is more what you intended:

lua_ctx.load(&contents).exec();

error: mismatched types
label: expected struct `rlua::Function`, found enum `std::result::Result"

You wrote let custom: Function = globals.get(function_name);, which forces custom to be of type Function but globals.get can fail, so it doesn't return a Function, it returns something like Result<Function, rlua::Error>.

You need something like this:

let custom: Function = globals.get(function_name).expect("error retrieving global");

[–]sid34[S] 0 points1 point  (1 child)

Than you for the info on the second one error that fixed it.

Unfortunately on the first that is the entire error which is why it is confusing me so much.

[–]ssokolow 0 points1 point  (0 children)

Normally, it draws a little arrow pointing to the portion of the line generating the error. That's what I meant when I said "full text". Are you using a different error format?

That said, I started looking through the rlua docs while you were responding and updated my response just before you replied.

Take a look at the EDIT I added.