Skip to content

Commit

Permalink
avm2: Use '.stub.as' suffix to indicate stub class
Browse files Browse the repository at this point in the history
This removes the need for keeping an updating list in
'build_playerglobal', and made things easier for me
when porting classes to ActionScript.
  • Loading branch information
Aaron1011 authored and relrelb committed Jun 16, 2022
1 parent 4e805bb commit 21eac93
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 19 deletions.
32 changes: 13 additions & 19 deletions core/build_playerglobal/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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");
Expand All @@ -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::<Vec<_>>()
.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);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions core/src/avm2/globals/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
File renamed without changes.

0 comments on commit 21eac93

Please sign in to comment.