Commit Graph

1062 Commits

Author SHA1 Message Date
Alex Orlenko 0c53e09e30
Update tarpaulin settings 2023-04-12 01:03:33 +01:00
Alex Orlenko cdbf04f50c
Add pretty-print to the Debug formatting to Value to Table.
This would allow dumping any Lua variable in human readable form.
2023-04-11 20:36:41 +01:00
Alex Orlenko ba324b4f54
Allow deserializing Lua null into unit(`()`) or unit struct. See #264 2023-04-10 01:49:51 +01:00
Alex Orlenko 3e83753466
Add `Thread::set_hook()` function 2023-04-08 23:53:48 +01:00
Alex Orlenko 288934c82c
Refactor `HookTriggers` (make it const) 2023-04-05 01:02:27 +01:00
Alex Orlenko 483bc80fc4
Add `must_use` to `AsyncThread` 2023-04-05 00:23:13 +01:00
Alex Orlenko 354c69acc4
Update README 2023-03-30 23:22:01 +01:00
Alex Orlenko 6fa0a78ec0
Prepare v0.9.0-beta.1 2023-03-30 23:18:10 +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 da6d5a93c9
Update rustyline dependency 2023-03-30 22:34:41 +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 0848ddcdf7
Clippy 2023-03-28 20:53:22 +01:00
Alex Orlenko e182d474e0
More user-friendly error message about missing value for `name` attribute in module macro
Update the `[lua_module]` doc
2023-03-28 16:27:16 +01:00
Alex Orlenko 0f937b0a03
Switch to syn 2.0 2023-03-28 13:56:59 +01:00
Alex Orlenko cd9fc1d08f
Update Error doc 2023-03-26 20:58: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 9c1669020b
Clippy 2023-03-25 23:38:57 +00:00
Alex Orlenko 742307a267
Add &Lua to luau interrupt callback (fixes #197) 2023-03-25 16:30:31 +00:00
Alex Orlenko 781ded573a
Seal LuaSerdeExt/TableExt/AnyUserDataExt 2023-03-19 02:38:21 +00:00
Alex Orlenko 6a647f58be
Add `Error::downcast_ref()` method 2023-03-19 00:22:51 +00:00
Alex Orlenko 4bc6501d2e
Tests for the `ErrorContext` trait 2023-03-17 01:31:07 +00:00
Alex Orlenko 8d80321738
Add `ErrorContext` extension trait to attach additional context to `Error` 2023-03-17 01:20:57 +00:00
Alex Orlenko a0d37fd182
Rename `error` to `cause` in `Error::BadArgument` 2023-03-16 23:48:54 +00:00
Alex Orlenko 03787668fd
Improve error reporting when calling Rust functions from Lua.
In particular new error type `Error::BadArgument` added to help identify bad argument position or name (eg `self` for userdata).
2023-03-14 23:23:46 +00:00
Alex Orlenko 3059f82552
Update README and CHANGELOG 2023-03-12 23:54:19 +00:00
Alex Orlenko 22fbcfd9fb
Update edition everywhere 2023-03-12 01:03:31 +00:00
Alex Orlenko 304880bfd1
Fast metatable check for Lua::push_userdata_ref 2023-03-10 10:34:41 +00:00
Alex Orlenko 33c276d0b4
Optimize userdata methods call when __index and fields_getters are nil 2023-03-04 11:58:34 +00:00
Alex Orlenko 87d027e8ac
Rename rust_module in tests to test_module
This causes warning during compilation
2023-03-03 18:58:13 +00:00
Alex Orlenko d7db1b7f2e
Add Waker lifetime to WakerGuard 2023-03-03 18:29:04 +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 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 5394faca16
Rename `Owned*::to_ref()` to `as_ref()` 2023-03-02 15:36:11 +00:00
Alex Orlenko 4a3f6d60ad
Update exports in libs and prelude 2023-03-02 15:34:42 +00:00
Alex Orlenko 68b60e2a0a
Add `UserDataRef` and `UserDataRefMut` types that implement `FromLua`
and can be used as accessors to underlying `AnyUserData` type.
2023-02-26 21:52:28 +00:00
Alex Orlenko 888bd77e60
Add AnyUserDataExt to prelude 2023-02-25 23:59:29 +00:00
Alex Orlenko 949906f9f7
Fix potential deadlock when trying to reuse dropped RegistryKey.
If no free registry id found, we call protect_lua! macro while keeping mutex guard to the unref list.
Protected calls can trigger garbage collection and if RegistryKey is placed in userdata being collected, this can lead to deadlock.
The solution is drop mutex guard as soon as possible.
Also this commit includes optimization in creating reference in Lua registry.
2023-02-22 20:15:40 +00:00
Alex Orlenko 94f01e597c
Add `AnyUserDataExt` trait with auxiliary functions for `AnyUserData` 2023-02-18 23:40:28 +00:00
Alex Orlenko b8e3290f35
Update LuaRef/LuaOwnedRef
Move content of `Lua::make_owned_ref` into `LuaRef::into_owned`
Add crate-visible `Lua::clone` function (not trait)
2023-02-15 09:20:03 +00:00
Alex Orlenko 03ab828342
Return evicted value to `Lua::set_app_data` if it's already present.
Add "Panics" section to `Lua::*_app_data` docs.
2023-02-12 23:38:09 +00:00
Alex Orlenko b66bff9155
Drop `Lua::async_scope` as it's unsound 2023-02-12 22:25:10 +00:00
Alex Orlenko f52abf919e
Add create_userdata_ref/create_userdata_ref_mut for scope (#206)
New methods would allow creating userdata objects from (mutable) reference
to a UserData of registered type.
2023-02-12 16:37:02 +00:00
Alex Orlenko b790b525c1
Fix clippy warnings 2023-02-07 22:43:48 +00:00
Alex Orlenko f5182e0584
Force protected mode for long enough strings 2023-02-06 23:46:31 +00:00
Alex Orlenko 47c8300ccf
Allow registering and creating custom userdata types that don't necessary implement the `UserData` trait.
This is useful to register 3rd party types that cannot implement `UserData` due to Rust orphan rules.
See #206
2023-02-03 23:46:04 +00:00
Alex Orlenko 8339621f9c
Rename `to_lua_err` -> `into_lua_err` 2023-01-06 21:35:15 +00:00
Alex Orlenko 16cbb442e5
Fix clippy warnings 2023-01-06 20:50:29 +00:00
Alex Orlenko 88da28a68d
Allow deserializing values from serializable UserData using `Lua::from_value()` method.
Closes #240
2023-01-06 10:41:17 +00:00
Alex Orlenko a62061f453
Update README 2023-01-04 20:58:03 +00:00
Alex Orlenko cb3d58b1c7
Better Debug for String 2023-01-04 15:56:57 +00:00
Alex Orlenko fa46720f5a
Add `Table::clear()` method 2023-01-02 15:50:21 +00:00
Alex Orlenko 72b9209ae9
Rename wrapped_failure/thread cache to pool 2022-12-30 21:48:12 +00:00
Alex Orlenko 0cb7058476
Rename MultiValue cache to pool 2022-12-30 14:50:39 +00:00
Alex Orlenko ac8b3424d1
Update criterion 2022-12-30 13:45:59 +00:00
Alex Orlenko 2cb4b49d0d
Don't use unstable features in examples 2022-12-30 13:39:27 +00:00
Alex Orlenko d67332a3ac
Refactor `userdata::MetaMethod`.
Take `impl AsRef<str>` as name of metamethod (instead of `Into<MetaMethod>`) in UserDataMethods/UserDataFields.
Change position of generic args in userdata.
2022-12-24 19:16:58 +00:00
Alex Orlenko 22c6e9a7e7
Enable `unstable` feature flag in CI 2022-12-22 16:30:14 +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 9d28b790e7
Fix module tests 2022-12-21 21:05:23 +00:00
Alex Orlenko 61c285746c
Remove FromLua impl for UserData+Clone 2022-12-20 23:30:18 +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 0aa30226df
Check for invalid args when parsing `#[lua_module(...)]` proc macro 2022-12-18 00:35:41 +00:00
Alex Orlenko fdb5724053
Add ?Sized to PartialEq for Lua String 2022-12-18 00:35:41 +00:00
rise0chen b532f86674
feat: Support custom name of `lua_module` 2022-12-18 00:35:41 +00:00
Alex Orlenko c44463f030
Replace `impl AsRef<str>` with simple `&str` 2022-12-18 00:35:41 +00:00
Alex Orlenko de38e299fc
Use `impl AsRef<str>` for userdata methods/fields instead of generic param.
Use `impl AsRef<str>` for module names and named registry values.
2022-12-18 00:35:41 +00:00
Alex Orlenko 7526773a90
Do not clear usevalues when taking value out of userdata.
It has big performance penalty.
Lua GC can collect uservalues when userdata is not referenced anymore.
2022-12-18 00:35:41 +00:00
Alex Orlenko bf79d9e75d
Initial implementation of owned Lua types 2022-12-18 00:35:41 +00:00
Joel Natividad 02c08c6350
upgrade bstr from 0.2 to 1.0 2022-12-18 00:35:40 +00:00
Alex Orlenko 05eb20f9c6
Fix subtraction overflow when calculating index for `MultiValue::get()`.
Return `None` instead of panic in debug mode.
Fixes #232
2022-12-15 21:10:31 +00:00
Alex Orlenko 9716918517
Fix lifetime of `DebugNames` in `Debug::names()` and `DebugSource` in `Debug::source()`.
This can cause use-after-free if used wrong.
Now invalid code would not compile.
Reported in #230
2022-12-09 23:55:38 +00:00
Alex Orlenko c88417a3b6
Redefine `_VERSION` for Luau to include version number.
https://github.com/khvzak/mlua/discussions/228
2022-12-03 21:21:28 +00:00
Alex Orlenko 6e95386f30
Update Luau to 0.555 (luau-src 0.5.0)
This version includes inreased LUAI_MAXCSTACK limit (100000)
2022-12-03 17:55:26 +00:00
Alex Orlenko 6807dfa22e
v0.8.6 2022-11-07 01:05:14 +00:00
Alex Orlenko f27c49f931
Fix bug when recycled Registry slot can be set to Nil.
This can result in allocating the same slot twice and rewriting old value.
Lua uses (registry) table length to find next free slot and having Nil in the middle of the table can impact length calculation.
With this fix we ensure that Nil values uses a special LUA_REFNIL slot.
2022-11-07 00:10:57 +00:00
Alex Orlenko 693a808b6e
v0.8.5 2022-10-30 12:31:26 +00:00
Alex Orlenko a6ca65aa74
Better checks and tests when trying to modify a Luau readonly table 2022-10-30 11:41:09 +00:00
Alex Orlenko a7278cab78
Fix `Table::raw_push` for luau when readonly 2022-10-29 23:02:19 +01:00
Alex Orlenko e1bbd00a33
Fix getting caller information from Lua::load 2022-10-28 10:43:05 +01:00
Alex Orlenko e98998d6ac
Add push/pop methods to Table 2022-10-23 23:27:17 +01:00
Alex Orlenko cca177df5b
Minor serde optimizations 2022-10-23 03:13:24 +01:00
Alex Orlenko 65396a910f
Optimize `Lua::create_table` to use reference thread if possible 2022-10-23 00:24:04 +01:00
Alex Orlenko de69d10d73
Optimize `Lua::create_string` to use reference thread if possible 2022-10-23 00:14:13 +01:00
Alex Orlenko 959e61b97c
Optimize tables:
- Use reference thread directly for simple cases
- Fix issue when calling raw_set on readonly table (Luau)
- Add fasttrack methods for get/set/len when metatable is not set
2022-10-22 23:45:58 +01:00
Alex Orlenko 1040c0a347
Fix typo 2022-10-22 23:44:21 +01:00
Alex Orlenko 9045419586
Strings optimizations: get access to bytes directly from ref thread. 2022-10-22 23:43:08 +01:00
Alex Orlenko fcd162f3eb
Replace Lua::ref_thread_exec 2022-10-22 23:39:49 +01:00
Alex Orlenko 0354703dbf
Update formatting (Lua registry values) 2022-10-22 23:34:19 +01:00
Alex Orlenko 9831d0e397
Check that allocation does not exceed isize::MAX
See https://github.com/rust-lang/rust/issues/101899
2022-10-22 23:13:02 +01:00
Alex Orlenko 7f14d93c2b
v0.8.4 2022-10-09 14:40:15 +01:00
Alex Orlenko 29c6c9cb58
Fix clippy warnings 2022-10-09 14:08:33 +01:00
Alex Orlenko e01af22bac
Update push_userdata_ref 2022-10-09 13:56:30 +01:00
Alex Orlenko cfa959e599
Don't allocate extra byte for userdata (luau) 2022-10-09 13:56:06 +01:00
Alex Orlenko e523fb2c86
Update to Luau 0.548 (luau-src >=0.4) 2022-10-08 23:34:47 +01:00
Alex Orlenko 81a9998559
Update CI 2022-09-13 00:09:03 +01:00
Alex Orlenko 050ac4f5ad
Add luaL_setfuncs to preserved functions 2022-09-05 23:13:06 +01:00
Alex Orlenko 967cbb53b0
Update compile tests 2022-08-23 23:12:37 +01:00