From 70d4f6c7c20ef64b72a4c2cd01cb6b8ba49cfb63 Mon Sep 17 00:00:00 2001 From: David Wendt Date: Sun, 1 Sep 2019 18:23:55 -0600 Subject: [PATCH] Implement more math builtins. Random is currently a stub. --- core/src/avm1/globals.rs | 11 ++++++++++- core/src/avm1/globals/math.rs | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/core/src/avm1/globals.rs b/core/src/avm1/globals.rs index 8a3e523a3..f155e848d 100644 --- a/core/src/avm1/globals.rs +++ b/core/src/avm1/globals.rs @@ -26,11 +26,20 @@ pub fn getURL<'a, 'gc>( 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> { let mut globals = Object::object(gc_context); globals.set_object("Math", math::create(gc_context)); globals.set_function("getURL", getURL, gc_context); + globals.set_function("random", random, gc_context); globals -} +} \ No newline at end of file diff --git a/core/src/avm1/globals/math.rs b/core/src/avm1/globals/math.rs index b2f8c34d7..71601b64b 100644 --- a/core/src/avm1/globals/math.rs +++ b/core/src/avm1/globals/math.rs @@ -35,6 +35,14 @@ fn atan2<'gc>( 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>> { 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("random", random, gc_context); GcCell::allocate(gc_context, math) }