Rust + Lua - Why & Full Code Examples

แชร์
ฝัง
  • เผยแพร่เมื่อ 31 ม.ค. 2025

ความคิดเห็น • 40

  • @camwoo1233
    @camwoo1233 หลายเดือนก่อน +13

    Nice video! Luau is a more modern version of Lua (has typings, faster, etc) that's also supported by mlua. Definitely a great thing to consider for those looking at this space!

    • @JeremyChone
      @JeremyChone  หลายเดือนก่อน +2

      Yes, Luau can be a good choice. It's great that mlua allows us to choose the engine so easily.
      By the way, for devai.run, I am using Lua 5.4, but I might switch to Luau. They seem to have drifted a little, so I wanted to play it "conservative."

    • @binary132
      @binary132 หลายเดือนก่อน +1

      That’s not how I would characterize Luau. Luau is a fork, not a “more modern” Lua - it has support for certain things like timing our calls that regular Lua doesn’t have, that are useful for Roblox. But it’s not standard Lua, there are differences. And I don’t think Luau scripts will be guaranteed to run on LuaJIT.

    • @binary132
      @binary132 หลายเดือนก่อน

      timing out*

    • @JeremyChone
      @JeremyChone  หลายเดือนก่อน +2

      Yes, this was my impression as well-a fork that has drifted by now. This is why the standard Lua 5.4 is a good starting point, and then, depending on the need, adjustments can be made.
      Big kudos to the mlua developers for providing such a simple way to choose what we want to run with.

  • @fabricehategekimana5350
    @fabricehategekimana5350 หลายเดือนก่อน +4

    Wow thank you, I was asking myself how I could embedd lua scripts with Rust ! This is all I needed to know ! I want to integrate teal script (that will compile to lua) so people could have a typed scripting language. Thanks again !

  • @letronix6243
    @letronix6243 หลายเดือนก่อน +1

    Thank you very useful. I always wanted to someday add lua to my game engine and I now understand the workflow.

  • @emvdl
    @emvdl หลายเดือนก่อน +4

    Thanks @jeremy 👍

  • @irlshrek
    @irlshrek หลายเดือนก่อน +5

    this is so cool!!!

  • @GouthamGunasekaran
    @GouthamGunasekaran หลายเดือนก่อน +6

    Hello sir I completed your rust book programming playlist.... I'm from embedded c background, how can I use Rust programming in Embedded devices like ESP32 microcontrollers...does rust programming support popular microcontrollers...please make videos on how to use in microcontrollers...thanks for knowledge your sharing....your videos are really valuable information ❤.

    • @drweshnaw3365
      @drweshnaw3365 หลายเดือนก่อน +3

      It's been a second since I've touched this space; but rust has a ecosystem around a crate called:
      'embassy-rs' which when I tried it had OK documentation; and I'm sure it has gotten better, it supports most common micro controllers (and it was designed to be a framework first, so porting to a new micro-controller isn't impossible for a dedicated single person); though the more obscure you go the more documentation starts to be just reading function definitions and crate source code

    • @d-o-n-u-t
      @d-o-n-u-t หลายเดือนก่อน

      Last time I tried in mid-2024, Rust had a really good ecosystem for ESP32 microcontrollers. It was really magical. You should try it sometime. I didn’t use embassy, I think the makers of my particular board had a whole lineup of Rust crates.

  • @kamertonaudiophileplayer847
    @kamertonaudiophileplayer847 หลายเดือนก่อน +1

    Awesome! Thanks.

  • @cno9984
    @cno9984 หลายเดือนก่อน

    I think that embedding WASM would be a great choice as well. It's sandboxed, fast, lightweight and it can be compiled from many languages (e.g. C++ or Rust).

    • @JeremyChone
      @JeremyChone  หลายเดือนก่อน +1

      @cno9984 WASM would not serve the same purpose, as the user would have to compile to it, usually from a strongly typed/compiled language.
      With scripting, the user just writes and provides the script, and the application can take it from there.
      Both are good at what they do, and it’s true that they both allow external code to run inside the app.

  • @jeffg4686
    @jeffg4686 หลายเดือนก่อน

    Nice!
    We need to get full python interface eventually.
    I know we can do it via this type of way, but make it able to be python only by embedding this functionality into the engine.
    We need to draw that crowd - python is massive now.

    • @JeremyChone
      @JeremyChone  หลายเดือนก่อน

      Yes, Python would be nice, but integrating it is complex and heavy.
      Two main options are:
      1) [PyO3](pyo3.rs/) - popular but heavy.
      2) RustPython - a pure Rust interpreter, still experimental.
      Embedding Python is challenging due to its reliance on native libraries like NumPy, which introduces significant complexity.
      Using a lighter scripting language like Lua simplifies runtime and app complexity. While developers need to learn Lua, it offers high net value and allows calling other languages like Python or Node.js when needed.
      For apps like Deno, embedding V8 makes sense, as JS was the end goal, but Lua suits simpler use cases better.

    • @jeffg4686
      @jeffg4686 หลายเดือนก่อน

      @@JeremyChone -thanks, makes sense. I was just thinking in terms of aligning Bevy with a highly popular scripting language. Would make people more interested in Bevy and likely get more development going on here from big companies donating in plugins. It's practically hidden at this point. I guess that's why godot likely did their whole gdscript thing instead of python.

  • @eyz-4
    @eyz-4 หลายเดือนก่อน

    interesting. unrelated, have you ever used nifs with elixir and rust? a crate called rustler that's very interesting

    • @JeremyChone
      @JeremyChone  หลายเดือนก่อน

      It does look interesting, but I have not tried it.
      There are many other alternatives, such as full JS, Python, or Rust-based languages like Rhai or Rune, but Lua has a high net value when simple scripting is needed.

  • @danser_theplayer01
    @danser_theplayer01 หลายเดือนก่อน

    I wonder if javascript can be embedded like that or if it's just too "big and all powerful".

    • @JeremyChone
      @JeremyChone  หลายเดือนก่อน +1

      (copied reply for convenience)
      JavaScript is an option, but it is heavy and intrusive for applications. While Deno has made great strides in simplifying this, it is still orders of magnitude more complex and heavier than Lua.
      Lua has the advantage of clear expectations-developers don't expect to "npm install" or "pip install," keeping scripting simple and self-contained.
      In devai.run, I let developers use `utils.cmd.exec(...)` to call Python, Node, Bun, etc., and retrieve results. By controlling the `utils.cmd.exec` calls, I ensure they remain constrained within the application runtime.

    • @RustIsWinning
      @RustIsWinning หลายเดือนก่อน

      ​@@JeremyChoneHave you tried rustyscript? Deno core is not that complex tbh. There is also boajs and I'm pretty sure that quickjs bindings also exist somewhere.

    • @sunofabeach9424
      @sunofabeach9424 26 วันที่ผ่านมา

      @@RustIsWinning you still pull a whole V8 engine

    • @RustIsWinning
      @RustIsWinning 26 วันที่ผ่านมา

      @@sunofabeach9424 Not everything is v8 but it is just a solid engine. You can always choose a smaller engine but dont expect it to be fast.

  •  หลายเดือนก่อน

    whats your thought on rai ?

    • @JeremyChone
      @JeremyChone  หลายเดือนก่อน +1

      Rhai is a good technology, and it is pure Rust, which has some benefits. However, I think the net value of Lua is greater.
      Here is a quick pros/cons list:
      *Rhai*:
      - pros:
      Pure Rust, no unsafe code
      Relatively simple to use
      - cons:
      Relatively unknown, medium size of 3 MB
      AST Walker (not a full scripting engine) does not support async.
      *Lua*:
      - cons:
      C integration, many unsafe aspects
      (but mitigated by engine maturity and library reliability)
      - pros:
      Relatively well-known, super small at 300 KB,
      Full scripting engine with async support and many features.
      Super simple to use and embed (can handle bidirectional calls)
      Supports sending (with a cost, but very convenient)
      Overall, I think that Lua is a better choice for its size, simplicity, popularity, and full, mature scripting capability.

    •  หลายเดือนก่อน

      🙏

  • @mahabat23
    @mahabat23 หลายเดือนก่อน

    what is the code editor, xcode?

    • @JeremyChone
      @JeremyChone  หลายเดือนก่อน

      vscode, with Google Materials + Custom Icons & Colors.

  • @ricardorochadev
    @ricardorochadev 5 วันที่ผ่านมา

    Lua is a Brazilian language. It means moon

  • @أميرالمؤمنينبنمحمدأكرم
    @أميرالمؤمنينبنمحمدأكرم หลายเดือนก่อน +1

    Use case please

    • @fabiand
      @fabiand หลายเดือนก่อน +4

      I mean he explained the usecase pretty well in the beginning of the video

    • @JeremyChone
      @JeremyChone  หลายเดือนก่อน +1

      devai.run is a great usecase for this.

    • @sunofabeach9424
      @sunofabeach9424 26 วันที่ผ่านมา

      I use it in Bevy game engine. when you change something in Rust code, the whole program needs to be precompiled. there are many ways to increase compilation speed but on my machine it still takes 5-10 seconds each time I change something. Lua scripts, on the other hand, can be considered as *resources* by Bevy, they can be hot reloaded upon being changed, then Lua code is almost instantly recompiled. extremely useful for prototyping

  • @broom7294
    @broom7294 หลายเดือนก่อน

    now do javascript 😁

    • @kallebysantos5167
      @kallebysantos5167 หลายเดือนก่อน

      You can use Deno by deno_core and other extension crates

    • @JeremyChone
      @JeremyChone  หลายเดือนก่อน +3

      JavaScript is an option, but it is heavy and intrusive for applications. While Deno has made great strides in simplifying this, it is still orders of magnitude more complex and heavier than Lua.
      Lua has the advantage of clear expectations-developers don't expect to "npm install" or "pip install," keeping scripting simple and self-contained.
      In devai.run, I let developers use `utils.cmd.exec(...)` to call Python, Node, Bun, etc., and retrieve results. By controlling the `utils.cmd.exec` calls, I ensure they remain constrained within the application runtime.

  • @surplusking2425
    @surplusking2425 หลายเดือนก่อน

    C++ + Go is much better than Rust + Lua

    • @JeremyChone
      @JeremyChone  หลายเดือนก่อน +2

      Not sure if those pairs compare.