Commit Graph

74 Commits

Author SHA1 Message Date
Alex Orlenko 9fdba541e9
Update `UserDataMethods::add_async_method()` functions to take `&T` as second argument instead of cloning `T`.
New functions: `UserDataMethods::add_async_method_mut()`, `UserDataMethods::add_async_meta_method_mut()`.
2023-06-15 00:34:41 +01:00
Alex Orlenko da6d5a93c9
Update rustyline dependency 2023-03-30 22:34:41 +01:00
Alex Orlenko 22fbcfd9fb
Update edition everywhere 2023-03-12 01:03:31 +00:00
Alex Orlenko 8339621f9c
Rename `to_lua_err` -> `into_lua_err` 2023-01-06 21:35:15 +00:00
Alex Orlenko 2cb4b49d0d
Don't use unstable features in examples 2022-12-30 13:39:27 +00:00
Alex Orlenko 61c285746c
Remove FromLua impl for UserData+Clone 2022-12-20 23:30:18 +00:00
Alex Orlenko 56abc4a700
Refactor `AsChunk` trait 2022-12-19 21:12:36 +00:00
Alex Orlenko bf79d9e75d
Initial implementation of owned Lua types 2022-12-18 00:35:41 +00:00
Alex Orlenko 4fc69be5f6
Update rustyline dev dependency 2022-07-25 14:14:01 +01:00
Alex Orlenko 1807fa789c
Don't require Lua sources for modules in build system 2022-05-07 22:16:54 +01:00
Alex Orlenko 25a4879cde
Update examples: async_http_client/async_http_server/async_tcp_server
Make them following best practices and remove `unsafe` code.
2021-10-12 11:55:25 +01:00
Alex Orlenko 559f9e6c6b
Add `target.aarch64-apple-darwin` conf to module examples 2021-10-11 18:07:34 +01:00
Alex Orlenko c702c5eff2
Add userdata example 2021-06-21 20:28:14 +01:00
Alex Orlenko a208156ed2 Update examples to include `chunk!` macro 2021-06-19 14:41:48 +01:00
Alex Orlenko 08ffeb0ca9 Improve module mode:
- Don't hide module function inside `luaopen_%` function.
- Raise Lua exception instead of panic if module function returns error.
2021-06-13 22:38:51 +01:00
Alex Orlenko 6c0096d8ac Update examples 2021-06-03 23:52:29 +01:00
Alex Orlenko e8de2a458a Allow multiple entrypoints in a single module share the same Lua state.
Previously it would initialize different Lua instances.
Fixes #49.
2021-05-18 20:07:34 +01:00
Alex Orlenko 2fae94586d Remove Result from lua.null() and lua.array_metatable(). They never fail. 2021-04-27 00:38:13 +01:00
Alex Orlenko 8de75d1c18 Update tokio to 1.0 for async examples 2021-01-20 10:47:27 +00:00
Alex Orlenko bedd430eb5 Re-export mlua_derive 2020-12-29 22:26:15 +00:00
Alex Orlenko afc41ab23c Add serialization example & update others 2020-12-29 21:39:34 +00:00
Alex Orlenko c5d0ccc433 Add `reqwest` http client example to fetch json 2020-12-28 15:21:45 +00:00
Alex Orlenko 2eb40deafd Add test to check loading module from lua coroutine (thread) 2020-06-07 20:38:19 +01:00
Alex Orlenko 5952a1f709 New `module` feature
Don't link module with Lua core (see: http://lua-users.org/wiki/BuildingModules)
Example and tests for modules
2020-06-07 20:38:11 +01:00
Alex Orlenko 60c659ecff Add async http server example 2020-05-15 01:48:57 +01:00
Alex Orlenko 7b0e4b4280 Add Send capability to Lua 2020-05-11 02:43:34 +01:00
Alex Orlenko 6e2bb73cff Bind Futures lifetimes to 'lua rather than 'static.
Fix async examples.
2020-05-11 02:43:34 +01:00
Alex Orlenko d8897d867b Update examples 2020-04-19 01:23:42 +01:00
Alex Orlenko f7dc9da107 Update README
Cargo fmt and minor changes
2020-04-17 22:52:34 +01:00
Alex Orlenko 47e8a80c1c v0.3.0-alpha.1 with async support
Squashed commit of the async branch.
2020-04-17 22:39:50 +01:00
Alex Orlenko 6874c2e004 Fix examples and docs 2019-11-04 22:23:15 +00:00
kyren 65d8ad2f86 Allow non-utf8 Lua source in load / exec / eval 2018-10-01 06:00:21 -04:00
kyren 8538874dd3 Whoops, misplaced assert 2018-10-01 05:31:28 -04:00
kyren 4625ac9d52 Some more minor guided tour updates 2018-10-01 05:24:11 -04:00
kyren c7684fef32 Update comments in guided tour for recent additions 2018-10-01 05:20:05 -04:00
kyren 70b67052c9 Upgrade rustyline to 2.0 to avoid confusion 2018-09-24 21:27:29 -04:00
kyren b8da08187d Move integration tests into top-level tests directory
other minor refactors
2018-09-16 20:15:51 -04:00
kyren bd00af2bac Initial design for non-'static scoped userdata
Uses the same UserData trait, and should at least in theory support everything
that 'static UserData does, except that any functions added that rely on
AnyUserData are pretty much useless.

Probably pretty slow and I'm not sure how to make it dramatically faster, which
is a shame because generally when you need non'-static userdata you might be
creating it kind of a lot (if it was long-lived, it would probably be 'static).

Haven't added tests yet, will do that next.
2018-09-04 03:40:13 -04:00
kyren 31fa9173ae Fix #78 2018-05-02 20:05:43 -04:00
kyren 61236e685f Change changelog, readme, examples, Cargo.toml for 0.12 release 2018-02-10 19:04:18 -05:00
kyren d0ff10b528 I believe this is all the external API changes necessary for 'm' safety 2017-12-03 23:45:00 -05:00
kyren e7661a5c27 auto-formatting 2017-10-23 16:42:20 -04:00
kyren 50436d3463 autoformatting 2017-08-03 02:03:28 -04:00
kyren 16f57d18e5 Merge pull request #34 from jonas-schievink/better-error
[WIP] Enhanced errors
2017-08-02 16:00:08 -04:00
Jonas Schievink 95698735a2 Fix multiline inputs 2017-08-02 14:36:10 +02:00
Jonas Schievink 3f20319a84 Use rustyline for the REPL
This makes the REPL more usable as you can now edit lines and recall
previously executed statements.
2017-08-02 14:32:45 +02:00
Jonas Schievink bf76e41487 Merge IncompleteStatement into SyntaxError
Both are a form of syntax error, this reflects that better. No
functionality is lost, incomplete inputs are moved to a bool field of
SyntaxError.
2017-08-01 23:23:31 +02:00
kyren f44917ff83 Replace _: () with () everywhere 2017-08-01 14:09:47 -04:00
kyren 48bf35dc5b Fix references to hlists in documentation, improve? Variadic usability
Also rename to/from/pack/unpack to pack/unpack/pack_multi/unpack_multi, I don't
know if this makes their usage clearer, and it IS a bit confusing that I'm
changing the meaning of the words 'pack' and 'unpack'
2017-08-01 13:55:08 -04:00
kyren d02e32a80a Remove the rest of the uses of pack / unpack 2017-07-31 01:27:35 -04:00
kyren 4549abbb85 Two major API changes to start with:
* Callbacks have generic argument and return types
* All variadics are done with tuples
2017-07-31 01:21:41 -04:00
Jonas Schievink 8bd0c2c812 Rename `LuaString` to `String`
This required a lot of little adjustments where we used std's `String`
before. In downstream code, this shouldn't be necessary, as you can just
do `use rlua::String as LuaString` to disambiguate.
2017-07-23 18:36:50 +02:00
Jonas Schievink 9df7727eaa Remove the `Lua*` prefix from most types
cc #15

Doesn't touch `LuaString` mainly because that's a *lot* of renaming work
and the code looks weird. Also I want feedback before I proceed.
2017-07-23 18:36:50 +02:00
kyren 160c5405e1 Add back explanatory comment about trying "return <expr>" before statement
Also run through rustfmt
2017-07-19 20:10:11 -04:00
Jonas Schievink d9098900d1 Give `Lua::eval` a source name param and simplify 2017-07-16 22:53:32 +02:00
kyren 6f0caa4a6d Update README, small example changes. 2017-06-25 22:25:28 -04:00
kyren d3b311fe49 Another major API change, out of stack space is not an Err
It, ahem "should not" be possible to exhaust lua stack space in normal usage,
and causing stack errors to be Err is slightly obnoxious.  I have been wanting
to make this change for a while, and removing the callback API from tables makes
this sensible *I think*.

I can think of a couple of ways that this is not technically true, but I think
that they are acceptable, or should be handled differently.

One, you can make arbitrarily sized LuaVariadic values.  I think this is maybe a
bug already, because there is an argument limit in Lua which is lower than the
stack limit.  I'm not sure what happens there, but if it is a stack based panic,
(or any panic?) it is a bug.

Two, I believe that if you recurse over and over between lua -> rust -> lua ->
rust etc, and call rlua API functions, you might get a stack panic.  I think for
trusted lua code, this is morally equivalent to a regular stack overflow in
plain rust, which is already.. well it's not a panic but it's some kind of safe
crash I'm not sure, so I think this is acceptable.  For *untrusted* lua code,
this could theoretically be a problem if the API provided a callback that would
call back into lua, then some lua script could force a stack based panic.  There
are so many concerns with untrusted lua code, and this library is NOT safe
enough yet for untrusted code (it doesn't even provide an option to limit lua to
the safe API subset yet!), so this is not currently an issue.  When the library
provides support for "safe lua", it should come with big warnings anyway, and
being able to force a stack panic is pretty minor in comparison.

I think if there are other ways to cause unbounded stack usage, that it is a
bug, or there can be an error just for that situation, like argument count
limits.

This commit also fixes several stupid bugs with tests, stack checking, and
panics.
2017-06-25 17:15:11 -04:00
kyren bf9bf849c2 Simplification of error types
The multi-level error types were a mistake.  Probably should have waited on the
cargo version bump, oh well.
2017-06-25 04:25:48 -04:00
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