Commit graph

66 commits

Author SHA1 Message Date
kyren 3deb6df525 Lots of LuaError changes
It is possible that I have gone too far here into error discrimination and
should scale it back, not sure yet.
2017-06-24 20:57:04 -04:00
kyren 47db72cac4 Big API incompatible error change, remove dependency on error_chain
The current situation with error_chain is less than ideal, and there are lots of
conflicting interests that are impossible to meet at once.  Here is an
unorganized brain dump of the current situation, stay awhile and listen!

This change was triggered ultimately by the desire to make LuaError implement
Clone, and this is currently impossible with error_chain.  LuaError must
implement Clone to be a proper lua citizen that can live as userdata within a
lua runtime, because there is no way to limit what the lua runtime can do with a
received error.  Currently, this is solved by there being a rule that the error
will "expire" if the error is passed back into rust, and this is very
sub-optimal.  In fact, one could easily imagine a scenario where lua is for
example memoizing some function, and if the function has ever errored in the
past the function should continue returning the same error, and this situation
immediately fails with this restriciton in place.

Additionally, there are other more minor problems with error_chain which make
the API less good than it could be, or limit how we can use error_chain.  This
change has already solved a small bug in a Chucklefish project, where the
conversion from an external error type (Borrow[Mut]Error) was allowed but not
intended for user code, and was accidentally used.  Additionally, pattern
matching on error_chain errors, which should be common when dealing with Lua, is
less convenient than a hand rolled error type.

So, if we decide not to use error_chain, we now have a new set of problems if we
decide interoperability with error_chain is important.  The first problem we run
into is that there are two natural bounds for wrapped errors that we would
pick, (Error + Send + Sync), or just Error, and neither of them will
interoperate well with error_chain.  (Error + Send + Sync) means we can't wrap
error chain errors into LuaError::ExternalError (they're missing the Sync
bound), and having the bounds be just Error means the opposite, that we can't
hold a LuaError inside an error_chain error.

We could just decide that interoperability with error_chain is the most
important qualification, and pick (Error + Send), but this causes a DIFFERENT
set of problems.  The rust ecosystem has the two primary error bounds as Error
or (Error + Send + Sync), and there are Into impls from &str / String to
Box<Error + Send + Sync> for example, but NOT (Error + Send).  This means that
we are forced to manually recreate the conversions from &str / String to
LuaError rather than relying on a single Into<Box<Error + Send + Sync>> bound,
but this means that string conversions have a different set of methods than
other error types for external error conversion.  I have not been able to figure
out an API that I am happy with that uses the (Error + Send) bound.  Box<Error>
is obnoxious because not having errors implement Send causes needless problems
in a multithreaded context, so that leaves (Error + Send + Sync).  This is
actually a completely reasonable bound for external errors, and has the nice
String Into impls that we would want, the ONLY problem is that it is a pain to
interoperate with the current version of error_chain.

It would be nice to be able to specify the traits that an error generated by the
error_chain macro would implement, and this is apparently in progress in the
error_chain library.  This would solve both the problem with not being able to
implement Clone and the problems with (Error + Send) bounds.  I am not convinced
that this library should go back to using error_chain when that functionality is
in stable error_chain though, because of the other minor usability problems with
using error_chain.

In that theoretical situation, the downside of NOT using error_chain is simply
that there would not be automatic stacktraces of LuaError.  This is not a huge
problem, because stack traces of lua errors are not extremely useful, and for
external errors it is not too hard to create a different version of the
LuaExternalResult / LuaExternalError traits and do conversion from an
error_chain type into a type that will print the stacktrace on display, or
use downcasting in the error causes.

So in summary, this library is no longer using error_chain, and probably will
not use it again in the future.  Currently this means that to interoperate with
error_chain, you should use error_chain 0.8.1, which derives Sync on errors, or
wait for a version that supports user defined trait derives.  In the future
when error_chain supports user defined trait derives, users may have to take an
extra step to make wrapped external errors print the stacktrace that they
capture.

This change works, but is not entirely complete.  There is no error
documentation yet, and the change brought to a head an ugly module organization
problem.  There will be more commits for documentation and reorganization, then
a new stable version of rlua.
2017-06-24 18:11:56 -04:00
kyren f0c2f9a870 Method renames, remove ToLua / FromLua impls for Sets
There is no single obvious form for a set in lua, and it is not very difficult
to accept a table and convert the sequence values into a set.

Also rename some methods as per discussion.
2017-06-20 18:04:25 -05:00
Jonas Schievink ed210e88b5 Rename LuaTable::(raw_)length to (raw_)len
All Rust containers use `len` for this. Even in the Lua API, this is
called `lua_len` and `lua_rawlen`.
2017-06-18 14:36:30 +02:00
Jonas Schievink de0f3dc3c0 Rename Lua::load to Lua::exec
When talking about "loading" Lua code, it usually means compiling a
chunk of code into a runnable Lua function, but without actually
running it. This makes that clear.
2017-06-18 14:31:38 +02:00
kyren 75b7024a93 Merge pull request #7 from jonas-schievink/popen
Enable `io.popen` on Linux
2017-06-17 16:31:09 -04:00
Jonas Schievink 4a980de0ed Allow multiline input in the REPL example 2017-06-17 14:43:05 +02:00
Jonas Schievink 4f05516783 Add a simple repl example 2017-06-17 01:19:21 +02:00
kyren b02dda3431 that example hardly shows ALL the features 2017-06-15 16:30:16 -04:00
kyren 32c83d77b7 small warning / clippy fixes, doc comments 2017-06-15 16:27:39 -04:00
kyren 0022057058 rustfmt changes 2017-06-15 10:26:39 -04:00
kyren 8440298e71 Go ahead and release 0.5.0
partially for the selfish reason that my submodule setup does not deal well with
ureleased versions of cargo libs where the version number ends with -pre
2017-06-11 01:33:08 -04:00
kyren 5c8aa19b8d Two major API changes:
Allow load to return values, allows reimplementing require() like functions
properly.

Make globals table explicit in Lua, remove Lua::get / Lua::set in favor of
Lua::globals.  Allows obeying globals metatable, using other Table functions on
the globals table.

Also added "has" method as shorthand for checking whether a table entry is not
nil.
2017-06-11 01:12:25 -04:00
kyren b15ee9053e Update to use hlist_macro for hlist macros.
You will type hlist! hlist_pat! and HList! so often that every character
counts.  Apologize for the API churn in the README.
2017-05-22 11:16:34 -04:00
kyren e35cdbfe88 show variadics in examples 2017-05-21 21:57:15 -04:00
kyren c7693ae0a2 Examples and initial README 2017-05-21 21:47:32 -04:00