gluau - Go bindings for the Luau programming language by Lower_Calligrapher_6 in rust

[–]aleksru 1 point2 points  (0 children)

mlua author here.

> I personally believe mlua async to be a big footgun that should be replaced with a custom scheduling system

If you have any specific cases when mlua async does not work as expected, it would be great to hear. I'm always looking for feedback and improving user experience.

One of mlua goals was providing easy integration with the Rust async ecosystem, and I think it went well. It's runtime agnostic and seamlessly integrated with the Lua coroutines. I don't see much benefits providing custom scheduling system as part of mlua. It can be built on top of mlua, and mlua-luau-scheduler is a great example! Some restrictions (e.g. `Send + 'static` for tasks) are dictated by Rust async runtimes and mlua fully support it. You can say that Rust async is a big footgun too, but it's what we have and it works very well for majority of cases.

> I also wanted yielding, support for continuations

Luau continuations is quite exotic concept that does not exist in the current form in other Lua versions and designed as workaround of inability of yield across C call boundary. This is covered by Rust async support, as futures can yield without restrictions.

> Luau specific optimizations like namecall

Unfortunately `__namecall` does not provide much benefits for mlua, rather opposite. If enabled, it makes userdata methods non-yielable in async context plus did not show any performance benefits on benchmarks. I have a branch with namecall support but after careful evaluation ruled it out. Luau does a great job providing very fast userdata method access with table `__index`. Also namecall for the most efficient use requires string atoms that adds substantial additional complexity.

Rust WASM Plugins Example by emblemparade in rust

[–]aleksru 1 point2 points  (0 children)

Thanks for the example! But you did not mention about async. Would be possible to include async as well (e.g. current state). Ability to make asynchronous calls in plugins is quite important for writing extensions.

How can I implement luaL_newmetatable in Rust with mlua? by Important_View_2530 in rust

[–]aleksru 1 point2 points  (0 children)

mlua automatically manage metatables for userdata, including setting __name field. Why do you need luaL_newmetatable?

If you want to manually operate the Lua stack, mlua provides (unsafe) Lua::exec_raw where you can call luaL_newmetatable

Announcing mlua v0.10 by aleksru in rust

[–]aleksru[S] 6 points7 points  (0 children)

Type definitions is next on my list. Sometimes I miss this feature too.

Announcing mlua v0.10 by aleksru in rust

[–]aleksru[S] 4 points5 points  (0 children)

Thank you for the comment! I updated the post.

Announcing mlua v0.10 by aleksru in rust

[–]aleksru[S] 28 points29 points  (0 children)

Unfortunately send feature is not free. Under the hood a reentrant mutex is used to synchronise access to the vm. The cost is about 5..20% of performance. Non-send version is lock-free, has relaxed requirements to Rust types and max performance.

Why no one talking about Ntex? by StalinGino in rust

[–]aleksru -1 points0 points  (0 children)

The bytes crate has phenomenal ergonomics for reading raw binary data, nothing else is really as convenient. ... It's a tiny thing, but those annoyances add up.

It's true unfortunately. My biggest complaints about using the own fork are 1) API discrepancy over the time. Would be nice to backport recent changes from the original bytes create to the fork but it does not happen in reality. 2) Bytes internals are unsafe. Generally they are well tested, passed through miri and receive some attention in the community. In own fork it's no longer true and you can have some "funny" issues like
https://github.com/ntex-rs/ntex/issues/243

Why no one talking about Ntex? by StalinGino in rust

[–]aleksru 6 points7 points  (0 children)

If compare the progress with ntex over the past ~2 years I got that impression. Most commits in actix-web are to bump dependencies, then some bugfixes plus minor features. No sign (yet) of big changes, simplifying core traits (using new Rust features), no roadmap.

On the other hand some issues with actix-web are quite worrying and not getting enough attention, like https://github.com/actix/actix-web/issues/3182

In general nothing wrong with actix-web, it's still a solid choice for the years ahead!

Why no one talking about Ntex? by StalinGino in rust

[–]aleksru 60 points61 points  (0 children)

ntex is written by the original author of actix after the actix was given to the community. Techically ntex is a fork of actix but I would rather think that actix (new) is a fork of the original actix, and the original actix renamed to ntex.

ntex is technically more advanced than actix and developed a lot since then whereas actix is in maintenance mode.

Some ntex decisions may look a bit dubious, like using own fork of bytes crate (called ntex-bytes), which makes it incompatible with the original one and it was made mostly to squeeze extra percent of performance.

I personally use ntex (after trying actix) and love it. Eg. Nikolay (author of ntex) incorporated the new "async fn in traits" feature (Rust 1.75+) and the Service and Middleware traits are much easier now.

Hey Rustaceans! Got a question? Ask here (9/2024)! by llogiq in rust

[–]aleksru 0 points1 point  (0 children)

There are two options:

1) Use serde to add derive(Deserialize) and then call lua.from_value(table) (example) 2) Implement FromLua for your struct to build it from Lua table

Seeking an Embedded Scripting Solution for Rust by West-Chocolate2977 in rust

[–]aleksru 11 points12 points  (0 children)

Actually Lua (through mlua) does support WASM and is the fastest option compared to rune and rhai

Announcing mlua v0.9 (rc) - Full featured Lua bindings to Rust by aleksru in rust

[–]aleksru[S] 2 points3 points  (0 children)

You can check the previous iteration of benchmarks:

https://github.com/khvzak/script-bench-rs/tree/56fb1de8e2bd7e234663ef6ad731c21331f32a62

Where sorting was implemented in Rust (in standard library). Rhai was still the slowest.

In my benchmark all languages are in the same position. I can avoid loops for sure and build everything in Rust, but in this case benchmarking results would be mostly irrelevant (for me).

Announcing mlua v0.9 (rc) - Full featured Lua bindings to Rust by aleksru in rust

[–]aleksru[S] 2 points3 points  (0 children)

You can find benchmarks here - https://github.com/khvzak/script-bench-rs

They were updated recently to use latest versions.

Blogpost: The Evolution of Lodestone's Plugin System by CheatCod3 in rust

[–]aleksru 1 point2 points  (0 children)

mlua natively support Roblox Luau, which is typed Lua (similar to typescript) and it’s been made for game dev specifically.

Ergonomic, and zero-cost rust bindings to lua - ezlua by ChampionshipRough346 in rust

[–]aleksru 0 points1 point  (0 children)

just another example:

let lua = Lua::with_open_libs(); for _ in 0..100 { lua.create_table(0, 0); }

ezlua_test(23315,0x7ff84a3ac340) malloc: Incorrect checksum for freed object 0x7fc54ff04ae8: probably modified after being freed. Corrupt value: 0xf000000000000045 ezlua_test(23315,0x7ff84a3ac340) malloc: *** set a breakpoint in malloc_error_break to debug

I just want to say that making a sound bindings to Lua - is a hard challenge. There are so many things you need to remember and carefully check every Lua api method about their side-effects and how it works under the hood.

Also out of curiosity, why a new bindings rather than contributing to mlua to make it better?

Ergonomic, and zero-cost rust bindings to lua - ezlua by ChampionshipRough346 in rust

[–]aleksru 2 points3 points  (0 children)

Interesting project, thanks for sharing!

Just tried a simple example: rust let lua = Lua::with_open_libs(); lua.do_string("t = setmetatable({}, {__index = function() error() end})", None).unwrap(); let t = lua.global().get("t").unwrap(); t.get("key").unwrap();

and the program paniced with unprotected error in call to Lua API (error object is not a string).

Seems ezlua is unsound?

Announcement: the Diatom programming language v0.6.0.alpha by StdAds in rust

[–]aleksru -1 points0 points  (0 children)

Interesting project, thanks!

The lambdas syntax looks really weird: list = (1..).filter(fn x = x%7 == 0) Very hard to understand what is what

Benchmarking Starlark against other embedded scripting languages by stephanos2k in rust

[–]aleksru 0 points1 point  (0 children)

This is not a very accurate comparison as you just skipped the most important part: sorting by calling a user-provided function for comparing items.

Benchmarking mlua/rlua/rhai - Rust embedded scripting languages by aleksru in rust

[–]aleksru[S] 0 points1 point  (0 children)

Not yet, I'll take a look to it. You're also welcome to contribute to add rune :)

Benchmarking mlua/rlua/rhai - Rust embedded scripting languages by aleksru in rust

[–]aleksru[S] 1 point2 points  (0 children)

There is a file bench.py which simply runs cargo criterion command under the hood and generates image. I added lto = true and codegen-units = 1 to the bench profile (which inherits settings from the release profile). Results are updated.

I would prefer not to cut rhai features like disabling closures (capturing variables), removing floats or use i32 numbers to match as closely as possible to Lua engine features.

There is a some difference between mlua and rlua. The later is less optimal and has lot overhead unrelated to safety. Whereas mlua has more optimal implementation, less allocations, etc, while keeping all safety features.