Thursday, July 9, 2020

WebAssmebly passing string from C to JavaScript

Recently, I am working on a project that involves WebAssembly. In the project I would need to call out a JavaScript function with a C string char *string as parameter.

I could not get the string in JavaScript function, searching on the internet does not result in any useful information. None of the solutions I found are elegant. Then I realized I had used the WebSocket APIs from Emscripten, which is passing the URL as a C string to the underline JavaScript support function. How does it do that? I digged out the source of it and found in function emscripten_websocket_new, it is using UTF8ToString to convert the C string to a JavaScript String. UTF8ToString is Emscripten's runtime function, I could not call it directly from my JavaScript function.

According to the preamble.js document, I would need to use -s 'EXTRA_EXPORTED_RUNTIME_METHODS=["UTF8ToString"]' on the linker command to export the function and use it as Module.UTF8ToString. Problem solved.

Below are sample code that demonstrate the usage:
JavaScirpt function:

function processing_string_from_c(ptr, len) {
    var text = Module.UTF8ToString(ptr, len);
In the C code:
 char *string;
 EM_ASM({process_string_from_c($0, $1);}, string, strlen(string));
And in the linker line, remember to use

Wednesday, July 25, 2018

Slackware Creator Patrick Volkerding needs help

It was sad to know that Patrick (The creator/maintainer of Slackware) is on financial crisis.

It is unfortunate that he do not get his share of income from the store, and now he is

I mean, I'm sitting here in a house with a giant hole in the roof, a broken door sealed with duct tape, and a failed air conditioning condenser that I can't afford to fix, my wife has been driving on a spare tire for weeks, my teeth need serious attention again, and I only just got a machine here with UEFI for the first time (bought a used machine... really out of my budget but it had to be done).

The Slackware community is eager to help and for the time being Patrick gave his PayPal account link before he could setup a proper channel for donation.

Patrick Volkerding's Paypal account:

And please donate if you like Slackware and willing to help.

Patrick has a cafepress account for Official Licensed Slackware Store. Confirmed by Patrick.

Friday, February 2, 2018

Why people think bitcoin has value, I still don't understand?

I still don't understand why people will value Bitcoin or any derivative coins.

When I first heard about the name of Bitcoin when it was first come out, my instinct think of it has absolutely no value besides wasting resources to calculate those blocks.

The so call decentralize nature of it only has value on the eyes criminal for money launching. Each and every transaction need to be kept in the bitcoin network and it is growing bigger and bigger. That is causing Transaction are getting longer and longer

Even with today's value of USD$8K per bitcoin, I still see no value of it.

Wednesday, October 4, 2017

New Ada for Slackware released

Finally, long after released of GNAT GPL 2017 and GCC in 7.x series in Slackware-current, I got some time to work on the Ada environment for Slackware and got a working version of GPS.

The new release is at GitHub

Friday, May 19, 2017

Thursday, May 4, 2017

GCC 7.1 is out

GCC 7.1 was released on May 2.

I tried it out and recompiled all my Ada related builds, finally I got a stable GPS that does not crash after opening a project file. It still crashed on me, maybe I should revert to an older version?

I have updated my build scripts ada-4-slackware on gitHub. There is still some problems with ASIS 2016, some API changed for the new compiler, will update the build script once got time.