Skip to content

Instantly share code, notes, and snippets.

View nokotan's full-sized avatar

かめのこにょこにょこ nokotan

View GitHub Profile
@nokotan
nokotan / collisionDetection.c
Created February 28, 2022 06:53
JavaScript vs WebAssembly of v8 jit'ed code
#include <math.h>
struct position {
double x;
double y;
double z;
};
int collisionDetection(struct position *positions,
double *radiuses,
@nokotan
nokotan / externref.cpp
Last active June 17, 2023 05:55
use externref in c code
// __externref_t is a opaque pointer that will be translated to wasm externref.
__attribute__((import_name("receive_object")))
__externref_t receive_object(void);
__attribute__((import_name("send_object")))
void send_object(__externref_t);
int main() {
send_object(receive_object());
@nokotan
nokotan / wss.ts
Created September 15, 2021 04:39
WebSocket Server
import WebSocket, { Server } from 'ws';
const wss = new Server({ port: 28080 });
let uniqueID = 0;
let clients: WebSocket[] = [];
wss.on('connection', function connection(ws) {
const clientId = uniqueID++;
clients.push(ws);
#include <emscripten.h>
#include <functional>
#include <numeric>
#include <cassert>
#include <iostream>
std::function<void()> mainLoop;
void runMainLoop()
{
@echo off
setlocal
chcp 65001 > nul
set GitLog=%USERPROFILE%\git.log
set GitTmp=%USERPROFILE%\git.tmp
:: echo ^> git %* >> %GitLog%
if "%1" equ "rev-parse" goto rev_parse
@nokotan
nokotan / inline_asm_in_emscripten.cpp
Created March 13, 2021 15:58
inline WebAssembly in emscripten
#include <cstdint>
#include <iostream>
int32_t add(int32_t n) {
int32_t sum;
__asm (
"local.get %1\n"
"i32.const 1\n"
"i32.add\n"
"local.set %0"
@nokotan
nokotan / extract-comments.py
Created February 26, 2021 16:32
Extract Comments in C/C++ Source File
#!/usr/bin/python3
from clang.cindex import Index, Config, CursorKind
import json as JsonUtil
import os, io, sys
class MyTreeWalker:
def __init__(self):
@nokotan
nokotan / ReturnStructureFromJS.cpp
Created February 8, 2021 07:05
JS関数から構造体をかえしてみる
# include <stdio.h>
# include <emscripten.h>
struct vec2
{
float x, y;
};
extern "C"
{
@nokotan
nokotan / Main.cpp
Created January 20, 2021 07:20
std::future をコルーチンで待ってみる on emscripten
# include <future>
# include <chrono>
# include <iostream>
# include <experimental/coroutine>
# include <emscripten.h>
# include <emscripten/html5.h>
namespace std
{
@nokotan
nokotan / coroutine_on_emscripten.cpp
Last active January 20, 2021 07:19
Simple coroutine test
#include <stdio.h>
#include <experimental/coroutine>
#include <thread>
#include <iostream>
#include <utility>
#include <optional>
#include <thread>