Commit Graph

78 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 2bbb203050
Revert "Make Debug interface more user friendly"
This reverts commit b3b8d79446.
2023-07-06 13:32:11 -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 b3b8d79446
Make Debug interface more user friendly
- use String instead of Vec<u8>
- update docs
- unify fields between lua5.x/luau
- line numbers are `usize`
2023-07-06 00:38:33 +01:00
Alex Orlenko c1168d3ec1
Refactor `call_async()` functions to use static dispatch outside of traits 2023-06-21 12:44:24 +01:00
Alex Orlenko cf0524aa23
Use lua_iscfunction instead of lua_getinfo in `Function::environment()` 2023-06-08 09:33:48 +01:00
Alex Orlenko 9596f2e9ee
Fix warning when compiling for lua51 2023-06-03 14:24:34 +01:00
Alex Orlenko 1dc32452e6
Support getting and setting environment for Lua functions.
Closes #218
2023-06-03 12:56:49 +01:00
Alex Orlenko baf25e263f
Change _mlua to __mlua prefix for internal chunk names 2023-05-30 00:36:09 +01:00
Alex Orlenko 3abf73dee5
Update `FunctionInfo` doc and interface 2023-05-30 00:33:57 +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 4daa7de997
Various improvements for owned types, including:
- tests
- shortcuts for `OwnedFunction` and `OwnedAnyUserData`
2023-04-26 15:40:48 +01:00
Alex Orlenko 0fccdfed5c
Fix feature flags for owned types 2023-04-14 01:17:26 +01:00
Alex Orlenko aaf0a5e44a
Remove usage of crate::ffi (clippy) 2023-04-14 00:36:31 +01:00
Alex Orlenko 65e72f39ae
Remove unstable feature flag from Function::wrap/wrap_mut/wrap_async 2023-04-14 00:21:18 +01:00
Alex Orlenko f66932e8d2
Revert "Rename `Owned*::to_ref()` to `as_ref()`"
This reverts commit 5394faca16.
2023-03-30 22:35:43 +01:00
Alex Orlenko d9aac08b81
Support setting memory limit for Lua 5.1/JIT/Luau
Other versions already support this feature.
Closes #119
2023-03-26 00:06:52 +00:00
Alex Orlenko 22c973af02
Async: Don't clone function when executing it from recycled thread 2023-03-03 18:22:39 +00:00
Alex Orlenko 5394faca16
Rename `Owned*::to_ref()` to `as_ref()` 2023-03-02 15:36:11 +00:00
Alex Orlenko 1d4a135e8e
Add `Function::wrap`/`Function::wrap_mut`/`Function::wrap_async` to wrap functions into a type that implements `IntoLua` trait.
This is useful to avoid calling `lua.create_function*` every time when `Function` handle is needed.
2022-12-22 16:24:35 +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 56abc4a700
Refactor `AsChunk` trait 2022-12-19 21:12:36 +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 29c6c9cb58
Fix clippy warnings 2022-10-09 14:08:33 +01:00
Alex Orlenko e523fb2c86
Update to Luau 0.548 (luau-src >=0.4) 2022-10-08 23:34:47 +01:00
Trisha 20a16839aa
Fix typo in doc comment 2022-08-23 01:47:17 +01:00
Alex Orlenko 4a25eab257
Merge pull request #189 from hack3ric/master
`Function::bind`: simply clone the function if args are empty `MultiValue`
2022-07-22 00:28:18 +01:00
Alex Orlenko 40fe937878
Fix a bug in `Function::bind` when args and binds are empty
This leads to a Lua assertion due to using wrong stack index
2022-07-22 00:24:53 +01:00
Eric Long f3f173fcb6
`Function::bind`: simply clone the function if `args` are empty `MultiValue` 2022-07-21 20:54:49 +08:00
Alex Orlenko 0076aa735a
Add `Function::coverage` for Luau to obtain coverage report 2022-05-24 02:01:46 +01:00
Alex Orlenko 8d71ea79aa
Cache bytecode for internal Lua chunks 2022-05-16 20:29:02 +01:00
Alex Orlenko 2a8c5c7f82
Refactor `Function::bind` implementation.
Make it possible to bind async function arguments.
Fixes #161
2022-05-15 01:15:31 +01:00
Alex Orlenko 5133a9837a
Add `Function::info()` to get information about functions.
Closes #149 and #7.
2022-04-18 18:28:11 +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 ec1fa04085
Update docs 2022-03-25 00:43:54 +00:00
Alex Orlenko c322e028e2
Initial Luau support 2022-03-20 20:30:20 +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 5b1483bd56
Change syntax of `protect_lua` macro 2021-09-28 18:47:08 +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 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 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 0bad4a0ff9 Fix spelling 2021-05-10 19:53:38 +01:00
Alex Orlenko e8505b5239 Change signature of Function::dump() to remove Result 2021-05-02 11:48:42 +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 dd58cdad52 Add Function::dump() to dump lua function to a binary chunk 2020-07-27 23:26:33 +01:00
Alex Orlenko 687ecc9247 Update documentation 2020-05-15 01:48:57 +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 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 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 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 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 f0186d1799 Provisional "fix" for #71. Requires nightly :( 2018-02-15 21:39:35 -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 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