Web assembly in Lazarus lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Packs · 2023-09-18 18:19 Does any one worked on web assembly in Lazarus. Please guide me ---------------------------------------------------------------------- PierceNg · 2023-09-19 02:08 For starters, read the wiki pages. ---------------------------------------------------------------------- circular · 2023-09-19 05:52 Hi Prakash! Compiling to WebAssembly is an exciting idea. There is some documentation here: https://wiki.freepascal.org/WebAssembly For what I understand, the programs can be embedded in a web page with pas2js and it runs within it a WebAssembly compiled. For example: https://www.freepascal.org/~michael/pas2js-demos/wasienv/canvas/ There are links at the bottom of the page to show the source code. Regards ---------------------------------------------------------------------- egsuh · 2023-10-03 13:26 Does it mean to hide codes of jacascript? ---------------------------------------------------------------------- PierceNg · 2023-10-04 00:54 Quote from: egsuh on October 03, 2023, 03:26:17 pmDoes it mean to hide codes of jacascript? WebAssembly (Wasm) is the 'executable' binary format for an abstract machine. The web browser implements this abstract machine allowing it to execute .wasm files. Wasm is designed to be executed at near native speed; well, nearer to native speed than Javascript can be. Since Wasm is an executable format, programming languages can target it. That's another benefit of Wasm: Write programs for the web browser in your favourite language. Actually, modern computers are so fast, and desktop computers typically so idle, people have compiled interpreters (Python, Javascript, etc) into Wasm, then use the web browser's Wasm engine to run the interpreter to run Python/Javascript/whatever scripts. Layers upon layers of compilation/transformation and still fast enough to be useful and/or fun. ---------------------------------------------------------------------- egsuh · 2023-10-05 01:45 Wow. This is great. I’m more interested in hiding javascript codes so that others cannot see them. ---------------------------------------------------------------------- tr_escape · 2023-10-05 05:29 Quote from: egsuh on October 05, 2023, 03:45:34 amWow. This is great. I’m more interested in hiding javascript codes so that others cannot see them. Actually users can be see transpilled/compiled codes as javascript by some tools: https://webassembly.github.io/wabt/demo/wat2wasm/index.html Main repo: https://github.com/WebAssembly/wabt/blob/main/docs/decompiler.md Also there are some attemps to decompile one of them: https://v8.dev/blog/wasm-decompile But ofcourse it isn't your pascal codes ---------------------------------------------------------------------- Warfley · 2023-10-06 07:44 The thing about WASM is, as great as it sounds, it's actually not as useful for web development as it may appear. The problem is the browser has no APIs towards WASM, meaning you WASM code cannot interact with anything in the browser. It cannot display anything, access the DOM, the web storage, perform webrequests, etc. All that WASM can do is do raw computations and then call JavaScript functions which can then actually do this sort of work. So to give an example, lets say you want to color a button green after you clicked it, you would need to first register a JavaScript function to be called when the button is clicked. This JS function then calls the WASM function, which then has the logic to select the green color, and then it would call a javascript function which takes the color as argument and would set the color of the button to that argument. At this point you replaced 1 javascript function with two functions of JavaScript and one function of WASM with absolutely no benefit Meaning if you just want to make a website that displays things and interacts with a backend, WASM does not give you any advantage, because for all that functionality you need to use javascript anyway. WASM is only good if you need to perform a lot of RAW computations, e.g. encoding and decoding video files or something similar. If you do not have such requirements, using plain Pas2JS is probably going to be the better choice for you. ---------------------------------------------------------------------- egsuh · 2023-10-07 07:17 Quote meaning you WASM code cannot interact with anything in the browser. It cannot display anything, access the DOM, the web storage, perform webrequests, etc. If this is the case, WASM has no merit at all for me, because my javascript codes are mostly accessing and controlling DOM. ---------------------------------------------------------------------- Fibonacci · 2023-10-07 07:26 WASM is for things like this: https://wavacity.com/ 24 MB of WASM Rendering, processing, computing ---------------------------------------------------------------------- Warfley · 2023-10-07 10:50 Quote from: Fibonacci on October 07, 2023, 09:26:59 amWASM is for things like this: https://wavacity.com/ 24 MB of WASM Rendering, processing, computing Note that this is emscripten, which automatically also generates the required JavaScript to interact with the browser API. So besides the 24 MB of WASM, this also contains a 12k loc JavaScript file Emscripten is aboslutely great to translate existing C++ programs into WASM and JavaScript, with very little effort. It has automatic translation rules for GUI frameworks like GTK, for filesystem access, etc. which is why it can be used to quite seamlessly port whole C++ applications (like Audacity in this case) to the web. The FPC WASM capabilities are of course much more limited, you can't expect to put in a whole Lazarus Project and get a fully functional WASM+JS application out. I think for Pascal you are going to rather do most of the work in Pas2JS manually, and then take the parts that require more performance and put them into a dedicated WASM library, which is then called by the Pas2JS code. Quote from: egsuh on October 07, 2023, 09:17:14 amIf this is the case, WASM has no merit at all for me, because my javascript codes are mostly accessing and controlling DOM. As I said, WASM is great in theory, but in practice not that useful for the vast majority of applications. That said I think to have read somewhee that the Webassembly group at W3C is currently working on a future version of WASM, which will not require JavaScript as intermediary anymore, but get direct access to a set of browser APIs. ---------------------------------------------------------------------- Thaddy · 2023-10-07 15:02 FPC has a native WASI/WASM back end. Just build a cross-compiler for target WASM.... No need to fiddle with other languages.