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:
parent
4e805bb109
commit
21eac9364f
|
@ -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::<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);
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue