4 ms·
I was excited at first. Compile Javascript like code into WebAssembly text format? Zero dependencies? Count me in! I thought: Great! Let's try it! So how do I
by TekMol 8y ago
I was excited at first. Compile Javascript like code into WebAssembly text format? Zero dependencies? Count me in!
I thought: Great! Let's try it! So how do I use it? How do I hand over a string of Walt and get a string of WebAssemblyText back?
I though there is a javascript file somewhere in the project that has a compile() function that does that.
And then I clicked on the Quick Start Guide and it looks much more complicated. It tells me to install node, npm, webpack, walt-compiler, walt-loader... set up a project with a certain structure, create a landing page...
Help :) That's not what I want. I just want a function that takes a string and returns a string.
Would it be possible to just offer a javascript file to be used directly in the Browser? That exports a function which translates your JS dialect to WasmText?
Is that file somewhere in there maybe?
- manigandham 8y agoYes, that's the compiler: https://github.com/ballercat/walt/tree/master/packages/walt-compiler https://github.com/ballercat/walt/tree/master/packages/walt-... It's written in JS so you'll need node to run it, and npm is a package manager for node so you should use that to install and call it. If you just want a hosted site to play with code, it's linked right at the top: https://ballercat.github.io/walt/ https://ballercat.github.io/walt/
- TekMol 8y agoIt's written in JS so you'll need node to run it I happily run JS in my browser all day. Why do I need node for this code?
- codetrotter 8y ago> Why do I need node for this code? The next paragraph of the comment you replied to answers that — you don’t, you can use https://ballercat.github.io/walt/ https://ballercat.github.io/walt/ in your browser.
- manigandham 8y agoBecause different runtimes support different features and performance (like dealing with files and disk access) but I already posted the link for the browser version in that comment.
- cousin_it 8y agoI think that's not quite what was asked for. What was asked for is one JS file with a function that takes a string and returns a string. Not a node package, not a website. Check out Three.js, it's a big library which can be used as one file three.min.js.
- gchq-7703 8y agoIf you check the `dist` folder within the linked Git repository you can see a `walt.min.js` file[0]. You should be able to include that file and try out the package in your browser in a similar way to how you use `three.min.js`. [0] https://github.com/ballercat/walt/blob/master/packages/walt-compiler/dist/walt.min.js https://github.com/ballercat/walt/blob/master/packages/walt-...
- humblebee 8y agohttps://unpkg.com/walt-compiler@0.16.2/dist/walt.js https://unpkg.com/walt-compiler@0.16.2/dist/walt.js
- rymate1234 8y agoMaybe so you can deliver precompiled wasm to a browser rather than having to deliver the source and a compiler?
- krapp 8y agoYou don't need node to compile WASM or deliver it to the browser, either. The only reason this "needs" NPM is because it's become convention that all javascript projects need NPM and some related toolchain regardless of their complexity.
- derefr 8y agoNo, the convention is that Javascript projects are distributed as source rather than as "binaries" (single minified JS files.) Source code generally needs a build tool. NPM is a build tool.
- simen 8y agoIt doesn't translate to wasm text format, but to wasm binary format. The walt-compiler (https://github.com/ballercat/walt/tree/master/packages/walt-compiler https://github.com/ballercat/walt/tree/master/packages/walt-...) readme shows how to use it to compile text into a a buffer which you can write to disk or instantiate into a webassembly module.
- TekMol 8y agoIt doesn't translate to wasm text format, but to wasm binary format. Oh, ok. That is interesting too. But I would have liked to build a tool where I type Walt on the left and see the resulting WASMtext on the right. So this seems to not be a solution for that.
- KenanSulayman 8y agoWhat? Just use wasm2wat [1] and you’ll get the text format. [1] https://github.com/WebAssembly/wabt https://github.com/WebAssembly/wabt
- cygx 8y agoThat tool already exists: https://ballercat.github.io/walt/ https://ballercat.github.io/walt/ - though you have to switch 'tabs' to see the WASM code.
- TekMol 8y agoYes, I saw that. It's not the interface that I would like to use. I want to write Walt on the left and instantly see the WasmT on the right. Also, that tool does not work here. It gives me 'Uncaught ReferenceError: getAST is not defined' as soon as I type something in the code tab.
- runarberg 8y agoThese look less like questions about the project and more like feature requests. Perhaps you should try unpkg: <script src="https://unpkg.com/walt-compile"></script> And if that doesn't work, perhaps you can submit an issue or a PR.
- undershirt 8y agoHere you go :) https://jsbin.com/nisoget/edit?html,js,console https://jsbin.com/nisoget/edit?html,js,console
- TekMol 8y agoAwesome! Thanks man! This is what makes Hacker News great!
- undershirt 8y agoActually, check again! I just updated it to NOT use wabt. Walt-compiler has its own semantic printer, so its output is more readable. And yes! I think answering these kind of simple questions is important, so thanks for asking them.
- TekMol 8y agoEven better. I'm already having fun with it.
- nojvek 8y agoYour argument is valid, the QuickStart example isn’t wrong though. Webpack is somewhat the bundling standard in front end. What they showed, I can easily get it working in a large project without a lot of kungfu. If you want the walt->wasm function, it’s usually the loader. And yes, you can invoke the loader standalone. Perhaps they should give a much simpler example and then later a webpack example. It’s open source, open a PR may be?
- pygy_ 8y agoGo to https://flems.io/walt-compiler https://flems.io/walt-compiler You can then play with the `Walt` global.