[oden] Extract graphics module
This commit is contained in:
parent
611322d9a3
commit
8218b88820
1 changed files with 3 additions and 19 deletions
|
|
@ -1,22 +1,6 @@
|
||||||
use oden_js::{module, Context, ContextRef, Runtime, Value, ValueRef, ValueResult};
|
use oden_js::{Context, Runtime, Value};
|
||||||
|
|
||||||
pub struct GraphicsAPI {}
|
mod graphics;
|
||||||
|
|
||||||
impl GraphicsAPI {
|
|
||||||
fn define(ctx: &ContextRef) -> oden_js::Result<()> {
|
|
||||||
module::NativeModuleBuilder::new(ctx)
|
|
||||||
.export("print", ctx.new_dynamic_fn(Self::print_fn)?)?
|
|
||||||
.build("graphics")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn print_fn(ctx: &ContextRef, _this: &ValueRef, args: &[&ValueRef]) -> ValueResult {
|
|
||||||
for arg in args {
|
|
||||||
print!("{}", arg.to_string(ctx)?);
|
|
||||||
}
|
|
||||||
println!();
|
|
||||||
Ok(Value::undefined(ctx))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct ScriptContext {
|
pub struct ScriptContext {
|
||||||
context: Context,
|
context: Context,
|
||||||
|
|
@ -34,7 +18,7 @@ impl ScriptContext {
|
||||||
context.add_intrinsic_bigdecimal();
|
context.add_intrinsic_bigdecimal();
|
||||||
context.add_intrinsic_operators();
|
context.add_intrinsic_operators();
|
||||||
|
|
||||||
GraphicsAPI::define(&context).expect("Graphics module should load without error");
|
graphics::GraphicsAPI::define(&context).expect("Graphics module should load without error");
|
||||||
|
|
||||||
let js = include_str!("main.js");
|
let js = include_str!("main.js");
|
||||||
let module = context
|
let module = context
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue