Commit graph

167 commits

Author SHA1 Message Date
Alex Orlenko cb109f6e36 Rename to mlua 2019-10-01 16:11:12 +01:00
Alex Orlenko 11e22d1cba Temporary drop "compile-fail" tests due to unstable compiletest_rs crate 2019-09-30 22:34:20 +01:00
Alex Orlenko 54f4627195 Update tests (excl. compile-fail) 2019-09-29 13:03:32 +01:00
Alex Orlenko b23ee6a162 cargo fmt 2019-09-29 12:56:03 +01:00
kyren 65d8ad2f86 Allow non-utf8 Lua source in load / exec / eval 2018-10-01 06:00:21 -04:00
kyren 167184ae76 Allow arbitrary [u8] Lua strings 2018-09-30 15:42:04 -04:00
kyren 8810c36979 Add test for i128 Lua round-trip 2018-09-26 21:13:25 -04:00
kyren 58ce05ff9a Improve the situation with numerical conversion
This is a somewhat involved change with two breaking API changes:

1) Lua::coerce_xxx methods now return Option (this is easier and faster than
dealing with Result)
2) rlua numeric conversions now allow more loss of precision
conversions (e.g. 1.5f32 to 1i32)

The logic for the first breaking change is that mostly the coerce methods are
probably used internally, and they make sense as low-level fallible casts and
are now used as such, and there's no reason to confuse things with a Result with
a large error type and force the user to match on the error which will hopefully
only be FromLuaConversionError anyway.

The logic for the second change is that it matches the behavior of
num_traits::cast, and is more consistent in that *some* loss of precision
conversions were previously allowed (e.g. f64 to f32).

The problem is that now, Lua::coerce_integer and Lua::unpack::<i64> have
different behavior when given, for example, the number 1.5.  I still think this
is the best option, though, because the Lua::coerce_xxx methods represent how
Lua works internally and the standard C API cast functions that Lua provides,
and the ToLua / FromLua code represents the most common form of fallible Rust
numeric conversion.

I could revert this change and turn `Lua::eval::<i64>("1.5", None)` back into an
error, but it seems inconsistent to allow f64 -> f32 loss of precision but not
f64 -> i64 loss of precision.
2018-09-26 21:01:54 -04:00
kyren c3d0110722 Return rlua::Error on out of range numeric conversions using num_traits::cast 2018-09-24 22:14:50 -04:00
kyren 6a5ec6b387 cargo fmt 2018-09-24 22:13:42 -04:00
kyren b8da08187d Move integration tests into top-level tests directory
other minor refactors
2018-09-16 20:15:51 -04:00
kyren 4a587ca1c5 Add compilefail test for Scope::create_nonstatic_userdata 2018-09-16 19:54:58 -04:00
kyren 1a9c50f228 Solve (maybe) *another* soundness issue with Lua::scope
Callbacks should not be able to capture their arguments and hold onto them,
because the `&Lua` used in previous calls will not remain valid across calls.
One could imagine an API where the specific `&Lua` is simply stored inside the
`Scope` itself, but this is harder to do, and would (badly) encourage storing
references inside Lua userdata.

Ideally, the only way it should be possible to store Lua handles inside Lua
itself is through usafety or the `rental` crate or other self-borrowing
techniques to make references into 'static types.  If at all possible this
roadblock should stay, because reference types inside userdata are almost always
going to lead to a a memory leak, and if you accept the risks you should just
use `RegistryKey` with its manual removal.
2018-08-05 20:03:47 -04:00
kyren a2615a8cbb Fix for a soundness bug around scope, don't allow callback parameters to escape
Also includes other fixes for compiletest_rs failures, and a small reorg of tests
2018-08-05 11:54:33 -04:00
kyren 71f3dd50a1 New approach for ref types, use an auxillary thread stack
Vastly simpler and less magical than using a fixed size magical section of the
active stack, and seems to be no slower.  The only real downside is that
it *seems* extremely extremely hacky (and to be fair, it is).
2018-03-28 01:09:51 -04:00
kyren ace5cb44f0 Letting scope handles escape the scope was unsafe
This simplifies the Scope lifetimes, and should make it a compile error for
scope created handles to exit the scope.  This should be strictly better, as you
would never WANT to do this, but I hope that I have not caused a subtle lifetime
problem that would prevent passing those created handles back into Lua.  I've
tested every situation I can think of, and it doesn't appear to be an issue, but
I admit that I don't fully understand everything involved and I could be missing
something.

The reason that I needed to do this is that if you can let a scope handle escape
the scope, you have a LuaRef with an unused registry id, and that can lead to
UB.  Since not letting the scope references escape is a strict improvement
ANYWAY (if I haven't caused a lifetime issue), this is the easiest fix.

This is technically a breaking change but I think in most cases if you notice it
you would be invoking UB, or you had a function that accepted a Scope or
something.  I don't know if it's worth a version bump?
2018-02-19 17:40:48 -05:00
kyren d4c80d44c8 Attempt to enable compiletest_rs on nightly on travis 2018-02-10 00:27:15 -05:00