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.
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:
I think I read that Wren's creator deliberately avoided "the metaclass hierarchy matches the class hierarchy" (as used in Smalltalk and taken to an extreme in Ruby [0]) because the authors of Smalltalk have come to regret that design?
I'd be interested to hear more details about the issues with that approach. I've not had any problems with it, and occasionally found it useful. For example, in one situation I needed a hierarchy of static constructors that matched the hierarchy of instance constructors.
[0] Ruby also has "the meta-metaclass hierarchy matches the metaclass hierarchy" and "the meta-meta-metaclass hierarchy..." ad infinitum. It's a beautiful design really - it means that in Ruby (unlike Smalltalk), it's always true that "the superclass of the metaclass is the metaclass of the superclass".
Edit: Here's the quote I was remembering:
> My hunch is that we don't want metaclass inheritance. From talking to a few old Smalltalkers, they generally consider it a mistake there. Also, Java, C++, C#, etc. have semantics more similar to not allowing metaclass inheritance (in other words, static methods aren't inherited), and it seems to work well there.
https://groups.google.com/g/wren-lang/c/LkKg51fEUg4/m/0GOK0P...
Static method inheritance is one thing. Member method inheritance (or lack there of) makes it long in the tooth to work with if you want to represent covariant classes that share methods.
Wren does have instance method inheritance. It's implemented differently from most scripting languages, though. The implementation is more like a statically-typed language, for performance reasons:
https://wren.io/performance.html#copy-down-inheritance
So it does have:
I’ll need to test this as this is what I want from my scripting language. If this works than wren will replace my Lua janky scripting.Yes:
https://wren.io/try/?code=MYGwhgzhAECC0G8BQ1rAPYDsIBcBOArsDt...
Trying to update a field from a subclass and print the results doesn’t work.
If you change System.print(name) to System.print(_name) it works but it doesn’t when using the getter. You get null when System.print(name) is called.Same if you use this.name
Your `name` getter isn't working properly. Weirdly, Wren's implicit returns only work for functions written on a single line.
The getter either needs to be (exactly) `name { _name }` or it needs to explicitly `return _name`.
https://wren.io/functions.html#returning-values
That was it. Nuance in the “no new line after…” parsing. Thanks, it works now. Awesome!