Lutok 0.4
Loading...
Searching...
No Matches
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
37#if defined(_LIBCPP_VERSION) || __cplusplus >= 201103L
38#include <memory>
39#else
40#include <tr1/memory>
41#endif
42
43namespace lutok {
44
45
46class debug;
47class state;
48
49
55typedef int (*cxx_function)(state&);
56
57
59extern const int registry_index;
60
61
76class state {
77 struct impl;
78
80#if defined(_LIBCPP_VERSION) || __cplusplus >= 201103L
81 std::shared_ptr< impl > _pimpl;
82#else
83 std::tr1::shared_ptr< impl > _pimpl;
84#endif
85
86 void* new_userdata_voidp(const size_t);
87 void* to_userdata_voidp(const int);
88
89 friend class state_c_gate;
90 explicit state(void*);
91 void* raw_state(void);
92
93public:
94 state(void);
95 ~state(void);
96
97 void close(void);
98 void get_global(const std::string&);
99 void get_global_table(void);
100 bool get_metafield(const int, const std::string&);
101 bool get_metatable(const int);
102 void get_table(const int);
103 int get_top(void);
104 void insert(const int);
105 bool is_boolean(const int);
106 bool is_function(const int);
107 bool is_nil(const int);
108 bool is_number(const int);
109 bool is_string(const int);
110 bool is_table(const int);
111 bool is_userdata(const int);
112 void load_file(const std::string&);
113 void load_string(const std::string&);
114 void new_table(void);
115 template< typename Type > Type* new_userdata(void);
116 bool next(const int);
117 void open_all(void);
118 void open_base(void);
119 void open_string(void);
120 void open_table(void);
121 void pcall(const int, const int, const int);
122 void pop(const int);
123 void push_boolean(const bool);
124 void push_cxx_closure(cxx_function, const int);
125 void push_cxx_function(cxx_function);
126 void push_integer(const int);
127 void push_nil(void);
128 void push_string(const std::string&);
129 void push_value(const int);
130 void raw_get(const int);
131 void raw_set(const int);
132 void set_global(const std::string&);
133 void set_metatable(const int);
134 void set_table(const int);
135 bool to_boolean(const int);
136 long to_integer(const int);
137 template< typename Type > Type* to_userdata(const int);
138 std::string to_string(const int);
139 int upvalue_index(const int);
140};
141
142
143} // namespace lutok
144
145#endif // !defined(LUTOK_STATE_HPP)
const int registry_index
Stack index constant pointing to the registry table.
Definition: state.cpp:215
Gateway to the raw C state of Lua.
Definition: c_gate.hpp:55
Internal implementation for lutok::state.
Definition: state.cpp:219
A RAII model for the Lua state.
Definition: state.hpp:76
void get_global(const std::string &)
Wrapper around lua_getglobal.
Definition: state.cpp:302
bool get_metafield(const int, const std::string &)
Wrapper around luaL_getmetafield.
Definition: state.cpp:341
Type * to_userdata(const int)
Wrapper around lua_touserdata.
Definition: state.ipp:59
void push_cxx_closure(cxx_function, const int)
Wrapper around lua_pushcclosure.
Definition: state.cpp:680
void push_boolean(const bool)
Wrapper around lua_pushboolean.
Definition: state.cpp:666
int upvalue_index(const int)
Wrapper around lua_upvalueindex.
Definition: state.cpp:888
void close(void)
Terminates this Lua session.
Definition: state.cpp:284
bool is_nil(const int)
Wrapper around lua_isnil.
Definition: state.cpp:430
void get_global_table(void)
Pushes a reference to the global table onto the stack.
Definition: state.cpp:318
~state(void)
Destructor for the Lua state.
Definition: state.cpp:268
void * raw_state(void)
Gets the internal lua_State object.
Definition: state.cpp:901
void pcall(const int, const int, const int)
Wrapper around lua_pcall.
Definition: state.cpp:643
bool to_boolean(const int)
Wrapper around lua_toboolean.
Definition: state.cpp:825
void * to_userdata_voidp(const int)
Wrapper around lua_touserdata.
Definition: state.cpp:856
bool is_table(const int)
Wrapper around lua_istable.
Definition: state.cpp:466
void push_value(const int)
Wrapper around lua_pushvalue.
Definition: state.cpp:739
void load_file(const std::string &)
Wrapper around luaL_loadfile.
Definition: state.cpp:493
bool is_boolean(const int)
Wrapper around lua_isboolean.
Definition: state.cpp:406
void new_table(void)
Wrapper around lua_newtable.
Definition: state.cpp:521
void push_integer(const int)
Wrapper around lua_pushinteger.
Definition: state.cpp:709
void * new_userdata_voidp(const size_t)
Wrapper around lua_newuserdata.
Definition: state.cpp:538
void load_string(const std::string &)
Wrapper around luaL_loadstring.
Definition: state.cpp:510
void insert(const int)
Wrapper around lua_insert.
Definition: state.cpp:394
void push_nil(void)
Wrapper around lua_pushnil.
Definition: state.cpp:717
std::tr1::shared_ptr< impl > _pimpl
Pointer to the shared internal implementation.
Definition: state.hpp:83
void open_string(void)
Wrapper around luaopen_string.
Definition: state.cpp:603
void get_table(const int)
Wrapper around lua_gettable.
Definition: state.cpp:368
void open_table(void)
Wrapper around luaopen_table.
Definition: state.cpp:622
void push_string(const std::string &)
Wrapper around lua_pushstring.
Definition: state.cpp:729
void open_all(void)
Wrapper around luaL_openlibs.
Definition: state.cpp:577
void set_metatable(const int)
Wrapper around lua_setmetatable.
Definition: state.cpp:792
std::string to_string(const int)
Wrapper around lua_tostring.
Definition: state.cpp:871
void raw_set(const int)
Wrapper around lua_rawset.
Definition: state.cpp:762
Type * new_userdata(void)
Wrapper around lua_newuserdata.
Definition: state.ipp:46
bool is_function(const int)
Wrapper around lua_isfunction.
Definition: state.cpp:418
bool get_metatable(const int)
Wrapper around lua_getmetatable.
Definition: state.cpp:353
bool next(const int)
Wrapper around lua_next.
Definition: state.cpp:552
void open_base(void)
Wrapper around luaopen_base.
Definition: state.cpp:589
void pop(const int)
Wrapper around lua_pop.
Definition: state.cpp:654
void set_table(const int)
Wrapper around lua_settable.
Definition: state.cpp:807
bool is_number(const int)
Wrapper around lua_isnumber.
Definition: state.cpp:442
void raw_get(const int)
Wrapper around lua_rawget.
Definition: state.cpp:749
long to_integer(const int)
Wrapper around lua_tointeger.
Definition: state.cpp:838
bool is_userdata(const int)
Wrapper around lua_isuserdata.
Definition: state.cpp:478
void push_cxx_function(cxx_function)
Wrapper around lua_pushcfunction.
Definition: state.cpp:696
void set_global(const std::string &)
Wrapper around lua_setglobal.
Definition: state.cpp:777
state(void)
Initializes the Lua state.
Definition: state.cpp:242
bool is_string(const int)
Wrapper around lua_isstring.
Definition: state.cpp:454
int get_top(void)
Wrapper around lua_gettop.
Definition: state.cpp:384