Alex Orlenko
f06d0020ea
Add test to emulate method through field
2025-08-28 23:50:18 +01:00
Alex Orlenko
d399559d30
Add Lua::yield_with to allow yielding Rust async functions and exchange values between Lua coroutine and Rust.
...
This functionality is similar to `coroutine.yield` and `coroutine.resume` without C restrictions.
2025-08-28 18:41:24 +01:00
Alex Orlenko
30735d5ff1
Fix thread recovery when pushing a bad arg
...
We should not erase thread stack if a bad argument is pushed before resuming the thread.
2025-08-25 23:07:37 +01:00
Alex Orlenko
347856b806
Do not try to yield at non-yielable points in Luau interrupt
...
In particular we cannot yeild across metamethod/C-call boundaries.
This behaviour matches with Lua 5.3+ yielding from hooks only at safe points.
Closes #632
2025-08-25 12:19:50 +01:00
Alex Orlenko
774a63bece
Add Buffer::cursor() method
...
This can be useful for providing access to buffers through core IO traits.
2025-08-24 11:29:01 +01:00
Alex Orlenko
c481c87eac
Add Lua::create_buffer_with_capacity method
...
This allow creating a preallocated buffer with specified size initialized to zero.
2025-08-23 22:38:55 +01:00
Alex Orlenko
85b280a9d6
Update nightly Rust error message matching
2025-08-23 09:40:13 +01:00
Alex Orlenko
5f38445558
Fix warnings
2025-08-20 16:25:06 +01:00
Alex Orlenko
f0806a6d62
Lower fastpath table creation limit to 1 << 26
...
When Lua is configured without memory restrictions, we use fastpath for table creation (unprotected mode).
In generally it's safe as long as we `abort()` on allocation failure.
However some Lua versions have additional restrictions on table size that we need to adhere in mlua too.
Probably Luau has the lowest limits.
Fixes #627
2025-08-13 22:49:40 +01:00
Alex Orlenko
cb153a52b2
Make Luau registered aliases case-insensitive
...
Executing `require("@my_module")` or `require("@My_Module")` should give the same result and use case-insensitive name.
See #620 for details
2025-07-26 22:23:16 +01:00
Alex Orlenko
b1c69d3005
Use to_bits comparison to check if a float value can be represented as an integer losslessly.
...
This allows to simplify the code while still maintaining "negative zeros" edge case.
Thanks @JasonHise for the suggestion.
2025-07-25 21:25:08 +01:00
Alex Orlenko
841bd332e4
Fix LuaJIT negative zero tests
2025-07-25 15:24:04 +01:00
Alex Orlenko
815d1bd7c9
Better handling negative zeros to match Lua 5.3+ behavior
...
In Lua 5.3+ the function `lua_isinteger` returns "false" for -0.0 numbers.
In earlier Lua versions we should follow the same behavior to avoid losing the sign when converting to Integer.
Close #618
2025-07-25 14:32:47 +01:00
Alex Orlenko
a653d08768
Simplify Compiler::add_library_constant (combine lib and member)
2025-07-09 00:11:46 +01:00
Alex Orlenko
2b6b0144a1
Merge Compiler::set_vector_lib into set_vector_ctor
2025-07-08 23:55:45 +01:00
Alex Orlenko
b1f73ec29d
Update Luau Compiler methods to better control extra options:
...
- Add `add_mutable_global`
- Add `add_userdata_type`
- Replace `set_library_constants` with `add_library_constant`
- Add `add_disabled_builtin`
2025-07-08 22:22:44 +01:00
Alex Orlenko
ca22ea3be7
Deprecate Debug::curr_line() in favour of Debug::current_line() that returns Option
2025-07-08 10:09:26 +01:00
Alex Orlenko
646827a6bb
Update Table::set_metatable
...
- Return Err (instead of panic) when trying to change readonly table (Luau)
- Slightly optimize performance
2025-07-06 11:37:02 +01:00
Alex Orlenko
c90cac5189
Add Lua::set_globals method to replace global environment.
...
Closes #611
2025-07-06 10:57:25 +01:00
Alex Orlenko
a3302afdc1
Deprecate Value::as_str and Value::as_string_lossy
...
These methods don't follow Rust naming convention, see
https://rust-lang.github.io/api-guidelines/naming.html#ad-hoc-conversions-follow-as_-to_-into_-conventions-c-conv
2025-07-01 22:35:40 +01:00
Alex Orlenko
dfb4e9a668
Fix LuaJIT stack inspection tests
2025-07-01 21:40:06 +01:00
Alex Orlenko
a3697ab1db
Add Debug::function method to get function running at a given level.
...
Close #607
2025-06-30 23:25:36 +01:00
Alex Orlenko
faf547c154
Refactor Lua::inspect_stack and debug interface.
...
It was possible to cause a crash when getting a `Debug` instance and keeping it while deallocating the Lua stack frames.
2025-06-30 12:21:10 +01:00
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