That being said, it's not very usable right now.
It works, but it barely supports any gateway events and only gives you access to the message content due to how it works.
It's also not very stable at the moment, so if you find any bugs, feel free to open an issue.
The "main entry file" is src/main.c. This file contains boilerplate code to get you started. Feel free to add more commands by creating instances of Command and calling register_command with a pointer to your command as parameter.
-
Install Emscripten
Emscripten is used to compile C/C++ source code down to a small.wasmfile.
We can then import the binary in JavaScript land, instantiate and use it!
Installing emscripten is quite easy: see this page. -
Install Make
This step isn't required, but it will make compiling the source code a lot easier. -
Compile the source code
If you've just installed Make, you can simply runmake build. This will build the project and produce a.wasmfile. -
Import the TypeScript library
The easiest way to import this library for now is to simply copy & paste the contents ofsrc/pylonwasm.tsinto a new file. You can thenimport()it in a file, instantiatePylonWasmand register events.
Example:
import { PylonWasm } from './pylonwasm';
const pwasm = new PylonWasm(
'https://cdn.discordapp.com/attachments/652646728813772820/754364397853343815/pylonwasm.wasm'
);
discord.on(
discord.Event.MESSAGE_CREATE,
pwasm.forEvent(discord.Event.MESSAGE_CREATE).bind(pwasm)
);
// !!greet test
// ==> hello test!v8 (Google's JavaScript engine that Chromium and Pylon uses to run code) supports WebAssembly, which is a relatively new technology that supports running code written in another programming language.
This project uses Emscripten to compile code to WebAssembly, which we can then instantiate in JavaScript!
WebAssembly (by design) only allows numerical values to be passed around. This means no strings, structs or arrays. Only numbers and pointers are allowed.
The way this works is by allocating memory for the message content in JavaScript and calling C functions with a pointer to the message content as parameter.
As you can see, this makes it hard to pass a lot of external values to C functions, however I do have plans for making this possible by allocating memory for a struct in JavaScript and passing the pointer to the struct to C functions.
- Transfer pointer to structs rather than pointer to string
- Support more events
- Support for Pylon's built-in command group