Skip to content(if available)orjump to list(if available)

Wren: A classy little scripting language

plainOldText

Reminder the creator of Wren wrote the awesome Crafting Interpreters book [0].

[0] https://craftinginterpreters.com/

l9o

This is awesome. Thank you for sharing. I have been working on a small interpreted language for shell scripts with lots of help from Claude Code. The main idea is to automatically generate the cli interface for the scripts based on function definitions. However, I'm far from a programming languages expert, so I've been a bit hesitant to share my work. Going to give this book a read this week to see how far I am. Thank you!

ronbenton

Knowing this is the author makes me 1000% more interested in Wren. What a great book!

mhaberl

and he wrote Game Programming Patterns [0]

[0] https://gameprogrammingpatterns.com/

apitman

I was working on a custom runtime for minimal wasm apps recently. I didn't want to have to write all apps in C or Rust, so I went looking for tiny scripting languages. Lua is pretty small, but I wasn't able to get it to compile to wasm IIRC due to POSIX dependencies. This turned out to be quite easy with Wren[0].

[0]: https://github.com/wren-lang/wren/issues/1199

MattJ100

That's unusual that you struggled to build Lua. Lua is primarily C89, and used on non-POSIX microcontrollers for example. There are some optional bits of the standard library you would have to leave out - module loading uses dlopen(). This is done simply by defining the right feature macros for your target environment: https://www.lua.org/source/5.4/luaconf.h.html

You may also be interested in this project: https://github.com/fengari-lua/fengari

davidw

Looks very nice! Erlang's concurrency isn't 'cooperative' though - it has a scheduler, so even a runaway process won't bog down the whole system.

bragr

This seems like a nice alternative to Lua. I've always liked embedding Lua in other software, but I confess I have never really liked Lua as a language.

tromp

Wren ties with Phix for most tasks done on Rosetta Code [1].

[1] https://rosettacode.org/wiki/Rosetta_Code/Rank_languages_by_...

gnabgib

Popular in 2022 (301 points, 130 comments) https://news.ycombinator.com/item?id=32631553

2020 (122 points, 54 comments) https://news.ycombinator.com/item?id=23660464

reactordev

This looks super cool up until I got to the point where it says inherited classes don’t share the same metatable. Meaning if you want to provide the same method on your inherited classes, you have to write the same thing and do a super.method() which means a lot of work if you’re into OO design so I’m not sure if classes is the right construct here. Am I wrong or did I miss something from the documentation? Other than that it looks like fun to use as an embedded scripting engine.

nick__m

you probably meant metaclass and according to the doc classes inheritance don't have surprising behaviors. And about the metaclass not being inherited here are the implication:

  ...In more prosaic terms, this means that static methods are not inherited.

sandbags

I would love to replace JS as the scripting language in one of my native macOS apps and I wonder if Wren would be suitable.

The two biggest questions I’d have are:

1) how easy it would be to bridge Obj-C objects to Wren-space and vice versa (a big win of using JavascriptCore) 2) how easy would it be to implement script debugging? This is not exactly a strength of Javascript core but it is at least possible by connecting the Safari web inspector.

There’s lots I don’t like about JS and JSCore but i’ve yet to find a better alternative.