Thanks to a document I found on this forum here written by @geoffda, I was able to build my first kind of “Hello world” WASM module. It simply initializes the WASM module, and writes some lines on the Console output of FS2020.
I used Visual Studio 2019 and created a new project of type “MSFS WASM Module”, which automatically creates the necessary files (see here if you want to know how to do this).
Based on the document above, I slightly changed the contents of the cpp-file (the standard cpp file in VS2019 looks slightly different than the one Geoff shows in his document), and added a few fprintf lines that I expect to appear in the FS2020 Console.
#include <stdio.h>
#include <MSFS/MSFS.h>
#include "WASM_Module1.h"
extern "C" MSFS_CALLBACK void module_init(void)
{
fprintf(stderr, "HABI: stderr Line 1\n");
fprintf(stdout, "HABI: stdout Line 1\n");
fprintf(stderr, "HABI: stderr Line 2\n");
fprintf(stdout, "HABI: stdout Line 2\n");
fprintf(stdout, "HABI: stdout Line 3\n");
fprintf(stderr, "HABI: stderr Line 3\n");
fprintf(stdout, "HABI: stdout Line 4\n");
fprintf(stdout, "HABI: stdout Line 5\n");
fprintf(stderr, "HABI: stderr Line 4\n");
fprintf(stderr, "HABI: stderr Line 5\n");
}
After building this code, the target file “WASM_Module1.wasm” is created. I loaded this WASM file in the community folder and created the 2 required json files according the following structure:
Community
|-- WASM_Module1 (folder)
|---- modules (folder)
|------ WASM_Module1.wasm (file)
|---- layout.json (file)
|---- manifest.json (file)
The content of layout.json and manifest.json are like this:
layout.json (the size of my WASM file is 28318 bytes):
{
"content": [
{
"path": "modules/WASM_Module1.wasm",
"size": 28318,
"date": 132836382172023550
}
]
}
manifest.json
{
"dependencies": [],
"content_type": "MISC",
"title": "WASM_Module1",
"manufacturer": "",
"creator": "Hans Billiet",
"package_version": "0.1.0",
"minimum_game_version": "12.13.0",
"release_notes": {
"neutral": {
"LastUpdate": "",
"OlderHistory": ""
}
}
}
Then I started FS2020, used the “Windows/Console” and filtered on the word “HABI”. This shows the below:
Based on this output, my assumption is that the “stderr” is logging in the Errors (red cross), and stdout is logging in the Messages (blue i).
First question: Why do I only see one line for my Messages? If you look at my code above, you should see the same lines for Messages as for Errors. But it seems that the system stops printing in the Messages after the first newline (“\n”) is sent. Is this a known issue? Maybe this is the reason why the source code of @MobiFlight (see here) also only uses stderr?
Second question: Is there a way to restart the WASM module while FS2020 is running. That would avoid restarting FS2020 every time you have a code change (very long process ).