Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ezlua is unsound #5

Open
devzf opened this issue Jun 5, 2023 · 1 comment
Open

ezlua is unsound #5

devzf opened this issue Jun 5, 2023 · 1 comment

Comments

@devzf
Copy link

devzf commented Jun 5, 2023

Consider the following example:

use ezlua::prelude::*;

fn main() {
    let lua = Lua::with_open_libs();

    let st = std::rc::Rc::new(std::cell::RefCell::new(None));
    let st2 = st.clone();
    let f = lua
        .new_closure(move |s: LuaString<'static>| {
            st2.borrow_mut().replace(s);
        })
        .unwrap();
    lua.global().set("f", f).unwrap();
    lua.do_string("f('')", None).unwrap();

    let s = st.borrow();
    println!("{:?}", s.as_ref().map(|s| s.to_str()));
}

ezlua v0.3.1

@metaworm
Copy link
Owner

metaworm commented Jun 5, 2023

This is indeed a problem,

In order to implement universal function binding, it seems impossible to associate the lifetime parameters of LuaMethod with the &self reference of LuaState, otherwise it would compile wrong

In this case, the user should not declare the parameter's lifetime as 'static

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants