3 ms·
Wren does have instance method inheritance. It's implemented differently from most scripting languages, though. The implementation is more like a statically-typ
by pansa2 1y ago
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 https://wren.io/performance.html#copy-down-inheritance
- reactordev 1y agoSo it does have: class A { construct new () {} thing(obj) { … } } class B is A { construct new () {} } B.new().thing(obj) 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.
- pansa2 1y agoYes: https://wren.io/try/?code=MYGwhgzhAECC0G8BQ1rAPYDsIBcBOArsDtJgKYDu0AFAJSIC+K0OAFgJaYDm16ARgCt6yVKgDKAT1xkAtgDoADnk45eg2syZMkoSDABC0djHgi0WXIWKlKNYVqRJ9c8hTpy2nHgEZaQA https://wren.io/try/?code=MYGwhgzhAECC0G8BQ1rAPYDsIBcBOArsDt...
- reactordev 1y agoTrying to update a field from a subclass and print the results doesn’t work. class A { name { _name } name=(value){ _name=value } construct new () { _name = "hello" } thing() { System.print(name) } } class B is A { construct new () {} update(name){ super.name = name return this } } var b = B.new() b.update("world").thing() 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
- pansa2 1y agoYour `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 https://wren.io/functions.html#returning-values
- reactordev 1y agoThat was it. Nuance in the “no new line after…” parsing. Thanks, it works now. Awesome!