Update with current status
[gnash.git] / libcore / builtin_function.h
blobac270b66e19bc2369c153cfb5525df0e516d82f6
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // 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"
24 #include <cassert>
26 namespace gnash {
27 class fn_call;
30 namespace gnash {
33 /// This is a special type of function implementing AS-code in C++
35 /// Many functions (including classes) are implemented in ActionScript in
36 /// the reference player. Gnash implements them in C++, but they must
37 /// be treated like swf-defined functions.
39 /// They are distinct from NativeFunctions, which are part of the player and
40 /// do not go through the ActionScript interpreter.
41 class builtin_function : public UserFunction
43 typedef as_value (*ASFunction)(const fn_call& fn);
45 public:
47 /// Construct a builtin function/class with a default interface
49 /// The default interface will have a constructor member set as 'this'
50 ///
51 /// @param func
52 /// The C function to call when this as_function is invoked.
53 /// For classes, the function pointer is the constructor.
54 builtin_function(Global_as& gl, ASFunction func)
56 UserFunction(gl),
57 _func(func)
61 /// Return the number of registers required for function execution
63 /// Gnash's C++ implementations of AS functions don't need any registers!
64 virtual std::uint8_t registers() const {
65 return 0;
68 /// Invoke this function or this Class constructor
69 virtual as_value call(const fn_call& fn)
71 FrameGuard guard(getVM(fn), *this);
73 assert(_func);
74 return _func(fn);
77 bool isBuiltin() { return true; }
79 private:
81 ASFunction _func;
84 } // end of gnash namespace
86 #endif