my http more compatible with ssl, script+jsvar can do subclasses of D objects
Posted 2020-04-27
Blog
Articles- String interpolation DIP prototype
- terminal inline syntax highlighting, sdpy fonts improved
- January 18, 2021
- gdb debugging tips
- A little work on sdpy/terminal interop and apng debugging
- New plain tcp fiber socket class (with "how it works" docs), new arsd docs started, new dub subpackages in arsd. Also Turkish newsgroups added to forum.dlang.org
- Little audio player in D
- Thoughts on tutorial writing benefits, D marketing, and some simpledisplay.d improvements.
- arsd 9.0 rollup release, my thoughts on "google it" culture and related practices
- dpldocs.info cross-package search finally released! and more terminal getline enhancements
- I did a dconf livestream!
- New selective mouse input in terminal stack, Xft used in simpledisplay to improve TrueType font support
- simpleaudio now has playOgg, Mp3, Wav with resampling and can access multiple soundcards on Linux, adrdox gets ddoc on function params
- Weekend experiment: declarative GUI in D
- October 26, 2020
- My DConf livestream sneak preview
- Off topic jrpg video game review
- My thoughts on breakage, and I'll be in DConf Online 2020
- cgi.d hybrid server basically working, terminal.d can redirect stdout to a window if requested
- Some talk on cgi.d in benchmarks
- September 14, 2020
- New D update "dwidder" website launched, making-of post here
- white noise app in D
- More modern opengl in simpledisplay, document undocumented on dpldocs.info, tip on default template args
- Xlib taskbar in D
- D Tetris running on Webassembly
- Tetris in D
- Zero-runtime classes
- DConf online in the works for Nov 21-22, image copy/paste coming to sdpy soon
- July 13, 2020
- July 6, 2020
- simpledisplay getting dynamic loads, terminal gui gracefully degrades, i muse on scope raii classes
- Adam's dynamic link transition
- June 15, 2020
- June 8, 2020
- June 1, 2020
- foot pedal and midi fun, some dmd speed enhancements. Forum argues about @safe by default on extern.
- May 18, 2020
- simpleaudio dev work, rasp pi gpio module, static foreach rant, gcc 10's D support upped
- May 4, 2020
- my http more compatible with ssl, script+jsvar can do subclasses of D objects
- i want to make a jrpg, and have eye damage.
- Dustmite post on official blog
- What if I were dictator?
- March 30, 2020
- terminal.d with built-in emulator option releaed
- Online DConf in the works
- Dconf 2020 cancelled, Adam plays with terminal gui integration
- March 2, 2020
- some adrdox/dpldocsinfo updates
- terminal.d gets clipboard functions, ldc 1.20 out.
- DConf keynote speaker announced: Lua architect Roberto Ierusalimschy, Named args DIP discussed
- February 3, 2020
- Adam's terminal suite explained
- Understanding mixin templates, terminal.d improvements
- My attribute-by-default proposal. Also dmd 2.090 came out.
- DConf 2020 announced: June 17-20 in London. @safe by default debated. Adam did: Android, JNI, WebSocket in arsd libs
- tar.xz, --DRT tip, dom bug fixes, more Android and JNI, link to old phobos docs
- LDC 1.19 - Android, AVR. My rant on tests, update on JNI and COM.
- Walter's string interpolation proposal is OK but not great. My Android thing nearing beta release. dub downtime explained.
- Android project update, introduction to arsd.jni
- New pattern about interface contracts
- Adam shares Windows console secrets - DO NOT USE chcp!!
- Adam's rant on benchmarks
- Socket tutorial
- November 4, 2019
- October 28, 2019
- arsd package updates, forum nonsense
- Update on Android
- Adam does iOS "goodbye world"
- September 30, 2019
- D turns 20, Adam rants on software freedom
- Named arg DIPs and my thoughts on code organization
- September 9, 2019
- I wrote about mixin templates vs string mixins on Stack Overflow
- August 26, 2019
- Bug bounty in D again - my hot take, on reusing code, a fun picture, my tentative plan for the next month
- Time invested is worth a lot
- cgi.d's new scheduler, static this tricks
- July 29, 2019
- July 22, 2019
- Solving vs managing problems
- A big week in the arsd repo
- July 1, 2019
- June 24, 2019
- June 17, 2019
- CRTP thoughts, named arguments DIP review, DConf videos now on youtube
- musings on hybrid CT/RT tests, some more progress on new web framework
- a little more webassembly
- May 20, 2019
- Adam's string interpolation proposal
- DMD 2.086 live, GCC 9 with D support formally released, DConf coming soon, links to posts on builder pattern and disallowing implicit conversions with templates, and 2d array op overloads
- template constraint error improvements coming?
- dmd 2.086 beta, dstep 1.0 released, Adam works on memory usage
- obj-c and webassembly report, tips on is expressions linked.
- new ldc, new dmd, dpp on the blog
- D's future discussed in forums
- LDC beta, DConf blog link, Adam introduces gamehelpers.d
- March 18, 2019
- LDC 1.15.0-beta1, responsive design rant
- dmd 2.085.0 released
- Obj-C interop and D without druntime code to copy/paste
- dmd beta, more info coming next time, demo of new web framework initial prototype
- automatic web interface discussion, reflection tips and tricks
- Adam busy with weather and a move, lots of community announcements
- January 28, 2019
- Working on official blog 2018 retro, C++ new wrapped, dmd reading zips?
- dmd obj-c growing, Adam static foreaches an interface to RPC
- dmd 2.084, hope for future, but busy non-D week for me
- IDE tools released, my cgi.d gets new features
- DConf announced, tip, Adam rants: mouse trap
- This Week in D is back!
More fun stuff in the arsd repo these last couple days. And btw I got my first eye treatment too and it seems to have been a success I feel improvement already! But still gotta avoid staring at computer screens all the time.
Core D Development Statistics
In the community
Community announcements
See more at the announce forum.
What Adam is working on
I fixed a lot of little bugs over the weekend and played with a new scriptable subclass idea.
http bug fixes
arsd.http2 now dynamically loads openssl in an attempt to be more compatible with different openssl binary versions without recompiling the application. It also now correctly sets the hostname for tls ssi, meaning it will just work better on more shared encrypted servers.
subclasses in script
Most my weekend time though was spent on arsd.script and arsd.jsvar. Friday night, an IRC user asked if there was a script language that could inherit D classes. I said my script.d could with just a little work and that work could be automated with a template... then I spent some time and did it fairly automatically. And fixed more random bugs in script.d while I was in there, then realized I never switch and added it in there too!
I wrote up the examples as unittest documentation so you can see the new stuff here: arsd.jsvar.subclassable.
As you can see in the examples in the link, you can declare D classes normally, assign them to the script object via the subclassable template, then start instantiating and subclassing them in the script!
Subclasses created in the script can be passed back to D via references to the base class.
So the way it works is the subclassable template creates a final class that loops through all virtual methods and implements them with a stub that forwards to the var from jsvar. It also adds a private allocate method to help the script's new operator and instantiates a sub object to use as the var prototype.
The generated class is private, but since it implements the base class interface, the rest of D never needs to know about it. This same fact is what allows the script to override it: you set prototype things (which script.d can do in a D-like class syntax for you, or you can do members one by one)
Combining with minigui
Part of the fun here is combining these new facilities with arsd.minigui. Check this out:
There's the D side. Now, the script side:
Run the program with that (you must use the master branch of my arsd libs if you want to try at home) and you'll see a space on the left of the window. Since paddingLeft is actually a virtual method in minigui (something I kinda regret now because changing it is a bit of a pain; I'm probably going to change that at some point, so if you are reading this in the future it might not work like this anymore), it will override it. The script lang treats opCall on a numeric member to be mulitiplication with a default arg of 1, so 5() yields 5*1 (aka 5) or 5(x+2) is 5*x+10, like in algebra. But here it is just the opCall returning self that gives the illusion of this working.
I could have also just done paddingLeft = function() { return 30; }, but since the script supports other syntax, I might as well use it!
In D, I often do an anonymous class return new class Widget { ... } , but that's a little wordy. In the script though, the syntax is extremely small.
Though, of course, you CAN write it out in class style too:
Previously in script.d, you could attach individual objects and/or factory functions to return new ones, but you could never create new D instances like this and not have subclass overrides be visible to other native code.
The rest of minigui has no clue about this new script override feature, but it just worked with the replacement classes in the rest of it.
script.d is still buggy - I found 5 == 3+2 was failing before due to a precedence bug, and it just now got switch and is sure to be quirky in its own way I'll find as I use it more - and it makes zero effort for speed. But it is good at its original motivation: showing how easy D interop to a script language can be.
And this new little feature continues to push those limits.
To see more script.d examples, I wrote a few more here: arsd.script#examples. The classes demo at the bottom is generated from a unittest to show more interop pieces.
script in fiber
One other challenge I had with the script relates to the game I talked about last week: the implementations may take several looks to get user input or display animations, but the script shouldn't worry too much about that.
At first, I wanted to put in some kind of continuation feature in the interpreter, but then I realized there's an easier way: just wrap it in a Fiber and yield at those times.
It was actually really easy, and now my game script can say things like:
and while the reality in D is somewhat complicate to show all that stuff, the script is written just like that. I can't believe I didn't consider the fiber sooner.