Luau (Lua with type check) support?

Since now Luau (https://luau-lang.org/) from Roblox is open source. It would be an interesting option for Defold’s Lua scripting.

Last time I checked out Defold, Lua and the fact it lacks type checking is one of the main reasons I decide to move to other engine (I ended up writing my game in TypeScript and I am very happy with the decision, if you are interested, here’s my game’s Steam link: Industry Idle on Steam)

I wonder anyone here has (or plan to) give it a try? Any possibility of official support?

7 Likes

You might be interested in this:

3 Likes

I did check that out (or maybe a similar project) :slight_smile: And I have used the underlying TypeScript to Lua compiler for other Lua modding projects. The general problem with transpiling is that often time I need to go to the transpiled file for debugging - which can get annoying very quickly. Also I am not sure whether the project is production ready - I don’t think the project has 100% type coverage for the engine code?

I think the ts-defold project with VS code integration does source mapping from Lua to TypeScript.

Does it work on all platforms? How does it perform compared to LuaJIT? Is it fully compatible with standard Lua?

3 Likes

Parts of the Lua 5.x standard library are unsafe. Some of the functions provide access to the host operating system, including process execution and file reads. Some functions lack sufficient memory safety checks. Some functions are safe if all code is untrusted, but can break the isolation barrier between trusted and untrusted code.

The following libraries and global functions have been removed as a result:

  • io. library has been removed entirely, as it gives access to files and allows running processes
  • package. library has been removed entirely, as it gives access to files and allows loading native modules
  • os. library has been cleaned up from file and environment access functions (execute, exit, etc.). The only supported functions in the library are clock, date, difftime and time.
  • debug. library has been removed to a large extent, as it has functions that aren’t memory safe and other functions break isolation; the only supported functions are traceback.
  • dofile and loadfile allowed access to file system and have been removed.

These features are cool to have deleted if you want to make a game like Roblox, but not when making games where you trust your code and want access to these functions.

When initializing the default globals table, the tables are protected from modification:

  • All libraries (string, math, etc.) are marked as readonly
  • The string metatable is marked as readonly
  • The global table itself is marked as readonly

In other word, no monkey patching of builtin functions.

Seems like Luau would be a great fit if you want to make a game like Roblox which is itself a game development / publishing platform, or you want to make a game which is very mod friendly but also has security better built in.

3 Likes

Most of these could probably be added through an extension.

BUT I’m not sure if Luau even has a C API…

1 Like

It is built from C, and it has the regular headers afaict. The VM can be found here

3 Likes

Even though Luau and Defold Lua has some differences - I believe the high-level design goal is the similar. As a “scripting” language within an engine (or a game), some sandbox is needed. For example, both have restrictions on io and os library. Luau might be more restrictive than Defold Lua.

That being said, I am happy that the team is aware of this project. I think Lua could definitely benefit from a type checker (like TypeScript to JavaScript)

3 Likes

Hmm, I didn’t think we restricted theioand oslibraries? (I might remember wrong)

No, we do not restrict io and os functions as far as I know. @insraq in which way does the Defold version of Lua 5.1 differ from the official version?

according to @JCash, they planned to investigate luau in 2023, seems they dropped it as it’s 2024

1 Like

Defold now supports transpiling and you can already use Teal if you’re interested in a type-safe alternative to plain Lua. It still lacks several useful features, but I hope it will improve over time.

You can find more info here:

3 Likes

Yes, we found that Luau was a no-go as it is not a replacement for Lua. It lacks some moduled (e.g. io) and debug module doesn’t work the same. Also, it is not ABI compatible, and they have no intention of having that as a goal.

6 Likes