Commit Graph

792 Commits

Author SHA1 Message Date
Alex Orlenko cb1ac28f2a v0.5.4 2021-04-20 02:05:05 +01:00
Alex Orlenko 0bd36b42e7 Make error::Error non_exhaustive 2021-04-16 22:10:10 +01:00
Alex Orlenko e0da6ac929 Hide raw_sequence_values_by_len under async/serialize feature flags 2021-04-16 22:09:49 +01:00
Alex Orlenko 0c7db4916c Serialize only known (registered) userdata.
This reverts commit 7332c6a.
Non-static userdata is a special case and can cause segfault if try to serialize it.
Now it should be safe, plus I added non-static userdata destructor to generate better error messages
in case of accessing destructed userdata.
2021-04-16 22:01:55 +01:00
Alex Orlenko b9589491e4 Improve panic handling (check for twice resumed panics) 2021-04-15 23:04:36 +01:00
Alex Orlenko c363fb9288 v0.5.3 2021-03-04 00:01:06 +00:00
Alex Orlenko 726fde7e1f Optimise async callbacks (polling)
call async Rust callback [sum] 3 10
                        time:   [59.338 us 59.729 us 60.097 us]
                        change: [-10.336% -8.6212% -6.8003%] (p = 0.00 < 0.05)
                        Performance has improved.
2021-03-03 23:21:56 +00:00
Alex Orlenko 7cb9c4f39c Fix bug in returning nil-prefixed multi values from async function 2021-03-03 22:32:22 +00:00
Alex Orlenko b93ace0224 v0.5.2 2021-02-27 19:32:25 +00:00
Alex Orlenko 5f37bf812d Fix/whitelist some clippy warnings 2021-02-27 19:23:08 +00:00
Alex Orlenko 7775b4a99c Bump copyright year 2021-02-26 10:35:00 +00:00
Alex Orlenko 1d9cda10eb Add ToLua implementation for Cow<str> and Cow<CStr> 2021-02-26 10:23:36 +00:00
Alex Orlenko 7332c6a28c Remove `registered_userdata_mt` check 2021-02-22 20:38:36 +00:00
Alex Orlenko 335f433df4 Optimize callbacks 2021-02-21 23:52:20 +00:00
Alex Orlenko 2aed548747 Fix scoped async destruction of partially polled futures 2021-02-21 23:52:07 +00:00
Alex Orlenko aeb66115f7 v0.5.1 2021-01-20 11:04:03 +00:00
Alex Orlenko b6ff501b8c Fix numeric types conversion for 32bit lua. Fix #27 2021-01-20 10:46:23 +00:00
Alex Orlenko e62fd400d7 Remove unused exports from glue.{c,rs} && Fix some clippy warnings 2021-01-16 13:31:45 +00:00
Alex Orlenko 618874ef3c v0.5.0 2020-12-31 13:39:42 +00:00
Alex Orlenko 9f82cbe0c5 Update documentation 2020-12-31 13:39:38 +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 ce8955f5b9 Don't try to disable c modules without `package` loaded. Fix #24 2020-12-22 23:05:08 +00:00
Alex Orlenko 6e2b687cb7 Serde support (serialize feature flag) 2020-12-14 00:51:26 +00:00
Kai Schmidt c65058a40a impl `ToLua` and `FromLua` for `HashSet` and `BTreeSet` 2020-09-27 17:54:47 -07:00
Alex Orlenko a172c021c9 Update `set_memory_limit` doc 2020-07-30 12:16:25 +01:00
Alex Orlenko de2c5cd9a9 Fix compilation warnings on nightly rust 2020-07-28 21:10:55 +01:00
Alex Orlenko d201beadc9 Add ChunkMode enum to mark chunks as text or binary 2020-07-28 21:04:21 +01:00
Alex Orlenko dd58cdad52 Add Function::dump() to dump lua function to a binary chunk 2020-07-27 23:26:33 +01:00
Eidolon 883bf082b9 Make Lua::load load binary chunks when unsafe 2020-07-27 03:37:38 -05:00
Alex Orlenko 4265250cfd 0.4.1 release
Fix docs.rs build features
Update Cargo.toml description
2020-06-08 14:08:07 +01:00
Alex Orlenko efcaef3db7 Enable hooks support for LuaJIT 2020-06-07 20:38:19 +01:00
Alex Orlenko 0a13a9631d Fix LuaJIT 2.1 libraries loading 2020-06-07 20:38:19 +01:00
Alex Orlenko 3d42bc4ca6 Refactor main_state handling
Don't allow to set hook if main_state is not available
Remove Lua 5.1 dirty hack
2020-06-07 20:38:19 +01:00
Alex Orlenko 95b9fe8dac Fix clippy warnings 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 d5c22d989a Dirty hack to get lua 5.1 main state 2020-06-06 16:07:16 +01:00
Alex Orlenko a9a4cf13f1 Add `has_metamethod` to `AnyUserData` 2020-06-06 16:07:16 +01:00
Alex Orlenko c3822219e0 Add hooks support (based on rlua v0.17 implementation)
This feature works on lua54, lua53, lua52 and lua51 only.
LuaJIT is unstable.
2020-06-06 16:07:16 +01:00
Alex Orlenko f6da437d8b Update docs 2020-06-06 16:07:16 +01:00
Alex Orlenko 2fd6757f39 Add LuaJIT 2.0.5 stable support 2020-06-06 16:07:16 +01:00
Alex Orlenko cccec914ca Remove deprecated Table::call 2020-05-15 01:48:57 +01:00
Alex Orlenko 687ecc9247 Update documentation 2020-05-15 01:48:57 +01:00
Alex Orlenko 79bfb112aa Remove redundant lifetimes 2020-05-15 01:48:57 +01:00
Alex Orlenko 9f2d598517 Add clippy check and fix clippy warnings 2020-05-15 01:48:56 +01:00
Alex Orlenko 5a9a308790 Provide safe and unsafe Lua modes:
- In safe mode Lua would not have ability to load C code via `require` or `package.loadlib`
- Unsafe mode allows everything.
2020-05-12 02:14:48 +01:00
Alex Orlenko 1b2b94c808 Use Rust allocator for new Lua states that allows to set memory limit 2020-05-12 02:14:48 +01:00
Alex Orlenko 526e7418d8 Add MetaMethod::Close to support Lua 5.4 to-be-closed variables 2020-05-12 02:14:47 +01:00
Alex Orlenko 539b569ff4 Add Lua 5.4 (rc2) support 2020-05-11 02:43:34 +01:00
Alex Orlenko 5c226b4915 Lua 5.4 FFI 2020-05-11 02:43:34 +01:00
Alex Orlenko d366ce0dd4 Scope support (including async) 2020-05-11 02:43:34 +01:00
Alex Orlenko 2bd5c2f6ca Hide Lua "Send" capability under the optional "send" feature flag 2020-05-11 02:43:34 +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 7efcee853d Don't allow 'callback outlive 'lua 2020-05-11 02:43:33 +01:00
Alex Orlenko d672e19365 Add ToLua implementation for slices and arrays 2020-04-29 16:12:58 +01:00
Alex Orlenko bda399a5b4 Get yield function in the moment of async callback creation.
This is usefull to temporary override `coroutine.yield` prior to create_async_callback()
and then restore to original value.
2020-04-28 14:29:36 +01:00
Alex Orlenko fe5e87b0f5 Fix bugs with metatable cache:
- Don't use thread_local as Lua can be created in one thread and executed in another (in module mode);
- Make per state storage without luaL_ref;
2020-04-28 14:29:14 +01:00
Alex Orlenko 0efa0fcb6a Update documentation 2020-04-20 01:52:01 +01:00
Alex Orlenko c826798a6d Minor refactor 2020-04-19 16:51:35 +01:00
Alex Orlenko ee08050c1f Add TableExt trait with call_method/function methods 2020-04-19 16:15:16 +01:00
Alex Orlenko 222f4df668 Add family of `call_async` function
Update documentation
Move async tests to a separate file
2020-04-18 21:26:12 +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 1a788c48f1 Cherry-pick changes from rlua:
- Make Value::type_name() public
- Update CallbackError and ExternalError Display impl
2020-04-15 21:23:00 +01:00
Alex Orlenko e4dc773aa3 Remove `__ipairs` metamethod deprecated in lua 5.3 and not available by default 2020-01-25 20:47:36 +00:00
Alex Orlenko 27121c779d Add raw_insert() and raw_remove() for tables (represented as lists) 2020-01-07 20:53:47 +00:00
Alex Orlenko 5eec0ef56b Implement PartialEq trait for Value (and subtypes)
Add equals() method to compare values optionally invoking __eq.
2020-01-07 00:03:03 +00:00
Alex Orlenko 42b33849e1 Add support of loading a specified set of standard libraries 2019-12-26 23:04:21 +00:00
Alex Orlenko 143c3a81a7 Add pair and ipair metamethods support (lua 5.2/5.3 only) 2019-11-30 00:58:42 +00:00
Alex Orlenko fd17a01456 Add Lua 5.2 support 2019-11-30 00:58:41 +00:00
Alex Orlenko ae677b0918 Move lua 5.1 support under new "lua51" feature 2019-11-04 22:23:15 +00:00
Alex Orlenko 6874c2e004 Fix examples and docs 2019-11-04 22:23:15 +00:00
Alex Orlenko 29aa25a48b Dont take wrapped panic in error_tostring() 2019-11-04 22:23:09 +00:00
Alex Orlenko 85607d8bfc Impl Drop for Lua 2019-10-17 17:05:42 +01:00
Alex Orlenko ec08a76a41 Don't store extra data in the lua_State extra space 2019-10-17 17:05:42 +01:00
Alex Orlenko c4fd7a9faf Lua 5.1 support 2019-10-17 17:05:42 +01:00
Alex Orlenko b7c578c274 Replace libc with std::os::raw 2019-10-02 22:12:28 +01:00
Alex Orlenko 224ed8ff52 Add mlua_derive proc macro module 2019-10-02 22:12:27 +01:00
Alex Orlenko cb109f6e36 Rename to mlua 2019-10-01 16:11:12 +01:00
Alex Orlenko 2e5762f6e5 fmt glue.c 2019-09-30 22:34:47 +01:00
Alex Orlenko 2ca4273ffb Add call method to table 2019-09-30 22:15:27 +01:00
Alex Orlenko 78480b5f31 Use main state to store extra data and auxiliary registries 2019-09-30 22:14:58 +01:00
Alex Orlenko 45159bfda7 Add Table::raw_remove method 2019-09-29 12:56:06 +01:00
Alex Orlenko 0c230a3037 Allow to catch rust panics via pcall 2019-09-29 12:56:06 +01:00
Alex Orlenko b23ee6a162 cargo fmt 2019-09-29 12:56:03 +01:00
Alex Orlenko affa85feb0 Backport changes from rlua 0.16 (master branch) 2019-09-29 12:53:13 +01:00
Alex Orlenko 53b352466e Replace ffi module with implementation from "jcmoyer/rust-lua53" crate 2019-09-29 12:42:07 +01:00
Alex Orlenko 14a68dd6d2 Add dyn to trait objects 2019-09-29 12:42:07 +01:00
Alex Orlenko 47a8ac2b05 Allow only init Lua from an exiting state 2019-09-26 19:17:51 +01:00
kyren 65d8ad2f86 Allow non-utf8 Lua source in load / exec / eval 2018-10-01 06:00:21 -04:00
kyren 51339ecb1d Some documentation and changelog fixes 2018-10-01 05:14:43 -04:00
kyren 167184ae76 Allow arbitrary [u8] Lua strings 2018-09-30 15:42:04 -04:00
kyren 6d17a383df Avoid mem::uninitialized in generic context as it is unsound with e.g. bool 2018-09-26 21:07:11 -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 c07abdc03e
Merge pull request #79 from acrisci/system-lua-pkg-config
find system lua with pkg-config
2018-09-16 20:57:45 -04:00
kyren b8da08187d Move integration tests into top-level tests directory
other minor refactors
2018-09-16 20:15:51 -04:00
kyren 7eb71fb1df Rename Scope::create_userdata to Scope::create_nonstatic_userdata
avoids clashing with the previous method name to avoid confusion
2018-09-16 19:54:12 -04:00
kyren 6153ec4b95 basic tests for nonstatic userdata 2018-09-04 19:41:00 -04:00
kyren add547b356 comment terminology... fix? 2018-09-04 19:09:09 -04:00
kyren 703601e348 code re-org have slightly less pub(crate) items 2018-09-04 19:05:21 -04:00
kyren 30a94c4dec Comment updates that I really hope are correct
Tried to explain the rationale for safety around callbacks in Lua and Scope a
bit better, because every time I don't look at this for a while I forget my
reasoning.  I'm not always so great at using the right terminology, so to
whoever reads this, if I got this wrong please tell me.
2018-09-04 17:36:06 -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 37165a8201 Don't leak userdata if the metatable creation errors or panics 2018-09-04 03:38:22 -04:00
kyren 89b9968920 small macro style change 2018-09-02 20:34:39 -04:00
kyren 9c4d451d4c Implement tuple MultiValue tuple conversion up to 16 2018-09-02 02:48:54 -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 b35ff5fa12 Remove out of date documentation, simpler scope lifetimes
The documentation describing it being a logic bug to access "outer" callback
handles when inside an "inner" callback is inaccurate, that was only true when
using an older design for handle values.

Also, there is no reason to have a separate 'callback lifetime, because 'scope
is already invariant and just using 'scope seems equivalent.
2018-08-05 19:02:19 -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 8366960368 Update to failure 0.1.2, rename deprecated methods 2018-08-05 11:48:25 -04:00
kyren 2e1bdb64c0 format with up-to-date rustfmt 2018-08-05 09:51:39 -04:00
kyren e6688e1db2 very small doc fixes 2018-08-05 09:51:32 -04:00
kyren 02bc8da203 Prepare for 0.14.0 release 2018-06-29 01:24:28 -04:00
Tony Crisci 66e49518d3 find system lua with pkg-config 2018-05-14 08:51:51 -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 5aa22de68e Use git dependency on failure 1.0 for right now 2018-03-20 14:07:32 -04:00
kyren 8b9ab3d031 Small renames and comments to better communicate the intention of stack checking functions 2018-03-19 17:42:10 -04:00
kyren a05f0d5cd0 Where possible, don't call to_lua / from_lua / to_lua_multi / from_lua_multi callbacks during Lua stack manipulation
This should protect against being able to trigger a stack assert in Lua.  Lua
and associated types shoul be able to assume that LUA_MINSTACK stack slots are
available on any user entry point.  In the future, we could turn check_stack
into something that only checked the Lua stack when debug_assertions is true.
2018-03-19 15:16:40 -04:00
kyren 0d5e45e800 Always ensure LUA_MINSTACK available stack spaces on callback
Otherwise, cleanly error with an appropriate stack error.  Part of an effort to
ensure that it should not be possible to trigger a stack space assert.
2018-03-19 14:36:01 -04:00
kyren 4b6809c766 Clean up some lifetime specification 2018-03-19 14:35:46 -04:00
kyren 985636267c Fix some bad potential unsafety on inner callback calls.
Since we now optionally use stack spaces for handle values, we have to be
mindful of whether our stack handle points to the stack in an outer level of
Lua "stack protection".  We now keep track of the "recursion level" of Lua
instances, and do not allow ref manipulation on "outer" Lua instances until the
inner callback has returned.  Also, update the documentation to reflect the
additional panic behavior.
2018-03-12 22:36:52 -04:00
kyren 1019ab8a3f Use rlua_ asserts instead of unreachable!, changelog updates for 0.14
0.14 will be released alongside `failure` 1.0 with a dependency update.
2018-03-12 20:36:39 -04:00
kyren c6c90f201c Documentation updates for new handle behavior, and some minor cleanup 2018-03-12 17:50:48 -04:00
kyren 4358034bbf Do not crash in release when accessing an AnyUserData
Also, don't bother asserting if the userdata has no metatable, just behave as
though the userdata has no type.  This should be impossible to trigger currently
without the debug library, but it is not really that useful of an assert anyway.
2018-03-12 17:48:05 -04:00
kyren f0775f4a1a Move several asserts to only be active with debug, bump alpha version number 2018-03-12 16:14:52 -04:00
kyren f79d771f1a Documentation improvements, split scope into its own module, improved tests
Also makes `Lua` and associated types !UnwindSafe and !RefUnwindSafe, which they
should be because they are intensely internally mutable.  Lua IS still panic
safe, but that doesn't mean it should be marked as UnwindSafe (as I understand
it).
2018-03-12 16:00:11 -04:00
kyren ee23f199f0 Remove `stack_guard` function and instead just use StackGuard directly 2018-03-12 13:13:44 -04:00
kyren 95633ce915 Merge branch 'bench' 2018-03-12 12:29:27 -04:00
kyren 601e9f4cac A lot of performance changes.
Okay, so this is kind of a mega-commit of a lot of performance related changes
to rlua, some of which are pretty complicated.

There are some small improvements here and there, but most of the benefits of
this change are from a few big changes.  The simplest big change is that there
is now `protect_lua` as well as `protect_lua_call`, which allows skipping a
lightuserdata parameter and some stack manipulation in some cases.  Second
simplest is the change to use Vec instead of VecDeque for MultiValue, and to
have MultiValue be used as a sort of "backwards-only" Vec so that ToLuaMulti /
FromLuaMulti still work correctly.

The most complex change, though, is a change to the way LuaRef works, so that
LuaRef can optionally point into the Lua stack instead of only registry values.
At state creation a set number of stack slots is reserved for the first N LuaRef
types (currently 16), and space for these are also allocated separately
allocated at callback time.  There is a huge breaking change here, which is that
now any LuaRef types MUST only be used with the Lua on which they were created,
and CANNOT be used with any other Lua callback instance.  This mostly will
affect people using LuaRef types from inside a scope callback, but hopefully in
those cases `Function::bind` will be a suitable replacement.  On the plus side,
the rules for LuaRef types are easier to state now.

There is probably more easy-ish perf on the table here, but here's the
preliminary results, based on my very limited benchmarks:

create table            time:   [314.13 ns 315.71 ns 317.44 ns]
                        change: [-36.154% -35.670% -35.205%] (p = 0.00 < 0.05)
create array 10         time:   [2.9731 us 2.9816 us 2.9901 us]
                        change: [-16.996% -16.600% -16.196%] (p = 0.00 < 0.05)
                        Performance has improved.
create string table 10  time:   [5.6904 us 5.7164 us 5.7411 us]
                        change: [-53.536% -53.309% -53.079%] (p = 0.00 < 0.05)
                        Performance has improved.
call add function 3 10  time:   [5.1134 us 5.1222 us 5.1320 us]
                        change: [-4.1095% -3.6910% -3.1781%] (p = 0.00 < 0.05)
                        Performance has improved.
call callback add 2 10  time:   [5.4408 us 5.4480 us 5.4560 us]
                        change: [-6.4203% -5.7780% -5.0013%] (p = 0.00 < 0.05)
                        Performance has improved.
call callback append 10 time:   [9.8243 us 9.8410 us 9.8586 us]
                        change: [-26.937% -26.702% -26.469%] (p = 0.00 < 0.05)
                        Performance has improved.
create registry 10      time:   [3.7005 us 3.7089 us 3.7174 us]
                        change: [-8.4965% -8.1042% -7.6926%] (p = 0.00 < 0.05)
                        Performance has improved.

I think that a lot of these benchmarks are too "easy", and most API usage is
going to be more like the 'create string table 10' benchmark, where there are a
lot of handles and tables and strings, so I think that 25%-50% improvement is a
good guess for most use cases.
2018-03-11 23:20:10 -04:00
kyren 6470b6eefc Improve documentation about __index vs regular methods 2018-03-10 10:30:17 -05:00
kyren 431f84012a Enable stack leak panic universally
This will potentially panic on Drop of a `Lua` instance, which may be an abort
if this is a double panic, but that is more desirable than such a bug being
hidden.
2018-03-08 12:36:03 -05:00
kyren d06890afc6 Simplify stack_guard / stack_err_guard
The expected change is always zero, because stack_guard / stack_err_guard are
always used at `rlua` entry / exit points.
2018-03-08 11:40:24 -05:00
kyren 10802bf70f Whoops, fix an assert that was improperly changed to an internal error 2018-03-08 11:14:02 -05:00
kyren adfeaeab49 Change strategies for handling the Lua stack during panics
Previously, on an internal panic, the Lua stack would be reset before panicking
in an attempt to make sure that such panics would not cause stack leaks or leave
the stack in an unknown state.  Now, such panic handling is done in stack_guard
and stack_err_guard instead, and this is for a few reasons:

1) The previous approach did NOT handle user triggered panics that were outside
   of `rlua`, such as a panic in a ToLua / FromLua implementation.  This is
   especially bad since most other panics would be indicative of an internal bug
   anyway, so the utility of keeping `rlua` types usable after such panics was
   questionable.  It is much more sensible to ensure that `rlua` types are
   usable after *user generated* panics.
2) Every entry point into `rlua` should be guarded by a stack_guard or
   stack_err_guard anyway, so this should restore the Lua stack on exiting back
   to user code in all cases.
3) The method of stack restoration no longer *clears* the stack, only resets it
   to what it previously was.  This allows us, potentially, to keep values at
   the beginning of the Lua stack long term and know that panics will not
   clobber them.  There may be a way of dramatically speeding up ref types by
   using a small static area at the beginning of the stack instead of only the
   registry, so this may be important.
2018-03-08 10:59:50 -05:00
kyren 1e76de1d08 Update docs to include warning about RegistryKey in callbacks 2018-03-06 06:23:04 -05:00
kyren eb154e4a9e Further safety updates of `protect_lua_call`
Only allow Copy result types and Fn parameter functions, do not risk dropping
anything inside function passed to lua_pcall.
2018-03-06 06:22:05 -05:00
kyren 37feaebdce Also describe how protect_lua_call functions should not hold types that Drop 2018-03-01 17:56:19 -05:00
kyren 8ac78c4585 Make some changes whose necessity became recently apparent while reading rustc 1.24.1 change notes.
So, despite staring intently at the params structure magic in protect_lua_call,
there is still a nasty bug.  In the event of an error, the return value of the
parameters structure could be dropped despite being mem::unintialized.  Of
course, the actual return values are incidentally always Copy I think, so this
wasn't an actual bug, but I've proven to myself the danger of such dark majyyks.
Just use Option and be done with it, it doesn't have to be so complicated!

Also document why there are a slew of random functions in the ffi module.
2018-03-01 17:17:18 -05:00
kyren d7995137d7 Add debug API to ffi (not used yet, was using experimentally)
Also fix for cstr! macro
2018-02-28 14:42:05 -05:00
kyren a49ea51b79 Remove terrible awful no-good evil hack
The breakage is being addressed in rust itself.
2018-02-19 18:09:04 -05:00
kyren e19a5b6481 Cleanup max upvalues constant a bit, add some luaconf.h assumptions 2018-02-19 18:03:18 -05:00
kyren d78420b51c Communicate a little bit better about the checkstack constant 2018-02-19 17:57:39 -05: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 0450c9b597 Make error_traceback never trigger a Lua error
It is called from both Lua and Rust, and any error would hide the error it's
trying to generate a traceback for.
2018-02-18 21:13:35 -05:00
kyren b07557c1c7 more hard to trigger bugs that I noticed doing conversion 2018-02-18 06:09:15 -05:00
kyren bb2a9c5b5d Fix several bugs found while doing C conversion
Fixing these in master in case I need to back out the change I'm making
2018-02-18 05:26:14 -05:00
kyren dec360f78f Can.. can I do this? Is this a thing that actually works?
Drastic times and all that.
2018-02-16 22:01:41 -05:00
kyren 73de52dcce Remove debugging println!s 2018-02-16 21:09:49 -05:00
kyren f0186d1799 Provisional "fix" for #71. Requires nightly :( 2018-02-15 21:39:35 -05:00
kyren fc058eba60 comment fixes 2018-02-12 13:56:23 -05:00
kyren c22aae461b Some changes for panic correctness, stack usage correctness, and speed 2018-02-12 13:54:31 -05:00
kyren c4b3170e2b More documentation fixes 2018-02-11 18:17:15 -05:00
kyren bfe44089ef Documentation fixes / additions 2018-02-11 17:54:17 -05:00
kyren ea834635c1 Add `UserDataMethods::` `add_function_mut` and `add_meta_function_mut` 2018-02-11 17:53:25 -05:00
kyren 7231e95195 It's far too easy to write 'stack_guard' as opposed to 'stack_err_guard'!
And it will work until something fails!  Maybe there should be a test that calls
every possible function that invokes to_lua / from_lua with a type where both
directions fail?
2018-02-11 16:47:39 -05:00
kyren ce7e8e61fd shave this yak some more, make `Callback` type alias have two lifetimes 2018-02-11 08:51:17 -05:00
kyren da1e1625b3 Specify the types exactly in the scary transmute
If I happen to change the definition of the Callback type alias, instead of
creating a potentially arbitrary transmute, it will now instead fail to compile.
2018-02-11 08:30:03 -05:00
kyren a91e3ed411 clarify the scary transmute 2018-02-11 08:22:15 -05:00
kyren fd0e31c6ea Add some extra warnings about the reference cycle dangers of `RegistryKey` 2018-02-11 06:37:51 -05:00
kyren 20480ec88d fix unused process import warnings 2018-02-10 17:55:08 -05:00
kyren 9e3374ff9e lua_abort / lua_internal_abort macros 2018-02-10 17:49:54 -05:00
kyren d4c80d44c8 Attempt to enable compiletest_rs on nightly on travis 2018-02-10 00:27:15 -05:00
kyren 60743d45cd Move all tests into a tests/ subfolder 2018-02-09 23:52:05 -05:00
kyren d331e4b97c Error correctly on too many arguments / returns / binds / recursions
There are also some other drive-by changes to fix panicking in extern "C"
functions and other edge case stack errors
2018-02-09 23:40:23 -05:00
kyren fe6e4bdf35 Explicit error type for destructed callbacks
Also removes some cleverness if debug_assertions was disabled, as it really
doesn't make much of a performance difference.
2018-02-09 21:23:59 -05:00
kyren 514abd5b82 Actually unref scope created types from the registry AS WELL AS destructing them 2018-02-09 07:27:55 -05:00
kyren 84b009da03 A few small performance improvements
When 'debug_assertions' is not enabled, don't bother doing asserts in
stack_guard / stack_err_guard.  Also, add an optional feature not enabled by
default to disable LUA_USE_APICHECK in release mode.  Once the bugs in rlua that
allow you to trigger LUA_USE_APICHECK are fixed, this feature will be the
default behavior.
2018-02-09 01:22:34 -05:00
kyren de4d21f8ea Fix some strange lifetime usage on `Lua::create_function`
I don't think that the lifetime of the &Lua in the callback and the lifetime of
the &Lua from creating the callback need to be related at all.  I'm not sure if
this has any actual effect, but it makes more sense (I think?).
2018-02-08 18:52:29 -05:00
kyren b6bc8d0bed Make the `Scope` lifetimes more sensible
Avoids messy lifetime issues when interacting with other handle types with scope
produced values.

The whole lifetime situation with 'lua on most methods could actually probably
use some looking at, I'm sure it probably has lots of less than optimal
decisions in it.

This also adds a proper comment to the 'scope lifetime to explain that the key
is that 'scope needs to be invariant to make things safe.  Disregard my previous
commit message, the real problem is that I had a poor understanding of lifetime
variance / invaraince.
2018-02-08 18:45:07 -05:00
kyren 7701aeef85 TERRIBLE HACK FIX I DO NOT UNDERSTAND
Okay, so this is the fix for the previously mentioned lifetime problem.  I
mimicked the API for `crossbeam::scope` extremely closely for `Lua::scope`, and
for some reason things that would not compile with `crossbeam::scope` WOULD
compile with `Lua::scope`, and I could not figure it out.

So I took the crossbeam source and made tiny edits until I determined the
crossover point where invalid borrows would compile, and it was.. not what I
expected it to be.  Simply replacing a RefCell<Option<DtorChain<'a>>> with a
PhantomData<&'a ()> would suddenly cause this to compile with crossbeam:

```
struct Test {
    field: i32,
}
crossbeam::scope(|scope| {
    let mut t = Test {
        field: 0,
    };

    scope.spawn(|| t.field = 42);

    drop(t);

    // ...anything
})

```

which is precisely the same problem as `rlua`.

To say I am unsatisfied by this fix is a drastic understatement.  SURELY this
must be a compiler bug?
2018-02-08 05:12:27 -05:00
kyren f05716deb8 This SHOULD fix the lifetime problem with scope... but it doesn't!
The following code should not compile:

```
struct Test {
    field: i32,
}

let lua = Lua::new();
lua.scope(|scope| {
    let mut test = Test { field: 0 };

    let f = scope
        .create_function(|_, ()| {
            test.field = 42;
            Ok(())
        })
        .unwrap();
    lua.globals().set("bad!", f).unwrap();
});
```

yet it does with this commit.  However, I have a fix for this, which I do not in
any way understand.
2018-02-08 05:12:11 -05:00
kyren 7a0c066593 export accidentally hidden `Scope` type 2018-02-08 01:54:30 -05:00
kyren 164250b352 Don't panic with "rlua internal error" message on panics that are not internal
It is part of the contract that only LuaRef types constructed from the same
parent Lua state are passed into Lua, so generating a panic there is not an
internal error.
2018-02-07 17:05:00 -05:00
kyren b9d9bea28a slightly faster, less obnoxious scope drop 2018-02-07 16:51:24 -05:00
kyren 98ee4e9492 More correct scope drop behavior
now no longer aborts if a Drop impl panics
2018-02-07 16:42:03 -05:00
kyren ab9841a02f Don't keep the unref list around forever after Lua is dropped 2018-02-07 11:16:22 -05:00
kyren cb25a99f70 Lots of changes, not sure if actually safe yet.
* Make Lua Send
* Add Send bounds to (nearly) all instances where userdata and functions are
  passed to Lua
* Add a "scope" method which takes a callback that accepts a `Scope`, and give
  `Scope` the ability to create functions and userdata that are !Send, *and also
  functions that are not even 'static!*.
2018-02-06 20:53:25 -05:00
kyren 7780a91e19 fix missing unwrap in tests 2018-02-06 20:29:48 -05:00
kyren b056ed2c4e Don't panic on mismatched `RegistryKey` use, instead return error 2018-02-06 10:51:39 -05:00
kyren 823c2deaca Slightly different strategy with RegistryKey values
Provide a method for automatic cleanup of expired RegistryKey values, so that
manually cleaning up registry values is optional.
2018-02-06 03:33:19 -05:00
kyren 8820e7705c test `owns_registry_value` 2018-02-06 00:54:04 -05:00
kyren 79635f29be Add method to check whether a RegistryKey is owned by a given `Lua` instance 2018-02-06 00:41:51 -05:00
kyren d43f8129f3 experimentally make `RegistryKey` Send 2018-02-06 00:05:35 -05:00
kyren fe35742026 Set the metatable of __gc'ed userdata to something more informative 2018-02-05 14:40:20 -05:00
kyren 6382baa991 Use ptr::write to initialize uninitalized memory, NOT mem::replace 2018-01-27 18:38:00 -05:00
kyren 77eb73a50c Simplify handling of userdata __gc and resurrected userdata.
Now, simply remove the userdata table immediately before dropping the userdata.
This does two things, it prevents __gc from double dropping the userdata, and
after the first call to __gc, it prevents the userdata from being identified as
any particular userdata type, so it cannot be misused after being finalized.

This change thus removes the userdata invalidation error, and simplifies a lot
of userdata handling code.

It also fixes a panic bug.  Because there is no predictable order for
finalizers, it is possible to run a userdata finalizer that does not resurrect
itself before a lua table finalizer that accesses that userdata, and this means
that there were several asserts that were possible to trigger in normal Lua code
in util.rs related to `WrappedError`.

Now, finalized userdata is simply a userdata with no methods, so any use of
finalized userdata becomes a normal script runtime error (though, with a
potentially confusing error message).  As a future improvement, we could set
a metatable on finalized userdata that provides a better error message.
2018-01-27 18:27:01 -05:00
kyren 8527266d3b Add an API that exposes the functionality of `lua_getuservalue` and `lua_setuservalue` 2018-01-26 20:06:18 -05:00
kyren 0801104762 ACTUALLY expose `RegistryKey` API
Also fixes a safety issue with RegistryKey, where you could use RegistryKeys
with mismatching Lua instances.
2018-01-26 19:43:53 -05:00
Jonas Schievink ff847ea438 __gc would be safe now, reword MetaMethod docs accordingly 2018-01-26 21:31:01 +01:00
Jonas Schievink 0a4ae8d859 Additional `MetaMethod` docs 2018-01-26 19:44:35 +01:00
Jonas Schievink 79b028419f create_function docs: mention what returning `Err` does 2018-01-26 19:24:01 +01:00
Jonas Schievink 67f8e1d49c Fix rustdoc rendering warning 2018-01-26 18:35:21 +01:00
Jonas Schievink 2d89eb39da Don't use a `StdResult` alias for better docs.
This is a pretty opinionated change, but I find documentation to be
clearer when using plain old names everybody understands immediately.
2018-01-26 18:32:58 +01:00
kyren 79ba909db0 Experimentally use the `failure` crate for errors 2018-01-21 20:08:51 -05:00
kyren 685fc12aad Missed unprotected call to luaL_ref 2017-12-17 16:55:37 -05:00
kyren 42007260ca Add automatic Lua "user accessible registry" keys
Also, during the implementation of this, I noticed a problem with the 0.10
memory safety, which is that luaL_ref is also memory unsafe.  I attempted to
change the API to support luaL_ref potentially returning Result, but this change
will cause an enormous amount of API chaos, (just as an example, it becomes
impossible to implement Clone for LuaRef as is).  Instead, luaL_ref now is
guarded by gc_guard.
2017-12-17 00:46:22 -05:00
kyren e6d84a4bb3 Change API names, add unset function 2017-12-16 18:05:53 -05:00
kyren ad23fe83e0 auto formatting 2017-12-16 17:46:32 -05:00
kyren bfb6111e0a API for registry access via string keys only (for now)
Also includes some fixes for stack usage and changes an assert_eq to lua_assert
2017-12-16 17:44:13 -05:00
kyren 56c9493f23 spelling fix for my spelling fix 2017-12-05 07:30:34 -05:00
kyren d609d38675 spelling fixes 2017-12-05 00:12:00 -05:00
kyren 447810364a extra space 2017-12-04 23:57:08 -05:00
kyren 66a4e9a8e7 Add `ExpiredUserData` error and avoid what was previously a panic
Also make sure that panic messages clearly state that they are internal errors,
so people report them as a bug.  Since the only panics left are all internal
errors, just move the internal error message into the panic / assert macros.
2017-12-04 02:50:27 -05:00
kyren 80a98ef29c Couple of changes:
- Update readme, changelog, cargo version number in preparation for release
- Remove panicking behavior on recursive callback calls, add additional error
  variant for recursive callback errors.
2017-12-04 01:47:04 -05:00
kyren 0c644e7136 more reorganization in an attempt to shrink the size of lua.rs 2017-12-04 01:04:12 -05:00
kyren a44b6b5170 Move function and thread into their own modules, auto-formatting 2017-12-04 00:57:39 -05:00
kyren 51838f3509 Include garbage collector error type, remove unnecessary setmetatable wrapper 2017-12-04 00:35:13 -05:00
kyren d76935e683 I *THINK* this might actually be it, is rlua 'm' safe now? 2017-12-04 00:15:20 -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 e80e7d4540 missing push_string calls in util 2017-12-03 23:25:03 -05:00
kyren 67e8907f19 Couple of changes in preparation for 'm' safety:
- auto formatting
- add gc control to ffi
- add gc_guard to util functions
- use gc_guard to make util error handling functions never trigger __gc
  metamethod Lua errors even without __gc metatable wrapper
- sort of a technicality, don't call luaL_requiref outside of the Lua
  constructor, as it could trigger the garbage collector when user code has had
  a chance to set __gc metamethods.  Changes the API to load the debug table.
2017-12-03 23:01:03 -05:00
kyren 0bd676aa81 more refactoring 2017-12-03 21:19:32 -05:00
kyren c95f591935 remove specific protected functions in favor of generic protect_lua_call 2017-12-03 20:29:41 -05:00
kyren 37a3145ced missed stack size fix 2017-12-03 20:15:57 -05:00
kyren a490229f31 More refactoring towards mem error safety 2017-12-03 20:10:45 -05:00
kyren 0909ca34fc auto formatting 2017-12-03 18:25:53 -05:00
kyren e41c72d642 more refactoring trying to find a workable path to 'm' error safety 2017-12-03 18:15:31 -05:00
kyren 5742e3f20a still making small structural changes
slowly trying to refactor things until using all the protected calls in
protected_ffi is workable
2017-12-02 19:16:57 -05:00
kyren f51a822738 auto-formatting 2017-12-02 18:56:14 -05:00
kyren 8a6161b16f new strategy for protected ffi calls 2017-12-02 18:37:17 -05:00
kyren b7c80ec066 make some things private 2017-12-02 17:47:00 -05:00
kyren 2b7e89e7c6 move error / panic metatable creation 2017-12-02 17:13:46 -05:00
kyren fa1703d3d1 split macros into their own file 2017-12-02 17:04:33 -05:00
kyren 8a7e03978b Experimental protected versions of all used 'm' erroring functions 2017-12-02 15:41:53 -05:00
Timidger f9c451bd26 Add test ensuring behaviour is correct 2017-11-07 20:13:52 -08:00
Timidger 8ac27877e4 Only get gc on setmetatable if metatable isn't nil 2017-11-07 20:13:30 -08:00
Timidger a137086064 Check that we have enough room on stack for module 2017-10-29 15:26:40 -07:00
Timidger 71fdca5477 Fixed test to use Lua assert 2017-10-29 15:24:54 -07:00
Timidger 316c6976e4 Added pop after loading lua library 2017-10-29 14:54:55 -07:00
Timidger 26b7901ab3 Added test for loading unsafe debug library in Lua 2017-10-29 14:53:30 -07:00
Timidger 2658433bd1 Added ability to load debug lib, Fixes #52 2017-10-28 20:46:24 -07:00
kyren 892069edd6 Correctly wrap external errors so that Debug trait and Error::cause are correct 2017-10-26 16:49:16 -04:00
kyren deab88a851 Fix xpcall return values, make the tests a lot better. 2017-10-25 14:51:10 -04:00
kyren 773bf3e9ba Fix some clippy lints, possible edge case API incompatibility around HashMap 2017-10-24 16:15:57 -04:00
kyren f634ce1101 It turns out, luaL_ref uses 1 extra internal stack space
All my check_stack calls are wrong, and this blows up very easily in situations
with recursive data structures.
2017-10-24 08:53:26 -04:00
kyren e7661a5c27 auto-formatting 2017-10-23 16:42:20 -04:00
kyren 8c30acec4e Possibly better stack behavior 2017-10-23 15:17:46 -04:00
kyren ba183b0119 Fix quadratic behavior in bind 2017-10-23 14:50:47 -04:00
kyren 4b7a3403bc Cleanups of userdata handling, particularly around callbacks
First, make sure that `add_methods` cannot trigger another userdata registry
insert, causing an unintended panic.  Second, remove `RefCell` surrounding
userdata hashmap, as this change makes it no longer needed.  Third, add a
`RefCell` around `Callback` because FnMut means that callbacks cannot recurse
into themselves, and panic appropriately when this happens.  This should
eventually be turned into an error.
2017-10-14 18:26:09 -04:00
kyren c5a4dfd7eb more reorganization, move simple type defines to types.rs module 2017-09-30 01:27:18 -04:00
kyren 8324d9e648 move userdata tests into userdata.rs 2017-09-30 01:13:58 -04:00
kyren 7a45490aca crudely move LightUserData/UserData/AnyUserData to their own module 2017-09-30 01:08:08 -04:00
kyren cf764fbabe move table tests to table.rs 2017-09-30 00:53:28 -04:00
kyren f785180a77 Merge pull request #45 from jonas-schievink/string
Extend String API
2017-09-30 00:43:19 -04:00
kyren cc502379c1 Print CallbackError in a better way
CallbackError now, instead of displaying the cause description, instead prints
"callback error: <traceback>".  Since the cause is already in the cause chain of
the error, this avoids repeatedly printing the cause of callback errors along
the chain, and also actually prints the callback when using Display on each
error in the chain.
2017-09-26 11:36:50 -04:00
kyren 61dc2823a6 Merge pull request #47 from jonas-schievink/base--
Don't load the base library into the "base" global
2017-09-16 21:09:33 -04:00
Jonas Schievink a7a080b50a Don't load the base library into the "base" global
The stock Lua interpreter doesn't do this either. AFAIK the "base" library is supposed to be loaded into "_G" only as it contains functions like `assert` and `error`.
2017-09-17 00:07:19 +02:00
Jonas Schievink a5b6d8fc85 Add `String::as_bytes_with_nul`
This cannot be accomplished without using unsafe code, which justifies this addition in my opinion.

Also changes "null" to "nul" to be in sync with `std::ffi` docs. Naming is derived from `CStr::to_bytes_with_nul`, using `as_*` instead of `to_*` since this isn't doing any computation.
2017-09-15 23:33:28 +02:00
Jonas Schievink 0e4414fc0b Impl `AsRef<[u8]>` and generic `PartialEq` for `String`
Tests are also moved to the new string.rs file to ensure related functionality is in one place.
2017-09-15 23:10:53 +02:00
Jonas Schievink 823dd39e5d Move string and table wrappers into own files 2017-09-15 22:03:14 +02:00
Jonas Schievink 14d8b4a0a2 Fix links in `Variadic` docs 2017-09-15 20:56:46 +02:00
Jonas Schievink 22cbed0240 More documentation work 2017-09-14 22:59:59 +02:00
kyren d862c0f08e Add methods to get/set metatables on Table
Also make Table::raw_get actually use raw get function instead of lua_gettable!
2017-09-10 19:14:51 -04:00
kyren 13dc68c36d Rename 'lua lifetimes to actually be 'lua 2017-09-09 21:29:22 -04:00
kyren 5bf228fbd0 Fixup grammar error in doc comments. 2017-08-03 17:07:54 -04:00
kyren 50436d3463 autoformatting 2017-08-03 02:03:28 -04:00
kyren ffc9b032e7 Riiight, doctests don't even *show* warnings by default, this flag is important. 2017-08-02 17:12:34 -04:00
kyren b03397137b deny(warnings) on doctests I don't think is necessary anymore? 2017-08-02 16:37:55 -04:00
kyren 7c32ace204 Whoops, was testing removing that and placed it back in the wrong place 2017-08-02 16:37:30 -04:00
kyren 2553623b65 Provide custom allocators that ensure that OOM results in an abort
(closes unsafety hole)
2017-08-02 16:33:48 -04:00
kyren 16f57d18e5 Merge pull request #34 from jonas-schievink/better-error
[WIP] Enhanced errors
2017-08-02 16:00:08 -04:00
kyren c3c7d8c093 setmetatable should return the table 2017-08-02 15:56:16 -04:00
Jonas Schievink dd1d335cee Handle LUA_ERRERR 2017-08-02 21:41:35 +02:00
kyren 9c34d4b99f Fix soundness problems with rlua
setmetatable now wraps a __gc method in a cclosure that aborts on error, also
'debug' library is no longer provided.  We could provide just the subset of the
debug library that is sound, though.
2017-08-02 14:36:54 -04:00
kyren 820c38e806 Rename Active / Dead to better reflect their behavior 2017-08-02 13:05:26 -04:00
kyren f9f3d05804 Fix argument bugs with pcall / xpcall, add tests for it 2017-08-02 10:42:18 -04:00
Jonas Schievink 70f05ac068 Remove ErrorError 2017-08-02 14:01:00 +02:00
Jonas Schievink a43bfd8f63 Remove expected field from FromLuaConversionError 2017-08-02 13:56:28 +02:00
kyren f6cefca916 Remove stray 'for<'a>' of unused 'a lifetime 2017-08-01 18:35:09 -04:00
Jonas Schievink a1626399c4 Fix compilation 2017-08-01 23:43:51 +02:00
Jonas Schievink cb61d53ba5 Fix error message and shorten code 2017-08-01 23:42:42 +02:00
Jonas Schievink ed6e7ed5e7 Don't dispose whole traceback when it's not utf-8 2017-08-01 23:38:12 +02:00
Jonas Schievink 38a13c906e Remove "lua" prefix from error messages
Since this is `rlua::Error`, it should be clear that it refers to
Lua-related errors. Downstream crates want to define their own error
enums, which can add a prefix like "lua error:" to disambiguate.
2017-08-01 23:23:31 +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
Jonas Schievink ed0565c176 Fix handling of `CallbackError`
Previously, the traceback would be printed, but not the actual error.

I've removed traceback printing completely, not sure if that's a good
idea. A `Display` impl that outputs multiple lines feels weird.
2017-08-01 23:23:31 +02:00
Jonas Schievink 7e250dacce Enhance error messages 2017-08-01 23:23:31 +02:00
kyren f44917ff83 Replace _: () with () everywhere 2017-08-01 14:09:47 -04:00
kyren 8e9c93b9d1 Formatting, only implement tuple conversion up to 12 2017-08-01 13:57:51 -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 c1abc18066 Merge remote-tracking branch 'origin/master' into tuples 2017-08-01 13:02:58 -04:00
kyren 721ffc462d Callbacks should be 'static again, fix #33
Every time I do lifetime transmutation, I get it wrong.
2017-08-01 12:11:28 -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
kyren 8ba3886c96 Merge pull request #31 from jonas-schievink/clone-userdata
Relax requirements for UserData to impl FromLua
2017-07-30 14:57:35 -04:00
Jonas Schievink acabc3ec18 Relax requirements for UserData to impl FromLua
This was only allowed for `UserData` implementors that are also `Copy`.
This relaxes the requirement to be `Clone` instead.

While `Copy` makes sense to prevent allocations and other potentially
costly operations, other `FromLua` impls already do pretty expensive
stuff, so this seems worth it.
2017-07-29 15:53:37 +02:00
kyren ac37b2a0d4 Small typo fix 2017-07-28 10:57:19 -04:00
Jonas Schievink ad6cf21921 Document `Error`
I didn't yet document *everything* there is to say (in particular, how
exactly custom Rust errors can be passed through Lua), but I've some
changes to this type in mind that I'll do next.
2017-07-28 12:50:30 +02:00
kyren d415455ccb Fix several bugs with error handling in xxx_with_traceback functions
In resume_with_traceback, always use the coroutine stack for error handling so
we don't miss panics, in both _with_traceback functions remove the temporary
traceback entry from the stack.
2017-07-27 17:16:40 -04:00
kyren a2b77f37a2 'main_state' fix
Dont' confuse the state we're pushing the registry value for the main state to
with the main state itself, pop from the correct state.
2017-07-27 16:47:58 -04:00
kyren 3adacd5589 Merge pull request #27 from jonas-schievink/userdata
Few more examples and docs
2017-07-26 12:07:17 -04:00
kyren 8b6425dc39 Clean up lifetimes after LuaCallback typedef change 2017-07-26 11:43:38 -04:00
Jonas Schievink 2b182860f7 Don't use hlist macros in userdata example 2017-07-26 17:28:47 +02:00
Jonas Schievink f657d301da Document Lua::create_function 2017-07-26 16:38:10 +02:00
kyren bf6ef3ecad Fix wrong name of __newindex metamethod 2017-07-26 10:34:24 -04:00
Jonas Schievink bb662e5a12 Document the UserData trait 2017-07-26 01:55:29 +02:00
Jonas Schievink 4e52544bd1 Deny warnings in doc tests
This magical attribute is grossly underdocumented, but it works. And
it's literally the only thing that makes this work the way I want it to.
2017-07-25 23:41:58 +02:00
Jonas Schievink df5c8fa4b0 Remove unneeded variable from example
Apparently doctests swallow *all* of their output, including compiler
warnings, by default.
2017-07-25 22:58:18 +02:00
kyren 8515db4c82 Merge pull request #24 from jonas-schievink/examples
Enhance documentation and add more examples
2017-07-25 00:40:11 -04:00
kyren 8194c4d411 Use stack_guard when the function doesn't return Result
Also, simplify some things that used to use error_guard but now are not
2017-07-25 00:37:44 -04:00
Jonas Schievink 335ecbbac6 tiny typo 2017-07-25 02:13:11 +02:00
Jonas Schievink 54464b0842 AnyUserData docs 2017-07-25 02:11:17 +02:00
Jonas Schievink 58c80c05be Replace unneeded eval by exec 2017-07-25 02:05:57 +02:00
Jonas Schievink 34fd4a00ce Document UserDataMethods 2017-07-25 02:00:49 +02:00
Jonas Schievink e2aeca58ae Table docs and examples
This looks almost like the standard lib now :)
2017-07-25 01:40:53 +02:00
Jonas Schievink 09dc89895a Add an example 2017-07-25 00:42:59 +02:00
Jonas Schievink 1f2fc6455f Beef up the String API
Adds `as_bytes` to view the string as a `[u8]`. Unlike the conversion to
a `&str` slice, this cannot fail.

Adds tests for both functions, which made me notice that `to_str` is
broken when the string contains null bytes, so I made it use the
`as_bytes` method.
2017-07-25 00:37:37 +02:00
Jonas Schievink 0b7b7e9d79 Add Function::call example 2017-07-25 00:16:43 +02:00
Jonas Schievink 59ab95f6ff Beef up Function::bind docs + example 2017-07-25 00:05:36 +02:00
Jonas Schievink 63e0587d26 Remove "equivalent" Lua code from Function::bind
Not only was this code not equivalent, it didn't even run since varargs
cannot be used as an upvalue (it's multiple values, after all).

Since Lua does not allow passing 2 sets of variadic arguments to a
function, the resulting code would be *very* complex and would involve
packing both sets of varargs into tables, concatenating them, then
`table.unpack`ing them to finally pass them.

This complex code would only make the docs more difficult to understand,
which is the opposite effect I originally intended with this. Let's just
get rid of this bad equivalence.
2017-07-24 23:52:15 +02:00
Jonas Schievink 9b809a8197 Make examples adhere to API guidelines
> Examples use ?, not try!, not unwrap (C-QUESTION-MARK)

> Like it or not, example code is often copied verbatim by users.
> Unwrapping an error should be a conscious decision that the user
> needs to make.
2017-07-24 23:45:24 +02:00
kyren 69fa01df45 auto formatting 2017-07-24 10:40:00 -04:00
kyren b3b0f17f59 Slight changes for consistency
I am not actually sure what the best pattern is to import conflicting
standard types, but this is at least consistent.
2017-07-24 07:30:29 -04:00
kyren 698785df64 Merge remote-tracking branch 'base/master' into remove-lua-prefix 2017-07-24 07:21:54 -04:00
kyren c7d2311c6a Do several more Lua prefix renames, add prelude module
Rename the following:

LuaNil => Nil
LuaExternalError => ExternalError
LuaExternalResult => ExternalResult
LuaCallback => Callback (internal only)

Use qualified re-exports at the top of the module.

Add a new public 'prelude' module which re-exports everything with a
non-conflicting name (Adds back the Lua prefix), and is meant to be imported
unqualified.
2017-07-24 07:12:52 -04:00
kyren 44c99ea1b9 Remove error_guard
Replace with custom protected versions of lua ffi functions.
2017-07-23 13:41:46 -04:00
Jonas Schievink 8f044755dc Fixes after rebase 2017-07-23 18:37:48 +02:00
Jonas Schievink b47f9e0d76 Continue renames in comments/strings 2017-07-23 18:36:50 +02: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 91dbbfe759 More aggressively remove code from error_guard 2017-07-23 10:41:51 -04:00
Jonas Schievink 984ade66cc Make test_expired_userdata less noisy
The printing was cluttering the test runner output
2017-07-23 12:51:14 +02:00
Jonas Schievink 1c53ba3d4c Add a test ensuring that userdata is dropped 2017-07-23 12:50:42 +02:00
kyren 2bd7a2ee8c Reduce error_guard code to as little as possible
Also ensure that on error in error_guard the stack is in a predictable place.
2017-07-23 02:08:32 -04:00
kyren 36134e6373 Userdata can have __gc metamethods called multiple times
Lua 5.3 has the ability for scripts to define __gc metamethods on
tables, which gives them the ability to "resurrect" userdata after __gc
has been called.  This means, __gc can be called multiple times on
userdata.  This commit protects against this by simply panicking on
access after resurrection.  This is possibly not the best approach?
2017-07-23 01:00:33 -04:00
kyren 396a4b0916 Possibly this fixes rust stable? 2017-07-19 21:32:54 -04:00
kyren 5b723d58be Allow callback functions to have 'lua lifetime rather than 'static
Fixes #14
2017-07-19 21:28:16 -04:00
kyren 6df96d8eb1 Rename LightUserData to LuaLightUserData for consistency
I know, this is the opposite of PR #17 wishes to do, please don't take this as
an indication that I would wish to do the opposite.  I actually want to discuss
PR #17 with you, but I'm not sure about it yet, and my pedantry will not allow
me to let this remain inconsistent in the meantime.  This way, either way it's
consistent haha.
2017-07-19 20:15:46 -04: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 cc216721b8 slightly cleaner way of linking to an external liblua5.3, if the option is enabled 2017-07-09 17:05:54 -04:00
kyren 6b8a4240e2 format fix, fixes rustfmt warning 2017-06-30 15:17:53 -04:00
kyren d9478d6cd7 Comments should be wrapped at 100 lines, according to standard 2017-06-27 14:05:49 -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 7dba280a4b Tests for LuaError conversion, Important pcall / xpcall bugfixes. 2017-06-25 02:40:09 -04:00
kyren cbae1a805a This is a SLIGHTLY better implementation I think. 2017-06-25 02:04:14 -04:00
kyren 2c439f8097 Not sure I like everything about this approach yet 2017-06-25 01:47:55 -04:00
kyren a609f709ee A lot of corner case bugfixes 2017-06-25 01:10:26 -04:00
kyren b59b8cc23b Different strategy.. 2017-06-24 22:26:35 -04:00
kyren 1fda34225e Small improvements to WrappedError
Currently trying to figure out how to make LuaError a proper LuaUserDataType
2017-06-24 21:44:27 -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 802d5467c1 Change LuaError ToLua approach
Lua should be consistent independent of the way they are produced.  pcall in lua
should produce the same sort of error that would be returned by a LuaError
conversion.

The situation is not currently great, because LuaError is not Clone, so passing
a LuaError back into rust will result in the error being "consumed".
2017-06-23 19:41:08 -04:00
kyren 8e3a9f0e84 Add ToString metamethod, make LuaError implement LuaUserData
LuaError implementing LuaUserData makes it easy to return LuaResult from a
callback to implement callback functions that can error.
2017-06-23 15:24:03 -04:00
kyren 3ab3970c01 ACTUALLY correctly limit numeric conversions
Don't mistakenly do rust-side conversions from integer <-> number
2017-06-23 00:51:16 -04:00
kyren 918edad1b2 Merge pull request #13 from jonas-schievink/example
Add a few examples
2017-06-22 14:09:36 -05:00
Jonas Schievink 979e1d1675 Add example to `LuaString::to_str` 2017-06-22 10:49:18 +02:00
kyren 9dc0a3e098 Simplify load / exec / eval
load is the fundamental operation here
2017-06-21 19:40:18 -05:00
Jonas Schievink f75385305c Add an example to `LuaFunction::bind` 2017-06-22 00:38:08 +02:00
Jonas Schievink 2e87556a1b Add example to `LuaThread::resume`
Adapted from #8
2017-06-22 00:28:44 +02:00
Jonas Schievink 14c168f118 Add `Lua::load` for precompiling chunks
This allows loading scripts into memory, performing a syntax check and
precompiling them, without immediately running them like `exec` and
`eval` do.
2017-06-22 00:16:30 +02:00
kyren 06cd2c8e68 Add numeric conversion test 2017-06-21 16:53:52 -05: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
kyren 7924a910e1 typo fixes 2017-06-19 02:08:50 -05:00
kyren a0e83b3d1b Big API change for tables
Removes the callback versions of loops over LuaTable, instead now there are
'pairs' and 'ipairs' iterators over them.
2017-06-19 02:04:00 -05:00
kyren f1dee39416 update reference to raw_length method 2017-06-18 17:11:55 -05:00
Jonas Schievink 16ae4720d6 Rename `LuaString::get` to `to_str`
This is what similar types in libstd do (`CStr::to_str`,
`OsStr::to_str`, `Path::to_str`).
2017-06-18 14:48:45 +02:00
Jonas Schievink a47a6e32ef Rename `LuaTable::has` to `contains_key`
This is what all Rust maps use
2017-06-18 14:39:18 +02: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 ba9f7a2ee7 Add mostly untested missing metamethods, improve documentation about them 2017-06-18 00:28:55 -04:00
kyren 56a30fba2e Slightly more palatable coroutine API 2017-06-17 23:50:40 -04:00
kyren 4d34ccdba1 Merge pull request #9 from jonas-schievink/docs
Documentation
2017-06-17 23:28:13 -04:00
kyren edc5fc8ce3 ACTUALLY check the status of lua threads before calling resume 2017-06-17 22:40:09 -04:00
Jonas Schievink 0e14d787b7 Documentation 2017-06-18 03:31:20 +02:00
kyren 32c83d77b7 small warning / clippy fixes, doc comments 2017-06-15 16:27:39 -04:00
kyren 484479477b Merge pull request #4 from jonas-schievink/result-to-lua-dejavu
Allow passing `Result<T, E>` to Lua
2017-06-15 15:59:20 -04:00
kyren 0d652a3c94 Merge pull request #5 from jonas-schievink/who-needs-macros
Remove src/macros.rs
2017-06-15 15:55:54 -04:00
kyren fc9164ab9f Merge pull request #6 from jonas-schievink/cfg_attr
Utilize `cfg_attr` instead of duplicating code
2017-06-15 15:55:06 -04:00
kyren 0022057058 rustfmt changes 2017-06-15 10:26:39 -04:00
Jonas Schievink 6b651820b6 Utilize `cfg_attr` instead of duplicating code 2017-06-14 01:30:33 +02:00
Jonas Schievink 5019396bd7 Remove src/macros.rs
It's not used by anything. It's not even included via `mod macros;`.
2017-06-14 01:24:38 +02:00
Jonas Schievink 80be9e8091 Allow passing `Result<T, E>` to Lua
For this to work, both `T` and `E` need to implement `ToLua`. An `Ok(t)`
passes the contained `T`, while an `Err(e)` passes `nil` followed by the
contained `E`. This matches the common Lua idiom used by functions like
`io.open`.

Closes #3
2017-06-14 01:17:41 +02: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 8203414b76 Use LUA_RIDX_MAINTHREAD instead of weird bespoke method 2017-06-05 05:03:18 -04:00
kyren 7436e84e93 make sure other table methods do not trigger metamethods and errors 2017-06-05 04:10:54 -04:00
kyren cb7c55f742 Don't need pub on internal function 2017-06-05 01:51:48 -04:00
kyren 1c0b1014ee Improve performance of create_table / create_array_table 2017-06-05 01:46:45 -04:00
kyren 9aed99e3e3 atpanic function was not a good idea, it's not sound
It crosses the C api boundary, the only proper way to panic would be to actually
error guard everywhere, aborting is fine.
2017-06-05 01:05:41 -04:00
kyren b3218137e1 Somewhat smarter strategy for error_guard calls, less ungodly slow.
Also add raw_length table function
2017-06-05 00:41:48 -04:00
kyren 47d4ea62ff Handle unprotected lua errors SOMEWHAT more elegantly
There should be drastically less ways to cause unprotected lua errors now, as
the LuaTable functions which were trivial to cause unprotected errors are now
protected. Unfortunately, they are protected in a pretty slow, terrible way
right now, but it at least works.

Also, set the atpanic function in lua to call a proper rust panic instead.
2017-06-05 00:03:39 -04:00
kyren e265633fb3 Callback versions of table functions 2017-05-26 23:49:12 -04:00
kyren 53b001cfce doc update again to test submodules 2017-05-25 12:12:12 -04:00
kyren c88762e90f Small doc update (secretly this is just to test submodules) 2017-05-25 12:01:12 -04:00
kyren acd0611692 Make Lua::to / Lua::from operate the correct way around
I know that Lua::to uses FromLua and Lua::from uses ToLua, but it only
makes sense that Lua::from(42) would return the LuaValue for 42, and
that Lua::to::<i64>(v) would convert the given lua value TO an integer.
The way it was just incredibly backwards.
2017-05-25 00:47:48 -04:00
kyren 87a395206d Correct checking of LuaRef origin, support lightuserdata
All lua types should now be at least somewhat usable from rust, if
incompletely so.  Any lua value should be readable in Rust as a
LuaValue, pop_value should never panic except in internal logic errors.
2017-05-25 00:43:35 -04:00
kyren 0111625d17 Basic coroutine support, currently very slightly broken
There is no longer any protection in passing LuaValue between
independent states, it is being re-added
2017-05-24 23:29:57 -04:00
kyren 5c0f183a52 Improved error handling and formatting
Now prints lua backtraces on callback errors as well.  This could be
controlled with LUA_BACKTRACE or just RUST_BACKTRACE or similar.
2017-05-22 14:25:36 -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 edb86bdeb7 Doc updates, remove unused functions 2017-05-21 22:32:16 -04:00
kyren 065c69894a Initial import 2017-05-21 19:50:59 -04:00