diff --git a/core/build_playerglobal/src/lib.rs b/core/build_playerglobal/src/lib.rs index 4122673019ed..37e6b3487094 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 ff566440ccd8..f085ca921c61 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