From 21eac9364fca986d457e0d9af73e99bf657f5655 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Thu, 16 Jun 2022 15:20:49 -0500 Subject: [PATCH] avm2: Use '.stub.as' suffix to indicate stub class This removes the need for keeping an updating list in 'build_playerglobal', and made things easier for me when porting classes to ActionScript. --- core/build_playerglobal/src/lib.rs | 32 ++++++++----------- .../globals/{Boolean.as => Boolean.stub.as} | 0 .../globals/{Number.as => Number.stub.as} | 0 .../globals/{Object.as => Object.stub.as} | 0 core/src/avm2/globals/README.md | 8 +++++ .../globals/{String.as => String.stub.as} | 0 6 files changed, 21 insertions(+), 19 deletions(-) rename core/src/avm2/globals/{Boolean.as => Boolean.stub.as} (100%) rename core/src/avm2/globals/{Number.as => Number.stub.as} (100%) rename core/src/avm2/globals/{Object.as => Object.stub.as} (100%) rename core/src/avm2/globals/{String.as => String.stub.as} (100%) diff --git a/core/build_playerglobal/src/lib.rs b/core/build_playerglobal/src/lib.rs index 412267301..37e6b3487 100644 --- a/core/build_playerglobal/src/lib.rs +++ b/core/build_playerglobal/src/lib.rs @@ -1,7 +1,6 @@ //! An internal Ruffle utility to build our playerglobal //! `library.swf` -use std::collections::HashSet; use std::fs::File; use std::path::PathBuf; use std::process::Command; @@ -23,13 +22,6 @@ pub fn build_playerglobal( let out_path = out_dir.join("playerglobal.swf"); - // These classes are currently stubs - they're referenced by - // other classes that we need to compile, but the real definition - // is in Ruffle itself (in Rust code). - // As a result, we don't emit them into the final SWF (but we do - // provide them to asc.jar with '-import' to link against). - let stub_classes: HashSet<_> = ["Object", "Number", "Boolean", "String"].into(); - // This will create 'playerglobal.abc', 'playerglobal.cpp', and 'playerglobal.h' // in `out_dir` let mut cmd = Command::new("java"); @@ -49,19 +41,21 @@ pub fn build_playerglobal( if entry.path().extension().and_then(|e| e.to_str()) != Some("as") { continue; } - let class = entry.into_path(); - let class_name: String = class - .strip_prefix(&classes_dir)? - .with_extension("") - .iter() - .map(|c| c.to_string_lossy()) - .collect::>() - .join("/"); - - if stub_classes.contains(class_name.as_str()) { + // Files like `uint.stub.as` are stubs - they're referenced by + // other classes that we need to compile, but the real definition + // is in Ruffle itself (in Rust code). + // As a result, we don't emit them into the final SWF (but we do + // provide them to asc.jar with '-import' to link against). + if entry + .path() + .file_stem() + .unwrap() + .to_string_lossy() + .ends_with(".stub") + { cmd.arg("-import"); } - cmd.arg(class); + cmd.arg(entry.path()); } println!("Compiling: {:?}", cmd); diff --git a/core/src/avm2/globals/Boolean.as b/core/src/avm2/globals/Boolean.stub.as similarity index 100% rename from core/src/avm2/globals/Boolean.as rename to core/src/avm2/globals/Boolean.stub.as diff --git a/core/src/avm2/globals/Number.as b/core/src/avm2/globals/Number.stub.as similarity index 100% rename from core/src/avm2/globals/Number.as rename to core/src/avm2/globals/Number.stub.as diff --git a/core/src/avm2/globals/Object.as b/core/src/avm2/globals/Object.stub.as similarity index 100% rename from core/src/avm2/globals/Object.as rename to core/src/avm2/globals/Object.stub.as diff --git a/core/src/avm2/globals/README.md b/core/src/avm2/globals/README.md index ff566440c..f085ca921 100644 --- a/core/src/avm2/globals/README.md +++ b/core/src/avm2/globals/README.md @@ -16,6 +16,14 @@ Currently, globals are implemented in one of two ways: file at build time, which is included into the final Ruffle binary and loaded during player initialization. +ActionScript files can be marked as 'stubs' by giving them the suffix +'.stub.as' instead of '.as' (e.g. 'Number.stub.as'). Stub classes +can be referenced from other '.as' files, but they will not be included +in the final 'playerglobal.swf'. This is useful when you need to write +a '.as' file that references a class defined in Rust - you can create +a stub class without needing to port the entire pre-existing class +to ActionScript. + In many cases, defining a class in ActionScript results in code that's much simpler and more readable than if were defined in Rust. diff --git a/core/src/avm2/globals/String.as b/core/src/avm2/globals/String.stub.as similarity index 100% rename from core/src/avm2/globals/String.as rename to core/src/avm2/globals/String.stub.as