Lutok  0.1
state.hpp
Go to the documentation of this file.
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 
00067 class state {
00068     struct impl;
00069 
00071     std::tr1::shared_ptr< impl > _pimpl;
00072 
00073     void* new_userdata_voidp(const size_t);
00074     void* to_userdata_voidp(const int);
00075 
00076     friend class state_c_gate;
00077     explicit state(void*);
00078     void* raw_state(void);
00079 
00080 public:
00081     state(void);
00082     ~state(void);
00083 
00084     void close(void);
00085     void get_global(const std::string&);
00086     void get_table(const int = -2);
00087     int get_top(void);
00088     bool is_boolean(const int = -1);
00089     bool is_function(const int = -1);
00090     bool is_nil(const int = -1);
00091     bool is_number(const int = -1);
00092     bool is_string(const int = -1);
00093     bool is_table(const int = -1);
00094     bool is_userdata(const int = -1);
00095     void load_file(const std::string&);
00096     void load_string(const std::string&);
00097     void new_table(void);
00098     template< typename Type > Type* new_userdata(void);
00099     bool next(const int = -2);
00100     void open_base(void);
00101     void open_string(void);
00102     void open_table(void);
00103     void pcall(const int, const int, const int);
00104     void pop(const int);
00105     void push_boolean(const bool);
00106     void push_cxx_closure(cxx_function, const int);
00107     void push_cxx_function(cxx_function);
00108     void push_integer(const int);
00109     void push_nil(void);
00110     void push_string(const std::string&);
00111     void set_global(const std::string&);
00112     void set_metatable(const int = -2);
00113     void set_table(const int = -3);
00114     bool to_boolean(const int = -1);
00115     long to_integer(const int = -1);
00116     template< typename Type > Type* to_userdata(const int = -1);
00117     std::string to_string(const int = -1);
00118     int upvalue_index(const int);
00119 };
00120 
00121 
00122 }  // namespace lutok
00123 
00124 #endif  // !defined(LUTOK_STATE_HPP)
 All Classes Namespaces Files Functions Variables Defines