luau-rs
Kind
luau-rs | Kind | |
---|---|---|
2 | 21 | |
16 | 2,565 | |
- | - | |
7.5 | 9.5 | |
over 2 years ago | over 1 year ago | |
Rust | Rust | |
GNU General Public License v3.0 only | MIT License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
luau-rs
-
Principles are products of practice, not the reverse
> - Do not repeat yourself.
I recently ran into a case where this was practically a necessity, because the alternative (of simply repeating myself) would not only have been prone to copy/paste errors during authorship, but also have resulted in code with an incredibly low signal to noise ratio (which also would have made authorship quite tedious).
For a bit of backstory, I'm currently toying with writing some Luau bindings for Rust, but Luau (by default) throws C++ exceptions instead of using longjmp. These exceptions can be thrown by almost any Luau function, and I need to prevent them from unwinding across FFI boundaries to avoid triggering Undefined Behavior, because in Rust, it is UB for a "C"-ABI function to unwind into its caller.
Here are some things that can throw C++ exceptions in Luau:
- OOM when allocating new garbage-collectible objects in an existing VM. Creating the VM itself is (most traditionally) done through luaL_newstate, which returns NULL on allocation failure, but once you have a VM, attempting to instantiate a collectible object within it will throw an exception if allocation fails. This can happen indirectly through any other operation that internally creates collectible objects.
- Attempting to modify a readonly table. Luau implements a readonly bit for tables that controls a guard against modification of that table, even by native code. It does this by throwing an exception when any such modification is attempted. However, just like collectible objects, table modification is an implementation detail of all sorts of things. While I don't expect anyone to be able to readonly the Luau registry, it is still a thing that you can do to arbitrary other tables (assuming that the host side doesn't omit or remove the `table.freeze` function from the standard library). Technically, you could defensively check the readonly bit from Rust before attempting those operations, but that would cause it to be checked twice on each operation, and this workaround doesn't generalize to other sources of exceptions, nor does it work through indirections (random other functions that happen to write to tables internally).
- Arbitrary function calls, if an interrupt callback is set. Luau supports an "interrupt" callback that is periodically called by the VM at "checkpoints" such as function calls. The interrupt callback is allowed to throw an exception, as this is the officially supported method of eventually terminating functions that contain infinite loops or other code that blocks the thread for too long. AFAIK, it can also be triggered in the middle of C closures if you perform certain operations like making a Luau function call. Although Luau function calls themselves may error, the interrupt callback can cause any Luau function call to error, even if it normally should not.
Luau probably expects those kinds of operations to be performed primarily by C++ functions executing under the VM ("C closures"), where any exceptions will be automatically caught and a status code returned to whoever called the VM. Generally, it is quite a reasonable assumption to make that a library will be used from the same language that it is written in.
However, Rust can't currently express "C closures" that are capable of unwinding, because unwinding out of a "C"-ABI function is Undefined Behavior (Rust wouldn't be able to unwind into the VM), and so is a "C"-ABI function unwinding into a Rust stack frame (library functions wouldn't be able to unwind into Rust in the first place).
The "C-unwind" ABI should eventually allow Rust to express and call FFI functions that are capable of unwinding, but it hasn't quite reached stabilization yet.
If Rust had already supported "C-unwind", I could have just defined a C++ wrapper function that catches Luau exceptions and translates them into a tagged union or something representing success or failure. Unfortunately that is not yet the case.
Luckily, Luau has some internal functions that allow you to catch exceptions regardless of whether they are exceptions or longjmps, but they work by executing a callback that you pass to it, and you can only pass a single pointer value through to the callback. Therefore, my first solution was to place the arguments to be passed in a struct, as well as a slot for a return value, and then read that struct by pointer in order to call the function and write its return value into the slot.[0]
This worked, but it was a lot of manual code for each individual function that had to be protected from errors - you had to duplicate the argument list about 4 times (wrapper function signature, struct definition, struct initializer, and wrapped function invocation), which quickly got quite tedious, especially since quite a few functions are going to need this wrapping treatment.
My first DRY implementation was to create a template that can produce a wrapper around any function, that calls it with any number of arguments, of any types. I still needed to manually prepare a list of functions in advance to protect, since you can't instantiate templates over FFI, but this was a lot more painless than the first try.
It's just that the templates are a bit of a mess.
[0]: https://github.com/LoganDark/luau-rs/blob/787eb0c7987c08304c...
[1]: https://github.com/LoganDark/luau-rs/blob/de5abd5420a5311c27...
-
Please, keep in mind there is ZERO FUNDING for my projects.
I've been asked twice to switch away from GPL and the argument is always that it limits who can use my work. Usually the argument goes past that and tries to stress just how seriously, debilitatingly, unusable my library becomes by being GPL-licensed.
Kind
-
Eliezer Yudkowsky has great news: "Parents conceiving today may have a fair chance of their kids living to see kindergarten."
As a developer of a proof assistant (Kind) I'm highly interested in this line of work. Can you point me to some of these papers? And perhaps people involved in this line of work?
- Somos os devs da HVM, o compilador Brasileiro que rodou o mundo. Vamos colocar nosso logo no /r/place?
-
A list of new budding programming languages and their interesting features?
Kind: A modern proof language (though functional).
- Fornjot: A next-generation Code-CAD application
-
How to handle list / contiguous array definition and implementation in a type system?
I have seen in languages like KindLang the definition of Array be like a Binary tree, but there is some magic there in the definition of the Array type that I don't understand yet. Also, I don't want to define the contiguous array further., it should be a literal contiguous array. The Kind "Word" type definition (arbitrary number of bytes) is closer to my contiguous array, but it has a similarly complex definition which like I said I don't understand.
-
Type Checking as Calculation
Totally agree about the Blub Paradox, but there's definitely value in Self Types. See, for example, [Kind](https://github.com/Kindelia/Kind), which is able to type recursive data types by using Self Types.
-
Please, keep in mind there is ZERO FUNDING for my projects.
For these who don't know, I'm the author of Kind and HVM. I've recently seen a criticism from an influent person in the community, who I often took as an inspiration, that made me really sad. "the guy behind this has built some impressive-sounding stuff before... it looks like his projects tend to just... go nowhere and he just abandons them and does something else?"
-
Is it possible to make join work for arbitrary depths?
This is very easy with dependent types! For example, in Kind:
- A massively parallel, optimal functional runtime in Rust
- Eu acabei de lançar um dos "compiladores" mais rápidos do mundo. Apoiem o trabalho brasileiro!
What are some alternatives?
rust-lua - Safe Rust bindings to Lua 5.1
HVM - A massively parallel, optimal functional runtime in Rust
openfare - Micropayment funded software.
opencascade.js - Port of the OpenCascade CAD library to JavaScript and WebAssembly via Emscripten.
CascadeStudio - A Full Live-Scripted CAD Kernel in the Browser
urweb - The Ur/Web programming language
awesome-rust-formalized-reasoning - An exhaustive list of all Rust resources regarding automated or semi-automated formalization efforts in any area, constructive mathematics, formal algorithms, and program verification.
awesome-programming-languages - The list of an awesome programming languages that you might be interested in
tlaplus - TLC is a model checker for specifications written in TLA+. The TLA+Toolbox is an IDE for TLA+.
lobster - The Lobster Programming Language
truck - Truck is a Rust CAD Kernel.
frag - Frag is a 3D first person shooting game written in Haskell, by Mun Hon Cheong