big merge from master, fix rpm creation, drop fetching swfdec
[gnash.git] / libcore / builtin_function.h
blob1e62cf917be4511397601a0f6a17f214ed8b672c
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3 // 2011 Free Software Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef GNASH_BUILTIN_FUNCTION_H
20 #define GNASH_BUILTIN_FUNCTION_H
22 #include "UserFunction.h"
23 #include "as_environment.h"
24 #include "fn_call.h"
26 #include <cassert>
28 namespace gnash {
31 /// This is a special type of function implementing AS-code in C++
33 /// Many functions (including classes) are implemented in ActionScript in
34 /// the reference player. Gnash implements them in C++, but they must
35 /// be treated like swf-defined functions.
37 /// They are distinct from NativeFunctions, which are part of the player and
38 /// do not go through the ActionScript interpreter.
39 class builtin_function : public UserFunction
41 typedef as_value (*ASFunction)(const fn_call& fn);
43 public:
45 /// Construct a builtin function/class with a default interface
47 /// The default interface will have a constructor member set as 'this'
48 ///
49 /// @param func
50 /// The C function to call when this as_function is invoked.
51 /// For classes, the function pointer is the constructor.
52 builtin_function(Global_as& gl, ASFunction func)
54 UserFunction(gl),
55 _func(func)
59 /// Return the number of registers required for function execution
61 /// Gnash's C++ implementations of AS functions don't need any registers!
62 virtual boost::uint8_t registers() const {
63 return 0;
66 /// Invoke this function or this Class constructor
67 virtual as_value call(const fn_call& fn)
69 FrameGuard guard(getVM(fn), *this);
71 assert(_func);
72 return _func(fn);
75 bool isBuiltin() { return true; }
77 private:
79 ASFunction _func;
82 } // end of gnash namespace
84 #endif