Live data from Hacker News

Teal – A statically-typed dialect of Lua

teal-language.org

51–60 of 176 posts

Re: Teal – A statically-typed dialect of Lua

#51
post #33
post #9

Earlier quoted context omitted.

It's nothing like C, and that's so much of its charm. Semantically, Lua is almost identical to the core of JavaScript. Metatables are a genius alternative to prototype chains. Lua's syntax is beautifully simple and unambiguous, but at the cost of being moderately inconvenient in 2025 unfortunately. It could benefit from an ESNext-style renewal. I get why they made the C API that way, but in practice it's very easy to…

FYI, for those who may not be aware, moonscript is the "coffeescript" for lua. It has been in production use for quite a while (the author of moonscript also created itch.io, using ... moonscript). yuescript, from the dora-ssr game engine dev, is essentially moonscript-2.0 And of course, if you want to treat lua as the scheme-like it really is (deep down), then ... fennel. Lots of choices. They all compile to straigh…

If Teal is the TypeScript of Lua, Fennel is the ClojureScript. Except Fennel is fully implemented in Lua itself and it transpiles (usually) to very simple, plain Lua code without much (if any) overhead and with no run-time library other than what is in Lua itself.

https://fennel-lang.org/

Re: Teal – A statically-typed dialect of Lua

#52
post #40
post #27

Earlier quoted context omitted.

> Teal replaces Lua's tables - the language's signature single, highly-flexible data structure - with separate arrays, tuples, maps, records and interfaces They're all just Lua tables with specialized type checking for specific behavior. I really wish the Lua authors would add official types to Lua. The time has come.

> I really wish the Lua authors would add official types to Lua. Never going to happen IMO. Adding static types would change the nature of the language completely, even more than it has in Python. As Teal shows, it would require giving up one of Lua's core features: tables as the language's single data structure. It would significantly complicate a language known for its simplicity. Even the implementation would need…

In reality, tables are used in specific fashions and not fully generally. (Partly because Lua itself even recognizes some of these fashions and provides relevant operations accordingly.) Lua tables are not really a single data structure; it is a single type that acts as multiple data structures at once.

Re: Teal – A statically-typed dialect of Lua

#53
post #20

> Teal is a statically-typed dialect of Lua. I was expecting Teal to be "Lua + type annotations", similar to Mypy. However from a quick look it does indeed seem to be a "dialect" in its own right. Teal is Lua-like and compiles to Lua, but there's more to it than just static types. Perhaps it's more similar to TypeScript? For example, Teal replaces Lua's tables - the language's signature single, highly-flexible data s…

It's interesting that you mention Typescript. In Typescript's early history, they added a bunch of features that they either thought would make it nicer for C# devs (classes, enums, option chaining, decorators, namespaces, etc.). Eventually, a bunch of these features were added to Javascript natively in nearly the exact same way they were implemented in Typescript. Now, the only remaining non-type-related features no…

Minor nitpick: decorators are still in "stage 3". Not formally part of ECMAScript standard yet.[1]

Anyway, that has not stopped large parts of the JavaScript ecosystem -- notably Angular -- from using an experimental variant of decorators, such as the one provided by TypeScript. [2]

[1] https://github.com/tc39/proposal-decorators

[2] https://github.com/angular/angular/issues/48096

Re: Teal – A statically-typed dialect of Lua

#54

How confident are you in the soundness of the type system? Also, are there any Lua constructs that are difficult/impossible to type? Is type checking decidable? (Is the type system Turing complete?)

People get this way about TypeScript too, and it always perplexes me. These projects are about adding types to untyped languages, and that comes with a few givens: * Your type system cannot be sound. It's going to have escape hatches and exceptions because that's how dynamic languages roll. * There will always be constructs that you can't type. See above. * If your type system is going to usefully type enough of the…

> Your type system cannot be sound.

This one I disagree with. Type assertions with runtime checks could keep the typed fragments sound, unlike TypeScript and Python. Also see Elixir's strong arrow proposal for how to encode which assertions can be elided on function calls (because the function will assert them already).

Re: Teal – A statically-typed dialect of Lua

#55
Oof. What is it about the devs who prefer static typing that they insist on bolting it onto every scripting language they can? It's nearly a compulsive disorder.

There's plenty of languages with compile time type safety, just go use one of them and leave the perfectly good dynamic ones alone.

Static typing proponents need accept that dynamic typing is a perfectly valid way to write and run code: It's way less verbose, it focuses code on logic rather than syntax (a.k.a. "scripting"), it's easier to mentally parse and generally easier to both learn and use.

Inflicting types on every piece of code written is just ridiculous.

Re: Teal – A statically-typed dialect of Lua

#56
post #3

I'm so relieved to see more types being added to good languages. So Teal is to Lua as TypeScript is to JavaScript. Which means it automatically plays well with any Lua environment. Unlike luau and nelua which are also statically typed but have their own runtimes. What version of Lua does it use? Lua gets new versions every few years so I don't know why so many impls don't continuously upgrade to the latest version.

Each new Lua version has breaking changes that are of dubious value to keep on the upgrade treadmill. Something like a Python2->3. LuaJIT is famously on 5.1 with no signs of moving.

Not moving straight to a more recent version, but still cherry-picking some parts of them. You can see some functionalities from Lua 5.2 and 5.3 are working in Luajit: https://luajit.org/extensions.html

Re: Teal – A statically-typed dialect of Lua

#57

I've been diving into Lua (a little late to this party, but turns out it's a perfect language to rewrite some commandline scripts I had that were getting unwieldy in Bash, especially with LLM assistance!) and it's really something of an eye-opener. LuaJITted Lua code runs at 80% (on average, sometimes faster!) of the compiled C version of the same algorithm , typically. Lua is embedded in a surprisingly massive numbe…

It is true that LuaJIT is stuck at 5.1, but you could write any performance critical sections in C/C++ and call it from Lua. Lack of LuaJIT for 5.1+ isn't that big of a deal for desktop apps. The embedded world is still stuck in 5.1, but for them, the benefits of the latest Lua is marginal.

and if you use luajit ffi, those calls actually get called just as fast as from a c program

Re: Teal – A statically-typed dialect of Lua

#58

This is very cool. I wonder if it works with Roblox, which is probably the environment with the largest number of Lua programmers. It certainly looks like it should work basically anywhere Lua works.

The use their dialect of Lua. Luau, stuck on 5.1 (correct me if I am wrong) like LuaJit for performance reasons. It is gradually typed, so no need to use Teal.

> Luau, stuck on 5.1 (correct me if I am wrong) like LuaJit for performance reasons.

It's not just for performance reasons, and they don't exactly have no features from newer versions. Take a look at the compatibility tables: https://luau.org/compatibility

Re: Teal – A statically-typed dialect of Lua

#59
post #6

Earlier quoted context omitted.

Lua is a good language. It's like C, if C were a scripting language. It's got an awesome C API. It's fast, lightweight, and embeddable. It's more performant than Python. It's a staple in video game scripting.

I don't think it's a good language, and I hate it. I've made thousands of the same mistakes with it—typing . instead of :. There's a reason Lua has a smaller audience than assembly.

> There's a reason Lua has a smaller audience than assembly.

I don't think that's true. It's a very embedded language. Its use in video games and video game modding alone would outnumber the number of people directly writing assembly to achieve things.

Post reply on HN