[oden] JavaScript, god help me
This commit is contained in:
parent
16e6f1304c
commit
8d7dd789ed
6 changed files with 92 additions and 4 deletions
|
|
@ -356,6 +356,8 @@ pub async fn run() {
|
|||
let mut state = State::new(window).await;
|
||||
|
||||
let context = script::ScriptContext::new();
|
||||
context.init();
|
||||
|
||||
event_loop.run(move |event, _, control_flow| {
|
||||
control_flow.set_poll();
|
||||
|
||||
|
|
|
|||
9
src/main.js
Normal file
9
src/main.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
function init() {
|
||||
// console.log("Hello world!");
|
||||
}
|
||||
|
||||
function update() {}
|
||||
|
||||
function draw() {}
|
||||
|
||||
export { init, update, draw }
|
||||
|
|
@ -1,7 +1,10 @@
|
|||
use oden_js as js;
|
||||
|
||||
pub struct ScriptContext {
|
||||
_context: js::Context,
|
||||
context: js::Context,
|
||||
init: js::Value,
|
||||
update: js::Value,
|
||||
draw: js::Value,
|
||||
}
|
||||
|
||||
impl ScriptContext {
|
||||
|
|
@ -13,10 +16,40 @@ impl ScriptContext {
|
|||
context.add_intrinsic_bigdecimal();
|
||||
context.add_intrinsic_operators();
|
||||
|
||||
ScriptContext { _context: context }
|
||||
let js = include_str!("main.js");
|
||||
let module = context
|
||||
.load_module(js, "main.js")
|
||||
.expect("Unable to load main");
|
||||
|
||||
let init = module
|
||||
.get_module_export(&context, "init")
|
||||
.expect("Unable to fetch init");
|
||||
let update = module
|
||||
.get_module_export(&context, "update")
|
||||
.expect("Unable to fetch update");
|
||||
let draw = module
|
||||
.get_module_export(&context, "draw")
|
||||
.expect("Unable to fetch draw");
|
||||
|
||||
ScriptContext {
|
||||
context,
|
||||
init,
|
||||
update,
|
||||
draw,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&self) {}
|
||||
pub fn init(&self) {
|
||||
self.init.call(&self.context).expect("Exception in init");
|
||||
}
|
||||
|
||||
pub fn render(&self) {}
|
||||
pub fn update(&self) {
|
||||
self.update
|
||||
.call(&self.context)
|
||||
.expect("Exception in update");
|
||||
}
|
||||
|
||||
pub fn render(&self) {
|
||||
self.draw.call(&self.context).expect("Exception in draw");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue