Remove building with NOCRYPTO option
[minix3.git] / external / bsd / lutok / dist / debug.cpp
blobe0a0b5eb21136421944955e9d0dc485b3bf19426
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.
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.
29 #include <cassert>
31 #include <lua.hpp>
33 #include <lutok/c_gate.hpp>
34 #include <lutok/debug.hpp>
35 #include <lutok/exceptions.hpp>
36 #include <lutok/state.ipp>
39 /// Internal implementation for lutok::debug.
40 struct lutok::debug::impl {
41 /// The Lua internal debug state.
42 lua_Debug lua_debug;
46 /// Constructor for an empty debug structure.
47 lutok::debug::debug(void) :
48 _pimpl(new impl())
53 /// Destructor.
54 lutok::debug::~debug(void)
59 /// Wrapper around lua_getinfo.
60 ///
61 /// \param s The Lua state.
62 /// \param what_ The second parameter to lua_getinfo.
63 ///
64 /// \warning Terminates execution if there is not enough memory to manipulate
65 /// the Lua stack.
66 void
67 lutok::debug::get_info(state& s, const std::string& what_)
69 lua_State* raw_state = state_c_gate(s).c_state();
71 if (lua_getinfo(raw_state, what_.c_str(), &_pimpl->lua_debug) == 0)
72 throw lutok::api_error::from_stack(s, "lua_getinfo");
76 /// Wrapper around lua_getstack.
77 ///
78 /// \param s The Lua state.
79 /// \param level The second parameter to lua_getstack.
80 void
81 lutok::debug::get_stack(state& s, const int level)
83 lua_State* raw_state = state_c_gate(s).c_state();
85 lua_getstack(raw_state, level, &_pimpl->lua_debug);
89 /// Accessor for the 'event' field of lua_Debug.
90 ///
91 /// \return Returns the 'event' field of the internal lua_Debug structure.
92 int
93 lutok::debug::event(void) const
95 return _pimpl->lua_debug.event;
99 /// Accessor for the 'name' field of lua_Debug.
101 /// \return Returns the 'name' field of the internal lua_Debug structure.
102 std::string
103 lutok::debug::name(void) const
105 assert(_pimpl->lua_debug.name != NULL);
106 return _pimpl->lua_debug.name;
110 /// Accessor for the 'namewhat' field of lua_Debug.
112 /// \return Returns the 'namewhat' field of the internal lua_Debug structure.
113 std::string
114 lutok::debug::name_what(void) const
116 assert(_pimpl->lua_debug.namewhat != NULL);
117 return _pimpl->lua_debug.namewhat;
121 /// Accessor for the 'what' field of lua_Debug.
123 /// \return Returns the 'what' field of the internal lua_Debug structure.
124 std::string
125 lutok::debug::what(void) const
127 assert(_pimpl->lua_debug.what != NULL);
128 return _pimpl->lua_debug.what;
132 /// Accessor for the 'source' field of lua_Debug.
134 /// \return Returns the 'source' field of the internal lua_Debug structure.
135 std::string
136 lutok::debug::source(void) const
138 assert(_pimpl->lua_debug.source != NULL);
139 return _pimpl->lua_debug.source;
143 /// Accessor for the 'currentline' field of lua_Debug.
145 /// \return Returns the 'currentline' field of the internal lua_Debug structure.
147 lutok::debug::current_line(void) const
149 return _pimpl->lua_debug.currentline;
153 /// Accessor for the 'nups' field of lua_Debug.
155 /// \return Returns the 'nups' field of the internal lua_Debug structure.
157 lutok::debug::n_ups(void) const
159 return _pimpl->lua_debug.nups;
163 /// Accessor for the 'linedefined' field of lua_Debug.
165 /// \return Returns the 'linedefined' field of the internal lua_Debug structure.
167 lutok::debug::line_defined(void) const
169 return _pimpl->lua_debug.linedefined;
173 /// Accessor for the 'lastlinedefined' field of lua_Debug.
175 /// \return Returns the 'lastlinedefined' field of the internal lua_Debug
176 /// structure.
178 lutok::debug::last_line_defined(void) const
180 return _pimpl->lua_debug.lastlinedefined;
184 /// Accessor for the 'short_src' field of lua_Debug.
186 /// \return Returns the 'short_src' field of the internal lua_Debug structure.
187 std::string
188 lutok::debug::short_src(void) const
190 assert(_pimpl->lua_debug.short_src != NULL);
191 return _pimpl->lua_debug.short_src;