Open tomaka opened 7 years ago
Also added the 'lua
lifetime to InsideCallback
to fix soundness.
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.
The current code is still unsound because it allows reading and writing the same userdata simultaneously.
Fix #10
Blocked by https://github.com/rust-lang/rust/issues/38673
Changes are:
LuaRead<&InsideCallback>
(right now it'sLuaRead<&mut InsideCallback> + 'static
, which is a hack)LuaRead<&'a InsideCallback>
so they will still work.LuaFunction
orLuaTable
do not implementLuaRead<&'a InsideCallback>
.LuaMutex<T>
(whereT
can beLuaFunction
orLuaTable
) does implementLuaRead<&'a InsideCallback>
.LuaMutex
struct has alock
function that locks theInsideCallback
and reads theT
. As long as theT
is alive, no otherLuaMutex
can be locked.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 exampletable1
by callingtable1.lock()
. Thelock
function will return aLuaTable
.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 thisLuaMutex
system.