12 ms·
Roll your own JavaScript runtime, pt. 3
- rickbutton 3y agoroll your own runtime does not imply to me `import runtime from "runtime";` but this seems to just be "include deno and use deno"?
- notamy 3y agoThis is using Deno as the glue between Rust and V8; it leaves many things to the end-user, such as stdlib implementation. This isn't quite the same as building it from scratch, but it's still building a good chunk of the runtime I think.
- deleted 3y ago[deleted]
- FascistDonut 3y agoWhen/why would you want to do this? I went to pt. 1 but it didn't seem clear.
- NTARelix 3y agoThe content of the series describes creating something like the beginnings of a Deno alternative, upon which the reader could fully recreate Deno or Node.js. It seems to me that the core idea presented is "a JavaScript/TypeScript interface to Rust". The thing that most interests me about something like this is not making yet another alternative to Deno or Node.js, but the potential for adding a scripting language to an application or framework written in Rust. I'm thinking like Python scripting of Blender, Lua as a scripting/modding layer for a game engine, scripting of Tiled with JS, an Electron alternative using GTK, your own browser.
- TechBro8615 3y agoWhen you want to add a sandboxed scripting language to any system, you might implement something like this. For example, a multi-tenant web proxy that lets users script functions for transforming requests, or a game that lets users script the user interface elements, would be two valid use cases.
- emmanueloga_ 3y agosounds useful for sandboxing
- rektide 3y agoThere's hundreds of programs that can be scripted with embedded Lua. For example, nginx web server, or neovim editor or awesomewm window manager. Having an embedded scripting language gives these systems enormous flexibility & utility. This series is effectively about doing the same, but embedded Deno instead of Lua. It's showing how to launch Deno runtime, and how to seed those runtime with various hooks to access & manipulate the program it's embedded in.
- olliej 3y agoThis is not any kind of "rolling your own JS runtime". This is "use our framework to use v8 from rust". What an obnoxious title. v8 is a JS runtime. JSC is a JS runtime. SpiderMonkey is a JS runtime. All of these are embeddable and have usable APIs. If all you are doing, is linking to a JS runtime, and then using it, you aren't "rolling your own runtime". If you want to roll your own JS runtime go look at how the LibJS folk in serenity did it - they did it without corporate backing and despite that I believe LibJS is fairly complete even with the new draft language features, albeit lacking a decade or so of performance optimizations.
- jchw 3y agoYeah unfortunately as pessimistic as it seems I must agree, this title is disappointing to me. I'd love to see a series discussing the ins and outs of even just tiny segments of implementing ECMA262, as there's quite a lot of interesting nuance that has come up over the years. I guess the difference is runtime vs perhaps interpreter, but it's definitely ambiguous.
- olliej 3y agoV8, JSC, etc have an interpreter (or JIT, or what have you), but they also include everything else: the GC, the standard library, the standard and core objects. e.g. the full runtime. Adding a couple of functions to an existing runtime is not rolling your own runtime.
- userbinator 3y agoYou might find this interesting: https://github.com/svaarala/duktape/blob/master/doc/compiler.rst https://github.com/svaarala/duktape/blob/master/doc/compiler...
- deleted 3y ago[deleted]
- intelVISA 3y agoI expected some interesting content and left with a "import v8: Cargo edition" 'tutorial' is this really a good look for the ailing Deno?
- obpe 3y agoJS has improved a lot over the years but I am not sure I would want it as the default scripting language for applications. JS is really only useful because it's the language you access the browser's API with. If you are creating a different kind of application and therefore don't need the DOM or other browser things then why JS at all? Having worked with Lua for some game mods, it seems like a better choice for an integrated language. Maybe a Rust inspired language would make a better fit for a modern DSL... insert XKCD comic about standards proliferation.
- giraffe_lady 3y agoLua is a better integrated language simply because that path is intended by its developers and directly documented, and its runtime is designed to be easy to couple to C. But nothing about its semantics make it better for that task than javascript. They are extremely similar except lua doesn't have stuff you would almost always want like basic string manipulation tools, regex, any array operations more sophisticated than loop. You can argue you don't need those things, but their lack isn't a feature either. If you're not coupling to C's memory model or if for some reason someone has already done the work of building and debugging the integration... you gain nothing by using lua over js. I've done professional work in lua and it's highly overrated imo. For integrated languages Tcl or janet is a better choice, unless your use case is extremely extremely simple and then forth is a better choice. The only time I would choose lua is if I'm integrating with C, the integration language tasks are very simple but also requires coroutines. Lua's coroutines are genuinely good.
- paulddraper 3y agoBecause Worse is Better [1] Lua is technically superior, but JavaScript is practically superior due to its ubiquitous platform the web browser. Similar but different to C "beating" Lisp. [1] https://en.wikipedia.org/wiki/Worse_is_better https://en.wikipedia.org/wiki/Worse_is_better
- tmountain 3y agoI strongly disagree. Lua somehow maintains a positive reputation, but it’s extremely quirky and weird in many ways. It has some Perl-esque rough edges (#array for length), and some “let’s be different” design decisions that are counterintuitive and unnecessary (arrays starting at the 1 index instead of 0). JavaScript as it is today is a vastly more ergonomic and fluid experience, and I am saying this as someone that has written tons of both. The embedding experience with Lua is likely much more form fit than JavaScript (sandboxing, etc). I’m strictly speaking about syntax and language features.
- tbillington 3y agoI made a demo integrating deno and sqlite into a quasi-"lambda" runtime in 200 lines for a rust meetup talk, if anyone is interested https://github.com/tbillington/rust_serverless_runtime https://github.com/tbillington/rust_serverless_runtime.