Skip to content

Commit

Permalink
Merge pull request #30 from AreaLayer/feat/bindings
Browse files Browse the repository at this point in the history
Add bindings
  • Loading branch information
22388o authored Aug 28, 2024
2 parents 8632d65 + a5a5f28 commit ae0d68a
Show file tree
Hide file tree
Showing 10 changed files with 297 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": ".",
"program": "build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
59 changes: 59 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}
144 changes: 144 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "javascript-dlc"
version = "0.1.0"
authors = ["AreaLayer <arealayer.net>"]
edition = "2018"


[lib]
crate-type = ["cdylib"]

[dependencies]
wasm-bindgen = "0.2"
web-sys = { version = "0.3", features = ["console"] }
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ Import packages or modules for build your own application
- [x] Bitcoin Knots
- [x] BOLT12 support
- [x] BOLT11 support
- [x] Bindings (Rust, TS and C++) [ Demo/WIP ]
- [ ] LNURL
- [ ] Breez SDK compatible
- [ ] Bindings (Rust, TS and C++)
- [ ] Node DLC compatible
- [ ] Mutinynet
- [ ] DLC message
Expand Down
8 changes: 8 additions & 0 deletions bindings/libraries/c++/greet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <string>

extern "C" {
const char* greet(const char* name) {
std::string greeting = "Hello, " + std::string(name) + "!";
return greeting.c_str();
}
}
6 changes: 6 additions & 0 deletions bindings/libraries/ts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { greet as rustGreet } from '../rust_wasm/rust_wasm';
import { greet as cppGreet } from '../cpp_wasm/cpp_wasm';


console.log(rustGreet('Rust'));
console.log(cppGreet('C++'));
9 changes: 9 additions & 0 deletions bindings/libraries/ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
}
}
15 changes: 15 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Import everything necessary from wasm_bindgen
use wasm_bindgen::prelude::*;

// Import the console logging functionality from the web_sys crate
use web_sys::console;

#[wasm_bindgen]
pub fn greet(name: &str) -> String {
format!("DLC, {}!", name)
}

#[wasm_bindgen]
pub fn log(msg: &str) {
console::log_1(&msg.into());
}

0 comments on commit ae0d68a

Please sign in to comment.