#include <libsswf.h>
Public Types | |
enum | action_function_t { ACTION_FUNCTION_LOAD_THIS = 0x0001, ACTION_FUNCTION_SUPPRESS_THIS = 0x0002, ACTION_FUNCTION_LOAD_ARGUMENTS = 0x0004, ACTION_FUNCTION_SUPPRESS_ARGUMENTS = 0x0008, ACTION_FUNCTION_LOAD_SUPER = 0x0010, ACTION_FUNCTION_SUPPRESS_SUPER = 0x0020, ACTION_FUNCTION_LOAD_ROOT = 0x0040, ACTION_FUNCTION_LOAD_PARENT = 0x0080, ACTION_FUNCTION_LOAD_GLOBAL = 0x0100 } |
List the flags supported by the DeclareFunction2 tag. More... | |
enum | as_set_prop_flags_t { PROP_FLAG_IS_HIDDEN = 1, PROP_FLAG_CAN_DELETE = 2, PROP_FLAG_CAN_OVERWRITE = 4 } |
List of flags available to call the ASSetPropFlags() function. More... | |
Public Member Functions | |
ActionFunction (TagBase *tag, action_t action=ACTION_DECLARE_FUNCTION) | |
Initializes ActionFunction objects. | |
void | AddAction (Action *action) |
Add an action in the function. | |
void | AddParameter (const char *name, int register_number=-1) |
Add a function parameter. | |
void | SetName (const char *name) |
Define the name of the function. | |
void | SetRegistersCount (unsigned int count) |
Set the maximum number of registers to use with this function. | |
virtual Vectors * | SubList (void) |
Get a pointer to the Vectors of sub-actions. | |
Private Member Functions | |
virtual Action * | Duplicate (void) const |
Duplicate the function action. | |
virtual ErrorManager::error_code_t | ParseData (const Data &data) |
Parse the function definitions and then the nested actions. | |
virtual ErrorManager::error_code_t | SaveData (Data &data, Data &nested_data) |
Save the function header and nested data. | |
Private Attributes | |
Vectors | f_actions |
unsigned short | f_flags |
char * | f_name |
Vectors | f_parameters |
unsigned int | f_registers_count |
Classes | |
struct | parameter_t |
Hold the parameters name and register number. More... |
These flags can be used to very much optimize ActionScripts.
Each special variable and arguments to functions can be saved in registers for fast retrieval.
ACTION_FUNCTION_LOAD_THIS |
Make 'this' variable ready.
The ACTION_FUNCTION_LOAD_THIS loads a register with the value of 'this'. The register depends on what is loaded before.
|
ACTION_FUNCTION_SUPPRESS_THIS |
Don't create the 'this' variable.
The ACTION_FUNCTION_SUPPRESS_THIS can be used so 'this' variable is not even created. This can speed things up.
|
ACTION_FUNCTION_LOAD_ARGUMENTS |
Load arguments in registers.
The ACTION_FUNCTION_LOAD_ARGUMENTS loads a register with the value of each of the arguments specified when calling this function. The registers depend on what is loaded before.
|
ACTION_FUNCTION_SUPPRESS_ARGUMENTS |
Ignore all arguments.
The ACTION_FUNCTION_SUPPRESS_ARGUMENTS ensures that the ActionScript interpreter does not spend any time saving the arguments. This useful for virtual functions support.
|
ACTION_FUNCTION_LOAD_SUPER |
Make the 'super' variable ready.
The ACTION_FUNCTION_LOAD_SUPER loads a register with the value of 'super'. The register depends on what is loaded before.
|
ACTION_FUNCTION_SUPPRESS_SUPER |
Don't bother creating the 'super' variable.
The ACTION_FUNCTION_SUPPRESS_SUPER asks the ActionScript interpreter to not bother creating the super variable. This can speed things up.
|
ACTION_FUNCTION_LOAD_ROOT |
Make the 'root' variable ready.
The ACTION_FUNCTION_LOAD_ROOT loads a register with the value of 'root'. The register depends on what is loaded before.
|
ACTION_FUNCTION_LOAD_PARENT |
Make the 'parent' variable ready.
The ACTION_FUNCTION_LOAD_PARENT loads a register with the value of 'parent'. The register depends on what is loaded before.
|
ACTION_FUNCTION_LOAD_GLOBAL |
Make the 'global' variable ready.
The ACTION_FUNCTION_LOAD_THIS loads a register with the value of 'global'. The register depends on what is loaded before.
|
This undocumented function is used to change the properties of an object variable member or function member. The properties are defined by three flags:
This function is used to initialize ActionFunction objects.
In debug mode it will test that the action is valid. It has to be set to either:
ACTION_DECLARE_FUNCTION or ACTION_DECLARE_FUNCTION2
The former can be used for movies version 5 or 6, the latter for movies version 7 or more.
[in] | tag | The tag holding this action |
[in] | action | The type of function to create |
References sswf::Action::ACTION_DECLARE_FUNCTION, sswf::Action::ACTION_DECLARE_FUNCTION2, sswf::assert(), f_flags, f_name, and f_registers_count.
Referenced by Duplicate().
void ActionFunction::AddAction | ( | Action * | action | ) |
Most functions include a set of actions to be executed when called. These actions are added using this functions. It is also possible to get a pointer to the sub-actions Vectors and directly add the actions in the Vectors object.
These actions are seen as the function block.
[in] | action | The action to add to this function |
References f_actions, and sswf::Vectors::Set().
Referenced by Duplicate().
void ActionFunction::AddParameter | ( | const char * | name, | |
int | register_number = -1 | |||
) |
This function adds a parameter to the ActionFunction.
The name is mandatory for an ACTION_DECLARE_FUNCTION and optional for an ACTION_DECLARE_FUNCTION2. There are some special parameter names for an ACTION_DECLARE_FUNCTION2 to create or not system registers. The special names are as follow:
According to my testings, the register 255 cannot be used. So you are limited to a register number from 1 to 254. However, don't forget that system parameters must use the first few registers! If the register number you specify is larger than the one defined by the sswf::ActionFunction::SetRegistersCount(unsigned int count) then the count is increased as required.
[in] | name | The name of the parameter |
[in] | register_number | The assigned register for that parameter |
References sswf::Action::ACTION_DECLARE_FUNCTION2, ACTION_FUNCTION_LOAD_ARGUMENTS, ACTION_FUNCTION_LOAD_GLOBAL, ACTION_FUNCTION_LOAD_PARENT, ACTION_FUNCTION_LOAD_ROOT, ACTION_FUNCTION_LOAD_SUPER, ACTION_FUNCTION_LOAD_THIS, ACTION_FUNCTION_SUPPRESS_ARGUMENTS, ACTION_FUNCTION_SUPPRESS_SUPER, ACTION_FUNCTION_SUPPRESS_THIS, sswf::assert(), sswf::Action::f_action, f_flags, sswf::ActionFunction::parameter_t::f_name, f_parameters, sswf::ActionFunction::parameter_t::f_register_number, f_registers_count, sswf::MemoryManager::MemAttach(), sswf::Vectors::Set(), and sswf::MemoryManager::StrDup().
Referenced by Duplicate(), and ParseData().
Action * ActionFunction::Duplicate | ( | void | ) | const [private, virtual] |
This function duplicates a function. This includes all the parameters and actions as well as the name and number of registers used in the list of parameters.
Reimplemented from sswf::Action.
References ActionFunction(), AddAction(), AddParameter(), sswf::Vectors::Count(), sswf::Action::Duplicate(), sswf::Action::f_action, f_actions, f_flags, sswf::ActionFunction::parameter_t::f_name, f_name, f_parameters, sswf::ActionFunction::parameter_t::f_register_number, f_registers_count, sswf::Vectors::Get(), SetName(), SetRegistersCount(), and sswf::Action::Tag().
ErrorManager::error_code_t ActionFunction::ParseData | ( | const Data & | data | ) | [private, virtual] |
This function parses the Function Action definitions (what registers are used) and then all the nested actions.
[in] | data | The source Data buffer |
Reimplemented from sswf::Action.
References sswf::Action::ACTION_DECLARE_FUNCTION2, AddParameter(), sswf::ErrorManager::ERROR_CODE_NONE, sswf::Action::f_action, f_actions, f_flags, f_name, f_registers_count, sswf::Data::GetByte(), sswf::Data::GetShort(), sswf::Data::GetString(), sswf::MemoryManager::MemClean(), sswf::Action::ParseList(), and sswf::Action::Tag().
ErrorManager::error_code_t ActionFunction::SaveData | ( | Data & | data, | |
Data & | nested_data | |||
) | [private, virtual] |
This function creates the function header which includes its name, all the parameters, whether to create or suppress system registers and the size of the function block.
Note that the function block cannot be larger than about 64Kb.
[in] | data | The Data buffer where the function is saved |
[in] | nested_data | The Data buffer holding the function block |
Reimplemented from sswf::Action.
References sswf::Action::ACTION_DECLARE_FUNCTION2, ACTION_FUNCTION_LOAD_GLOBAL, ACTION_FUNCTION_LOAD_PARENT, ACTION_FUNCTION_LOAD_ROOT, ACTION_FUNCTION_LOAD_SUPER, ACTION_FUNCTION_LOAD_THIS, sswf::Data::ByteSize(), sswf::Vectors::Count(), sswf::ErrorManager::ERROR_CODE_REGISTER_OVERFLOW, sswf::Action::f_action, f_flags, sswf::ActionFunction::parameter_t::f_name, f_name, f_parameters, sswf::ActionFunction::parameter_t::f_register_number, f_registers_count, sswf::Vectors::Get(), sswf::Action::GetMaxRegister(), sswf::ErrorManager::KeepFirst(), sswf::Action::OnError(), sswf::Data::PutByte(), sswf::Data::PutShort(), and sswf::Action::SaveString().
void ActionFunction::SetName | ( | const char * | name | ) |
This function saves the specified name as the name of the function.
This is the name you need to use to call the function later.
Note that an object function member has no name.
[in] | name | The new function name |
References f_name, sswf::MemoryManager::MemFree(), and sswf::MemoryManager::StrDup().
Referenced by Duplicate().
void ActionFunction::SetRegistersCount | ( | unsigned int | count | ) |
With an ACTION_DECLARE_FUNCTION2, you can use as many as 255 registers in your function, otherwise you are limited to 4 as before version 7. Also, before version 7, the parameters cannot automatically be assigned to registers and thus this function is not necessary.
[in] | count | The number of registers you want to use |
References f_registers_count.
Referenced by Duplicate().
Vectors * ActionFunction::SubList | ( | void | ) | [virtual] |
This function can be used to retrieve a pointer to the sub-actions Vectors object. This can be used to add actions to the function in a way similar to the main block.
Reimplemented from sswf::Action.
References f_actions.
Vectors sswf::ActionFunction::f_actions [private] |
Referenced by AddAction(), Duplicate(), ParseData(), and SubList().
unsigned short sswf::ActionFunction::f_flags [private] |
Referenced by ActionFunction(), AddParameter(), Duplicate(), ParseData(), and SaveData().
char* sswf::ActionFunction::f_name [private] |
Referenced by ActionFunction(), Duplicate(), ParseData(), SaveData(), and SetName().
Vectors sswf::ActionFunction::f_parameters [private] |
Referenced by AddParameter(), Duplicate(), and SaveData().
unsigned int sswf::ActionFunction::f_registers_count [private] |
Referenced by ActionFunction(), AddParameter(), Duplicate(), ParseData(), SaveData(), and SetRegistersCount().