Lutok
0.2
|
00001 // Copyright 2011 Google Inc. 00002 // All rights reserved. 00003 // 00004 // Redistribution and use in source and binary forms, with or without 00005 // modification, are permitted provided that the following conditions are 00006 // met: 00007 // 00008 // * Redistributions of source code must retain the above copyright 00009 // notice, this list of conditions and the following disclaimer. 00010 // * Redistributions in binary form must reproduce the above copyright 00011 // notice, this list of conditions and the following disclaimer in the 00012 // documentation and/or other materials provided with the distribution. 00013 // * Neither the name of Google Inc. nor the names of its contributors 00014 // may be used to endorse or promote products derived from this software 00015 // without specific prior written permission. 00016 // 00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00018 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00019 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00020 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00021 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00022 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00023 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00024 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00025 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00026 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00027 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00028 00031 00032 #if !defined(LUTOK_STATE_HPP) 00033 #define LUTOK_STATE_HPP 00034 00035 #include <string> 00036 #include <tr1/memory> 00037 00038 namespace lutok { 00039 00040 00041 class debug; 00042 class state; 00043 00044 00050 typedef int (*cxx_function)(state&); 00051 00052 00054 extern const int globals_index; 00055 00056 00071 class state { 00072 struct impl; 00073 00075 std::tr1::shared_ptr< impl > _pimpl; 00076 00077 void* new_userdata_voidp(const size_t); 00078 void* to_userdata_voidp(const int); 00079 00080 friend class state_c_gate; 00081 explicit state(void*); 00082 void* raw_state(void); 00083 00084 public: 00085 state(void); 00086 ~state(void); 00087 00088 void close(void); 00089 void get_global(const std::string&); 00090 bool get_metafield(const int, const std::string&); 00091 bool get_metatable(const int = -1); 00092 void get_table(const int = -2); 00093 int get_top(void); 00094 void insert(const int); 00095 bool is_boolean(const int = -1); 00096 bool is_function(const int = -1); 00097 bool is_nil(const int = -1); 00098 bool is_number(const int = -1); 00099 bool is_string(const int = -1); 00100 bool is_table(const int = -1); 00101 bool is_userdata(const int = -1); 00102 void load_file(const std::string&); 00103 void load_string(const std::string&); 00104 void new_table(void); 00105 template< typename Type > Type* new_userdata(void); 00106 bool next(const int = -2); 00107 void open_base(void); 00108 void open_string(void); 00109 void open_table(void); 00110 void pcall(const int, const int, const int); 00111 void pop(const int); 00112 void push_boolean(const bool); 00113 void push_cxx_closure(cxx_function, const int); 00114 void push_cxx_function(cxx_function); 00115 void push_integer(const int); 00116 void push_nil(void); 00117 void push_string(const std::string&); 00118 void push_value(const int = -1); 00119 void raw_get(const int = -2); 00120 void raw_set(const int = -3); 00121 void set_global(const std::string&); 00122 void set_metatable(const int = -2); 00123 void set_table(const int = -3); 00124 bool to_boolean(const int = -1); 00125 long to_integer(const int = -1); 00126 template< typename Type > Type* to_userdata(const int = -1); 00127 std::string to_string(const int = -1); 00128 int upvalue_index(const int); 00129 }; 00130 00131 00132 } // namespace lutok 00133 00134 #endif // !defined(LUTOK_STATE_HPP)