Implement more math builtins.
Random is currently a stub.
This commit is contained in:
parent
4e9fb2676b
commit
70d4f6c7c2
|
@ -26,11 +26,20 @@ pub fn getURL<'a, 'gc>(
|
||||||
Value::Undefined
|
Value::Undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn random<'gc>(
|
||||||
|
_action_context: &mut ActionContext<'_, 'gc, '_>,
|
||||||
|
_this: GcCell<'gc, Object<'gc>>,
|
||||||
|
args: &[Value<'gc>],
|
||||||
|
) -> Value<'gc> {
|
||||||
|
Value::Number(4.0) //chosen by fair dice roll. guaranteed to be random.
|
||||||
|
}
|
||||||
|
|
||||||
pub fn create_globals<'gc>(gc_context: MutationContext<'gc, '_>) -> Object<'gc> {
|
pub fn create_globals<'gc>(gc_context: MutationContext<'gc, '_>) -> Object<'gc> {
|
||||||
let mut globals = Object::object(gc_context);
|
let mut globals = Object::object(gc_context);
|
||||||
|
|
||||||
globals.set_object("Math", math::create(gc_context));
|
globals.set_object("Math", math::create(gc_context));
|
||||||
globals.set_function("getURL", getURL, gc_context);
|
globals.set_function("getURL", getURL, gc_context);
|
||||||
|
globals.set_function("random", random, gc_context);
|
||||||
|
|
||||||
globals
|
globals
|
||||||
}
|
}
|
|
@ -35,6 +35,14 @@ fn atan2<'gc>(
|
||||||
Value::Number(NAN)
|
Value::Number(NAN)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn random<'gc>(
|
||||||
|
_action_context: &mut ActionContext<'_, 'gc, '_>,
|
||||||
|
_this: GcCell<'gc, Object<'gc>>,
|
||||||
|
_args: &[Value<'gc>],
|
||||||
|
) -> Value<'gc> {
|
||||||
|
Value::Number(0.4) //chosen by fair dice roll. guaranteed to be random.
|
||||||
|
}
|
||||||
|
|
||||||
pub fn create<'gc>(gc_context: MutationContext<'gc, '_>) -> GcCell<'gc, Object<'gc>> {
|
pub fn create<'gc>(gc_context: MutationContext<'gc, '_>) -> GcCell<'gc, Object<'gc>> {
|
||||||
let mut math = Object::object(gc_context);
|
let mut math = Object::object(gc_context);
|
||||||
|
|
||||||
|
@ -63,6 +71,7 @@ pub fn create<'gc>(gc_context: MutationContext<'gc, '_>) -> GcCell<'gc, Object<'
|
||||||
);
|
);
|
||||||
|
|
||||||
math.set_function("atan2", atan2, gc_context);
|
math.set_function("atan2", atan2, gc_context);
|
||||||
|
math.set_function("random", random, gc_context);
|
||||||
|
|
||||||
GcCell::allocate(gc_context, math)
|
GcCell::allocate(gc_context, math)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue