478 Commits

Author SHA1 Message Date
Alex Orlenko 1cd2bdc808 Ignore test_async_require on windows 2025-06-23 16:37:46 +01:00
Alex Orlenko f8ed33a2aa Fix tests 2025-06-23 16:23:53 +01:00
Alex Orlenko 25955893e0 (Luau Require) Resolve Lua file path relative to the current directory
and unrelated to Rust source file location.
When a Lua file is required inside a Rust file (in a chunk), we should resolve the Lua file relative to the current directory,
instead of relative to the Rust chunk path.
The Rust file location is an internal information that does not exist when the compiled binary runs.
Fixes #605
2025-06-23 15:53:35 +01:00
Alex Orlenko 3f0c69b70b Fix logic to terminate futures on drop.
The underlying Lua thread must stay in yielded state rather than finished.
2025-06-17 15:25:21 +01:00
Alex Orlenko f539f60987 Fix Function::deep_clone() method (Luau).
The `lua_clonefunction` function can fail (and trigger GC) so we need to return Result instead of allowing longjmp
2025-06-16 21:41:29 +01:00
Alex Orlenko 634e5d4550 Reduce collectgarbage options in sandboxed mode
See https://luau.org/sandbox#library
2025-06-13 15:47:54 +01:00
Alex Orlenko 7bc72be7d3 Use serde feature flag instead of serialize.
The old one is still supported.
2025-06-12 13:35:22 +01:00
Alex Orlenko 39cac5699a Add unwinding support (returning an Error) to Luau Require implementation 2025-06-06 13:46:51 +01:00
Alex Orlenko 65e292dac4 More Luau require tests 2025-06-03 23:01:50 +01:00
Alex Orlenko 76a8f8cc71 Add __type to Error's userdata metatable.
Close #585
2025-05-27 01:31:54 +01:00
Alex Orlenko f36aaa5ce1 Add loadstring function to Luau
Closes #578
2025-05-15 11:10:42 +01:00
Alex Orlenko c5c1fe3b85 Fix tests 2025-05-14 00:19:29 +01:00
Alex Orlenko f16aca687d Terminate underlying Rust future when AsyncThread is dropped.
Before this change, Lua GC was responsible to collect and destroy the future if
`AsyncThread` dropped in yielded state.
Now we will propagate "drop" event immediately so Lua GC need to only free the memory.
2025-05-09 12:48:40 +01:00
Alex Orlenko 5dc6c3214b Prepare for 2024 edition 2025-05-06 21:28:21 +01:00
Alex Orlenko ed796fff51 Support async require loaders for Luau 2025-05-04 11:00:59 +01:00
Alex Orlenko 4fa8e645b7 Fix Luau "require" tests 2025-05-03 21:45:39 +01:00
Alex Orlenko 4a3dbafb6e Update scoped userdata mismatch tests 2025-05-01 13:12:00 +01:00
Alex Orlenko 97ca3e2c08 Check that type passed to scoped userdata self argument is userdata.
If passed type is non-userdata we try to get a pointer (which will be null) that triggers an assertion.
Having a check also allow us to generate right error message.
Fixes #569
2025-05-01 13:09:23 +01:00
Alex Orlenko 8e1df48e81 Add encode_empty_tables_as_array serialize option.
This will change the behaviour of encoding empty Lua tables into array instead of map.
2025-04-26 17:53:56 +01:00
Alex Orlenko 64b1d152b9 Deprecate Lua::load_from_finction and replace it with Lua::register_module and Lua::preload_module instead. 2025-04-26 13:42:07 +01:00
Alex Orlenko 560a30ca02 Support new Luau require system
This commit introduces the `Require` trait that be used to change `require` behaviour.
By default mlua implements behaviour same as `ReplRequirer` in the original Luau.
Unfortunately binary Luau modules are no longer supported by the new system.
2025-04-25 14:19:41 +01:00
Alex Orlenko 49958f4827 Split Luau thread event callback to creation and collection callbacks.
We need this because they have different requirements:
- Thread creation callback can return Error or panic
- Thread collection callback runs during Luau GC cycle and cannot make any Lua calls or trigger panics.
2025-04-06 13:57:15 +01:00
Alex Orlenko b805939320 Make Lua::weak() method and WeakLua struct public.
This can be useful to prevent circular dependencies between Rust and Lua
or check that Lua instance is still alive.
2025-04-05 23:40:05 +01:00
Alex Orlenko 53ff494ab9 Prepare for custom (Luau) userdata destructors.
We need to add logic later to prevent calling any Lua functions when UserData destructor is running.
2025-04-04 16:36:06 +01:00
Alex Orlenko c1a018a60d Add AnyUserData::type_id method 2025-03-31 22:41:42 +01:00
Alex Orlenko 1f970824b4 Support user thread creation callback (Luau) 2025-03-28 11:51:35 +00:00
Alex Orlenko b0140cdb9e Add Chunk::name(), Chunk::environment() and Chunk::mode() functions.
They can be used to retrieve existing chunk params.
2025-03-22 09:31:24 +00:00
Alex Orlenko 806817212e Rename Lua::init_from_ptr to Lua::get_or_init_from_ptr.
Return reference to `&Lua` with unbound lifetime (chosen by user).
2025-03-21 21:28:30 +00:00
Alex Orlenko 95c623e94d Use c string literal where appropriate 2025-03-21 15:57:15 +00:00
Alex Orlenko 4fe7d151a1 Refactor userdata-wrappers feature.
Support borrowing underlying data in `UserDataRef` and `UserDataRefMut`.
2025-03-21 14:19:38 +00:00
Alex Orlenko 69011a89d2 Revert "Add initial pluto support"
This reverts commit 0ed11e4134.
2025-03-14 22:59:06 +00:00
Alex Orlenko 0ed11e4134 Add initial pluto support
Pluto is a superset of Lua 5.4 with a focus on general-purpose programming.
`pluto` feature also enables `lua54` feature since they are compatible and share the same API.
2025-03-14 11:38:07 +00:00
Alex Orlenko 0ce599aff2 Update test case 2025-03-13 17:41:13 +00:00
Alex Orlenko 1ebb4b468a Support 52-bit integers for Luau
Simply to float conversion (it actually never fails or goes out of range)
2025-03-13 16:18:44 +00:00
Alex Orlenko ae7cdcb934 Remove (internal) borrow counter and use instead "locked" flag and strong reference counter 2025-02-14 14:41:37 +00:00
Alex Orlenko a01b032c35 Add bstr/serde dependency if serialize feature flag is enabled 2025-02-11 13:39:21 +00:00
Alex Orlenko 18497f1528 Add library constants support for Luau compiler.
Add ability to specify compile-time constants for known library members.
2025-02-11 00:16:22 +00:00
Alex Orlenko 28e8f56989 Fix tests 2025-02-09 22:17:25 +00:00
Alex Orlenko c1f8abba9e Do not allow recursive warnings (Lua 5.4) 2025-02-09 15:08:52 +00:00
Alex Orlenko 5bbd23ed1a Fix hook tests 2025-02-08 11:51:38 +00:00
Alex Orlenko 74b4601b48 Rework Lua hooks:
- Support global hooks inherited by new threads
- Support thread hooks, where each thread can have its own hook

This should also allow to enable hooks for async calls.
Related to #489 #347
2025-02-07 22:42:17 +00:00
Alex Orlenko 2b6172ef38 Fix tests 2025-02-05 19:01:07 +00:00
Joel Natividad 20f7ce097d Fix typos (#522)
* fix various typos in the codebase

* fix typos in CHANGELOG.md
2025-02-05 16:16:20 +00:00
Alex Orlenko fca38a6637 Imporove BorrowedStr/BorrowedBytes ergonomic.
Implement `FromLua` and `IntoLua` for these types to allow working with them directly.
2025-01-30 23:07:02 +00:00
Alex Orlenko cdd6a99136 Support Thread::resume_error call (Luau)
This method uses Luau-specific C API extension `lua_resumerror`
that allow to throw an error immediately when resuming a thead.
Closes #500 #513
2025-01-28 22:57:26 +00:00
Alex Orlenko 8574682ffc Improve From/Into Lua char conversion 2025-01-28 10:41:10 +00:00
tk 47bc372096 impl FromLua/IntoLua for char (#516) 2025-01-28 10:10:28 +00:00
Alex Orlenko d376cb9403 Enable Thread::reset() for all Lua versions 2025-01-28 10:08:16 +00:00
Alex Orlenko ea5ecccf02 Change AsyncThread<A, R> to AsyncThread<R>.
Push arguments in `Thread::into_async()` to the thread during the call instead of first poll.
The pushed arguments will be automatically used on resume.
Fixes #508 and relates to #500.
2025-01-28 10:08:08 +00:00
Alex Orlenko cd4091f64d Allow exhaustive match on Value.
It was not possible because `ValueRef` variant in `Value::Other` was private.
Closes #502 and #503
2024-12-10 23:37:19 +00:00