Lutok  0.3
 All Classes Namespaces Files Functions Variables Macros
state.hpp
Go to the documentation of this file.
1 // Copyright 2011 Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Google Inc. nor the names of its contributors
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
31 
32 #if !defined(LUTOK_STATE_HPP)
33 #define LUTOK_STATE_HPP
34 
35 #include <string>
36 #include <tr1/memory>
37 
38 namespace lutok {
39 
40 
41 class debug;
42 class state;
43 
44 
50 typedef int (*cxx_function)(state&);
51 
52 
54 extern const int registry_index;
55 
56 
71 class state {
72  struct impl;
73 
75  std::tr1::shared_ptr< impl > _pimpl;
76 
77  void* new_userdata_voidp(const size_t);
78  void* to_userdata_voidp(const int);
79 
80  friend class state_c_gate;
81  explicit state(void*);
82  void* raw_state(void);
83 
84 public:
85  state(void);
86  ~state(void);
87 
88  void close(void);
89  void get_global(const std::string&);
90  void get_global_table(void);
91  bool get_metafield(const int, const std::string&);
92  bool get_metatable(const int = -1);
93  void get_table(const int = -2);
94  int get_top(void);
95  void insert(const int);
96  bool is_boolean(const int = -1);
97  bool is_function(const int = -1);
98  bool is_nil(const int = -1);
99  bool is_number(const int = -1);
100  bool is_string(const int = -1);
101  bool is_table(const int = -1);
102  bool is_userdata(const int = -1);
103  void load_file(const std::string&);
104  void load_string(const std::string&);
105  void new_table(void);
106  template< typename Type > Type* new_userdata(void);
107  bool next(const int = -2);
108  void open_base(void);
109  void open_string(void);
110  void open_table(void);
111  void pcall(const int, const int, const int);
112  void pop(const int);
113  void push_boolean(const bool);
114  void push_cxx_closure(cxx_function, const int);
115  void push_cxx_function(cxx_function);
116  void push_integer(const int);
117  void push_nil(void);
118  void push_string(const std::string&);
119  void push_value(const int = -1);
120  void raw_get(const int = -2);
121  void raw_set(const int = -3);
122  void set_global(const std::string&);
123  void set_metatable(const int = -2);
124  void set_table(const int = -3);
125  bool to_boolean(const int = -1);
126  long to_integer(const int = -1);
127  template< typename Type > Type* to_userdata(const int = -1);
128  std::string to_string(const int = -1);
129  int upvalue_index(const int);
130 };
131 
132 
133 } // namespace lutok
134 
135 #endif // !defined(LUTOK_STATE_HPP)