Skip to content

Instantly share code, notes, and snippets.

@ngsankha
Created January 23, 2016 19:09
Show Gist options
  • Save ngsankha/3ad475c9f8a46862266e to your computer and use it in GitHub Desktop.
Save ngsankha/3ad475c9f8a46862266e to your computer and use it in GitHub Desktop.
ChakraCore embedding
use std::mem;
struct JsRuntimeHandle;
struct JsThreadServiceCallback;
struct JsRef;
type JsContextRef = JsRef;
type JsValueRef = JsRef;
type JsErrorCode = usize;
enum JsRuntimeAttributes {
JsRuntimeAttributeNone
}
#[link(name = "ChakraCore")]
extern {
fn JsCreateRuntime(attributes: JsRuntimeAttributes, threadService: Option<JsThreadServiceCallback>, runtime: *mut JsRuntimeHandle) -> JsErrorCode;
fn JsCreateContext(runtime: JsRuntimeHandle, newContext: *mut JsContextRef) -> JsErrorCode;
}
fn main() {
unsafe {
let mut rt: JsRuntimeHandle = mem::transmute(());
let mut cx: JsContextRef = mem::transmute(());
JsCreateRuntime(JsRuntimeAttributes::JsRuntimeAttributeNone, None, &mut rt);
println!("{}", JsCreateContext(rt, &mut cx));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment