Compare commits
No commits in common. "3b02faf9b4ac3fb8b511b333b69d15d10c65d6a9" and "a48a9efdb4c1b4337a3a809543c016b8df3f4e5d" have entirely different histories.
3b02faf9b4
...
a48a9efdb4
3 changed files with 15 additions and 55 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{ContextRef, Error, Result, Value, ValueRef};
|
use crate::{ContextRef, Error, Result, ValueRef};
|
||||||
use std::num::TryFromIntError;
|
use std::num::TryFromIntError;
|
||||||
|
|
||||||
pub trait TryFromValue: Sized {
|
pub trait TryFromValue: Sized {
|
||||||
|
|
@ -98,9 +98,10 @@ impl TryFromValue for String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFromValue for Value {
|
// impl<'c, T: Class> TryFrom<&'c ValueRef<'_>> for T {
|
||||||
#[inline]
|
//
|
||||||
fn try_from_value(value: &ValueRef, ctx: &ContextRef) -> Result<Self> {
|
// #[inline]
|
||||||
Ok(value.dup(ctx))
|
// fn try_from_value(value: &ValueRef, ctx:&ContextRef) -> Result< Self> {
|
||||||
}
|
// T::from_value(value)
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
function init() {
|
function init() {
|
||||||
graphics.print("Hello world!");
|
|
||||||
// console.log("Hello world!");
|
// console.log("Hello world!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,61 +1,21 @@
|
||||||
use oden_js::{Class, ClassID, Context, ContextRef, Runtime, Value, ValueRef, ValueResult};
|
use oden_js as js;
|
||||||
|
|
||||||
pub struct GraphicsAPI {}
|
|
||||||
|
|
||||||
impl GraphicsAPI {
|
|
||||||
fn print_fn(ctx: &ContextRef, _this: &ValueRef, args: &[&ValueRef]) -> ValueResult {
|
|
||||||
for arg in args {
|
|
||||||
print!("{}", arg.to_string(ctx)?);
|
|
||||||
}
|
|
||||||
println!();
|
|
||||||
Ok(Value::undefined(ctx))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Class for GraphicsAPI {
|
|
||||||
fn class_id() -> &'static ClassID {
|
|
||||||
static ID: ClassID = ClassID::new("GraphicsAPI");
|
|
||||||
&ID
|
|
||||||
}
|
|
||||||
|
|
||||||
fn prototype(context: &ContextRef) -> ValueResult {
|
|
||||||
let mut prototype = context.new_object()?;
|
|
||||||
|
|
||||||
let print = context.new_dynamic_fn(GraphicsAPI::print_fn)?;
|
|
||||||
prototype.set_property(context, "print", &print)?;
|
|
||||||
|
|
||||||
Ok(prototype)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct ScriptContext {
|
pub struct ScriptContext {
|
||||||
context: Context,
|
context: js::Context,
|
||||||
init: Value,
|
init: js::Value,
|
||||||
update: Value,
|
update: js::Value,
|
||||||
draw: Value,
|
draw: js::Value,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ScriptContext {
|
impl ScriptContext {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let runtime = Runtime::new();
|
let runtime = js::Runtime::new();
|
||||||
|
|
||||||
let mut context = Context::new(runtime);
|
let mut context = js::Context::new(runtime);
|
||||||
context.add_intrinsic_bigfloat();
|
context.add_intrinsic_bigfloat();
|
||||||
context.add_intrinsic_bigdecimal();
|
context.add_intrinsic_bigdecimal();
|
||||||
context.add_intrinsic_operators();
|
context.add_intrinsic_operators();
|
||||||
|
|
||||||
// TODO: This should be a module instead. Yuck.
|
|
||||||
let mut global = context
|
|
||||||
.global_object()
|
|
||||||
.expect("Unable to get global object");
|
|
||||||
let graphics = GraphicsAPI {};
|
|
||||||
let graphics = graphics
|
|
||||||
.into_value(&context)
|
|
||||||
.expect("Unable to wrap graphics API");
|
|
||||||
global
|
|
||||||
.set_property(&context, "graphics", &graphics)
|
|
||||||
.expect("Unable to establish graphics");
|
|
||||||
|
|
||||||
let js = include_str!("main.js");
|
let js = include_str!("main.js");
|
||||||
let module = context
|
let module = context
|
||||||
.load_module(js, "main.js")
|
.load_module(js, "main.js")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue