mlua-rs/rlua

consider expose ffi mod or create rlua-sys crate

clouds56 opened this issue · 4 comments

I'd like to use lua_getupvalue, lua_setupvalue and lua_pushcclosure to create a closure (other than function which has 0 upvalue), is it possible to use ffi directly outside the crate?

Hi,
I don't think we'd want to expose ffi directly as it's too easy to break rlua's invariants.
It may make sense adding a way to create a closure with upvalues (a variant of Context::create_function()).
However, does Function::bind() give you the functionality you need?

Yes, I'm using bind for now, but it seems using a different way to do this and I worried about performance since it always create a new function when bind and call.
I think it make sense to have API like

Context::create_closure(Fn(LuaContext, /* upvalue */ FromLuaMulti, /* args */ FromMulti) -> ToMultiValue) -> LuaClosure
Closure::with_upvalues(values: FromLuaMulti) -> LuaFunction

I've added the Future label as I think this needs a bit of investigation to see whether it does make a difference to performance or convenience, and can be added later.

khvzak commented

rlua is going to be deprecated soon and this feature is already supported by mlua, see mlua-sys crate which is available directly from mlua as mlua::ffi