Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GNASH_AS_ENVIRONMENT_H
00020 #define GNASH_AS_ENVIRONMENT_H
00021
00022 #include "smart_ptr.h"
00023 #include "as_value.h"
00024 #include "SafeStack.h"
00025
00026 #include <string>
00027 #include <vector>
00028
00029 namespace gnash {
00030
00031
00032 class DisplayObject;
00033 class VM;
00034 class Global_as;
00035 class movie_root;
00036 class string_table;
00037 class UserFunction;
00038
00040 class as_environment
00041 {
00042
00043 public:
00044
00046 typedef std::vector<as_object*> ScopeStack;
00047
00048 as_environment(VM& vm);
00049
00050 VM& getVM() const { return _vm; }
00051
00052 DisplayObject* get_target() const { return m_target; }
00053
00055
00061 void set_target(DisplayObject* target);
00062
00063 void set_original_target(DisplayObject* target) {
00064 _original_target = target;
00065 }
00066
00067 DisplayObject* get_original_target() { return _original_target; }
00068
00069
00070 void reset_target() { m_target = _original_target; }
00071
00073 void push(const as_value& val) {
00074 _stack.push(val);
00075 }
00076
00078 as_value pop()
00079 {
00080 try {
00081 return _stack.pop();
00082 } catch (StackException&) {
00083 return undefVal;
00084 }
00085 }
00086
00088
00093 as_value& top(size_t dist)
00094 {
00095 try {
00096 return _stack.top(dist);
00097 } catch (StackException&) {
00098 return undefVal;
00099 }
00100 }
00101
00103
00108 as_value& bottom(size_t index) const
00109 {
00110 try {
00111 return _stack.value(index);
00112 } catch (StackException&) {
00113 return undefVal;
00114 }
00115 }
00116
00118 void drop(size_t count)
00119 {
00120
00121
00122 _stack.drop(std::min(count, _stack.size()));
00123 }
00124
00125 size_t stack_size() const { return _stack.size(); }
00126
00130
00141 bool delVariableRaw(const std::string& varname,
00142 const ScopeStack& scopeStack);
00143
00145
00161 as_value get_variable(const std::string& varname,
00162 const ScopeStack& scopeStack, as_object** retTarget=NULL) const;
00163
00166
00182 void set_variable(const std::string& path, const as_value& val,
00183 const ScopeStack& scopeStack);
00184
00185 #ifdef GNASH_USE_GC
00186
00187
00192 void markReachableResources() const;
00193 #endif
00194
00196
00200 DisplayObject* find_target(const std::string& path) const;
00201
00203
00207 as_object* find_object(const std::string& path,
00208 const ScopeStack* scopeStack = 0) const;
00209
00211
00216 int get_version() const;
00217
00218 private:
00219
00220 VM& _vm;
00221
00223 SafeStack<as_value>& _stack;
00224
00226 DisplayObject* m_target;
00227
00229 DisplayObject* _original_target;
00230
00232
00242 void set_variable_raw(const std::string& path, const as_value& val,
00243 const ScopeStack& scopeStack);
00244
00251 as_value get_variable_raw(const std::string& varname,
00252 const ScopeStack& scopeStack, as_object** retTarget=NULL) const;
00253
00254 static as_value undefVal;
00255
00256 };
00257
00277 bool parsePath(const std::string& var_path, std::string& path,
00278 std::string& var);
00279
00280 inline VM&
00281 getVM(const as_environment& env)
00282 {
00283 return env.getVM();
00284 }
00285
00286 movie_root& getRoot(const as_environment& env);
00287 string_table& getStringTable(const as_environment& env);
00288 int getSWFVersion(const as_environment& env);
00289 Global_as& getGlobal(const as_environment &env);
00290
00291 }
00292
00293
00294 #endif // GNASH_AS_ENVIRONMENT_H
00295
00296
00297
00298
00299
00300