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.
This commit is contained in:
Aaron Hill 2022-06-16 15:20:49 -05:00 committed by relrelb
parent 4e805bb109
commit 21eac9364f
6 changed files with 21 additions and 19 deletions

View File

@ -1,7 +1,6 @@
//! An internal Ruffle utility to build our playerglobal //! An internal Ruffle utility to build our playerglobal
//! `library.swf` //! `library.swf`
use std::collections::HashSet;
use std::fs::File; use std::fs::File;
use std::path::PathBuf; use std::path::PathBuf;
use std::process::Command; use std::process::Command;
@ -23,13 +22,6 @@ pub fn build_playerglobal(
let out_path = out_dir.join("playerglobal.swf"); 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' // This will create 'playerglobal.abc', 'playerglobal.cpp', and 'playerglobal.h'
// in `out_dir` // in `out_dir`
let mut cmd = Command::new("java"); 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") { if entry.path().extension().and_then(|e| e.to_str()) != Some("as") {
continue; continue;
} }
let class = entry.into_path(); // Files like `uint.stub.as` are stubs - they're referenced by
let class_name: String = class // other classes that we need to compile, but the real definition
.strip_prefix(&classes_dir)? // is in Ruffle itself (in Rust code).
.with_extension("") // As a result, we don't emit them into the final SWF (but we do
.iter() // provide them to asc.jar with '-import' to link against).
.map(|c| c.to_string_lossy()) if entry
.collect::<Vec<_>>() .path()
.join("/"); .file_stem()
.unwrap()
if stub_classes.contains(class_name.as_str()) { .to_string_lossy()
.ends_with(".stub")
{
cmd.arg("-import"); cmd.arg("-import");
} }
cmd.arg(class); cmd.arg(entry.path());
} }
println!("Compiling: {:?}", cmd); println!("Compiling: {:?}", cmd);

View File

@ -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 file at build time, which is included into the final Ruffle binary
and loaded during player initialization. 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 In many cases, defining a class in ActionScript results in
code that's much simpler and more readable than if were code that's much simpler and more readable than if were
defined in Rust. defined in Rust.