tomaka / hlua

Rust library to interface with Lua
MIT License
507 stars 48 forks source link

[WIP] Add a LuaMutex type to borrow the InsideCallback #118

Open tomaka opened 7 years ago

tomaka commented 7 years ago

Fix #10

Blocked by https://github.com/rust-lang/rust/issues/38673

Changes are:

So for example if you want a Rust function that takes two tables as parameter, you can pass a closure like |(table1: LuaMutex<LuaTable<_>>, table2: LuaMutex<LuaTable<_>>)|. You can then read for example table1 by calling table1.lock(). The lock function will return a LuaTable.

As long as the LuaTable is alive, table2 can't be locked.

See #10 for an explanation about why this is necessary.

A future change is to allow LuaRead<&mut InsideCallback> if there is only one parameter, which would allow closures with only one parameter to bypass this LuaMutex system.

tomaka commented 7 years ago

Also added the 'lua lifetime to InsideCallback to fix soundness.

tomaka commented 7 years ago

I managed to make it work for InsideCallback<'static> only. Since this is the most common case, I'm going to push the change and fix this later.

tomaka commented 7 years ago

The current code is still unsound because it allows reading and writing the same userdata simultaneously.