Commit Graph

72 Commits

Author SHA1 Message Date
Michael Pfaff 061f84f702
Turn more comments into doc comments, improve debuggability 2023-07-16 14:39:35 -04:00
Michael Pfaff 96575e6ab5
More inline, make some methods and constructors public, add create_c_closure 2023-07-06 13:06:17 -04:00
Michael Pfaff 11d81209d9
API changes, inline more often 2023-07-06 13:06:08 -04:00
Alex Orlenko c905a34b1d
(Luau) Set thread globals to main thread globals when resetting the thread 2023-06-02 21:13:23 +01:00
Alex Orlenko e0224ab159
Use futures-core and futures-tasks via futures-util.
Just to reduce number of dependencies.
2023-05-29 00:30:29 +01:00
Alex Orlenko 6dee339783
Use `lua_closethread` in `AsyncThread::drop()` 2023-05-28 01:43:15 +01:00
Alex Orlenko 1c66a02878
Update to Lua 5.4.6 2023-05-21 00:55:06 +01:00
Alex Orlenko aaf0a5e44a
Remove usage of crate::ffi (clippy) 2023-04-14 00:36:31 +01:00
Alex Orlenko 3e83753466
Add `Thread::set_hook()` function 2023-04-08 23:53:48 +01:00
Alex Orlenko 483bc80fc4
Add `must_use` to `AsyncThread` 2023-04-05 00:23:13 +01:00
Alex Orlenko 1be927bc5d
Don't call error handler for memory errors in coroutines 2023-03-30 17:29:57 +01:00
Alex Orlenko d7db1b7f2e
Add Waker lifetime to WakerGuard 2023-03-03 18:29:04 +00:00
Alex Orlenko 8c18fa1764
Async: store pointer to Waker in extra data rather than in Lua ref thread 2023-03-03 15:19:54 +00:00
Alex Orlenko a13c188de3
Rename ToLua/ToLuaMulti -> IntoLua/IntoLuaMulti 2022-12-19 23:00:47 +00:00
Alex Orlenko c60f633a62
Add "unstable" feature flag.
Hide owned types under the new feature flag.
Drop OwnedString/OwnedThread types (unlikely they are useful).
2022-12-19 22:26:44 +00:00
Alex Orlenko 9b4e3a1598
Refactor LuaInner state
Add static_assertions to check for auto traits impl on compilation stage
Bump MSRV to 1.63 (required for `Ref::filter_map`)
2022-12-19 16:09:05 +00:00
Alex Orlenko bf79d9e75d
Initial implementation of owned Lua types 2022-12-18 00:35:41 +00:00
Alex Orlenko fcd162f3eb
Replace Lua::ref_thread_exec 2022-10-22 23:39:49 +01:00
Alex Orlenko 0cd724f63b
Fix Lua assertion when inspecting another thread stack.
The thread can be dead and it's not safe to call __tostring metamethod (if present) on error object.
Fixes #195
2022-08-01 22:07:39 +01:00
Alex Orlenko ab029b087d
Close to-be-closed variables for Lua 5.4 when using call_async functions
Fixes #192
2022-07-31 15:33:02 +01:00
Alex Orlenko 86f506a170
Fix clippy warnings 2022-04-14 21:55:36 +01:00
Alex Orlenko d1c80be033
Don't cast *const to *mut (for pointers comparison) 2022-04-08 22:52:55 +01:00
Alex Orlenko 55fac90a74
Fix Luau documentation in docs.rs
Enable `Lua::gc_inc` for Luau
Mark `debug` module as safe for Luau
2022-04-08 20:02:12 +01:00
Alex Orlenko 0ea65a2985
Fix doc test 2022-04-03 22:13:54 +01:00
Alex Orlenko 87c10ca93d
Sandboxing support 2022-03-28 23:42:35 +01:00
Alex Orlenko 714dd6249f
Enable Thread::reset for Luau 2022-03-23 21:13:48 +00:00
Alex Orlenko eed7b1f3af
More ffi module refactoring 2022-03-20 20:30:20 +00:00
Alex Orlenko 6dc127f4eb
Refactor ffi module
Initial Luau support work
2022-03-20 20:30:18 +00:00
Alex Orlenko 2fee3e7891
Update docs 2021-11-25 18:01:41 +00:00
Alex Orlenko 19bd254e1e
Update comments 2021-11-14 23:27:20 +00:00
Alex Orlenko 50f20e0c2c
Add thread (coroutine) cache to reset and later reuse to execute async functions.
It works on Lua 5.4 and LuaJIT (vendored) with `lua_resetthread` function.
2021-11-14 23:19:47 +00:00
Alex Orlenko 2c7d7117d2
Optimize MultiValue allocations (recycle old container) 2021-11-12 10:55:20 +00:00
Alex Orlenko ed48b11e7f
Update documentation references
Using rustdoc links (see RFC https://github.com/rust-lang/rfcs/pull/1946)
2021-10-12 00:49:45 +01:00
Alex Orlenko d098c9ccf6
Refactor Waker handling in async code.
Instead of storing `Option<Waker>` in the Lua registry, store it on the reference thread.
It gives approx +10% performance gain when calling async function.
2021-10-03 22:09:19 +01:00
Alex Orlenko c62b17a5c8
Fixed bug when polling async futures (#77)
We expect first value returned via coroutine.yield() to be a special Pending type.
But instead we checked second value.
2021-10-02 07:23:24 +01:00
Alex Orlenko e42d67c70d
Make `protect_lua` as a smart macro to choose from C/closure 2021-09-28 16:26:30 +01:00
Alex Orlenko ee1c8a1a3d
Add inline attributes to few hot funcs 2021-09-28 16:19:29 +01:00
Alex Orlenko 1731f5d61b
Revert "Make `protect_lua` as a smart macro to choose from C/closure"
This reverts commit 84fe5f7f76.
2021-07-08 18:41:10 +01:00
Alex Orlenko 60822d12d2
Revert "Move away from metatable hashmap cache to direct keys"
This reverts commit adbc9ccc9b.
2021-07-08 18:40:14 +01:00
Alex Orlenko adbc9ccc9b
Move away from metatable hashmap cache to direct keys 2021-07-08 15:37:18 +01:00
Alex Orlenko 84fe5f7f76
Make `protect_lua` as a smart macro to choose from C/closure 2021-07-07 12:54:19 +01:00
Alex Orlenko d3f44354e0 Revert commit ced808d5ab
I think this experiment is unsuccessful and does not work well in a module mode
with dynamic symbols resolution and mixing between different mlua instances.
Overall the Rust bug has been fixed and we can wait for the "C-unwind" feature become stable.
2021-06-16 22:13:01 +01:00
Alex Orlenko 6e52bb7e65 Fix clippy warnings && tests 2021-06-13 23:30:54 +01:00
Alex Orlenko 5293b8d6d2 Add `Thread::reset()` for luajit/lua54 2021-05-05 11:11:32 +01:00
Alex Orlenko 585c0a25d8 Replace 'Thread already finished' error with common `Error::CoroutineInactive` 2021-05-03 13:11:59 +01:00
Alex Orlenko 26d8d899f2 Allocate Waker slot in Registry in re-use it (instead of creating new userdata for it) 2021-05-02 13:04:02 +01:00
Alex Orlenko 67bc0b1196 Make AsyncPollPending internal value as LightUserData 2021-05-02 12:06:32 +01:00
Alex Orlenko 3f55958bdd Stack assertions review
Other minor code and documentation updates
2021-05-02 11:42:03 +01:00
Alex Orlenko ced808d5ab Don't trigger longjmp in rust.
Motivation behind this change is upcoming breaking change in Rust
compiler v1.52.0 to prevent unwinding across FFI boundaries.
https://github.com/rust-lang/rust/pull/76570
The new functionality requires nightly compiler to declare FFI
functions as "C-unwind".
The fundamental solution is to use C shim to wrap "e" and "m"
Lua functions in pcall.
Additionally define Rust calling convention to trigger lua_error
on Rust behalf.
2021-04-27 00:29:38 +01:00
Alex Orlenko 9f82cbe0c5 Update documentation 2020-12-31 13:39:38 +00:00
Alex Orlenko 687ecc9247 Update documentation 2020-05-15 01:48:57 +01:00
Alex Orlenko 539b569ff4 Add Lua 5.4 (rc2) support 2020-05-11 02:43:34 +01:00
Alex Orlenko 0efa0fcb6a Update documentation 2020-04-20 01:52:01 +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 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 6874c2e004 Fix examples and docs 2019-11-04 22:23:15 +00:00
Alex Orlenko cb109f6e36 Rename to mlua 2019-10-01 16:11:12 +01:00
Alex Orlenko affa85feb0 Backport changes from rlua 0.16 (master branch) 2019-09-29 12:53:13 +01:00
kyren 2e1bdb64c0 format with up-to-date rustfmt 2018-08-05 09:51:39 -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 ee23f199f0 Remove `stack_guard` function and instead just use StackGuard directly 2018-03-12 13:13:44 -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 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 c22aae461b Some changes for panic correctness, stack usage correctness, and speed 2018-02-12 13:54:31 -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 ad23fe83e0 auto formatting 2017-12-16 17:46:32 -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 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