1 // Copyright 2011 Google Inc.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
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.
37 #include "exceptions.hpp"
44 /// Wrapper around lua_getglobal to run in a protected environment.
46 /// \pre stack(-1) is the name of the global to get.
47 /// \post stack(-1) is the value of the global.
49 /// \param state The Lua C API state.
51 /// \return The number of return values pushed onto the stack.
53 protected_getglobal(lua_State* state)
55 lua_getglobal(state, lua_tostring(state, -1));
60 /// Wrapper around lua_gettable to run in a protected environment.
62 /// \pre stack(-2) is the table to get the element from.
63 /// \pre stack(-1) is the table index.
64 /// \post stack(-1) is the value of stack(-2)[stack(-1)].
66 /// \param state The Lua C API state.
68 /// \return The number of return values pushed onto the stack.
70 protected_gettable(lua_State* state)
72 lua_gettable(state, -2);
77 /// Wrapper around lua_next to run in a protected environment.
79 /// \pre stack(-2) is the table to get the next element from.
80 /// \pre stack(-1) is the last processed key.
81 /// \post stack(-1) is the value of next(stack(-2), stack(-1)).
83 /// \param state The Lua C API state.
85 /// \return The number of return values pushed onto the stack.
87 protected_next(lua_State* state)
89 const int more = lua_next(state, -2) != 0;
90 lua_pushboolean(state, more);
95 /// Wrapper around lua_setglobal to run in a protected environment.
97 /// \pre stack(-2) is the name of the global to set.
98 /// \pre stack(-1) is the value to set the global to.
100 /// \param state The Lua C API state.
102 /// \return The number of return values pushed onto the stack.
104 protected_setglobal(lua_State* state)
106 lua_setglobal(state, lua_tostring(state, -2));
111 /// Wrapper around lua_settable to run in a protected environment.
113 /// \pre stack(-3) is the table to set the element into.
114 /// \pre stack(-2) is the table index.
115 /// \pre stack(-1) is the value to set.
117 /// \param state The Lua C API state.
119 /// \return The number of return values pushed onto the stack.
121 protected_settable(lua_State* state)
123 lua_settable(state, -3);
128 /// Calls a C++ Lua function from a C calling environment.
130 /// Any errors reported by the C++ function are caught and reported to the
131 /// caller as Lua errors.
133 /// \param function The C++ function to call.
134 /// \param raw_state The raw Lua state.
136 /// \return The number of return values pushed onto the Lua stack by the
139 call_cxx_function_from_c(lutok::cxx_function function,
140 lua_State* raw_state) throw()
142 char error_buf[1024];
145 lutok::state state = lutok::state_c_gate::connect(raw_state);
146 return function(state);
147 } catch (const std::exception& e) {
148 std::strncpy(error_buf, e.what(), sizeof(error_buf));
150 std::strncpy(error_buf, "Unhandled exception in Lua C++ hook",
153 error_buf[sizeof(error_buf) - 1] = '\0';
154 // We raise the Lua error from outside the try/catch context and we use
155 // a stack-based buffer to hold the message to ensure that we do not leak
156 // any C++ objects (and, as a likely result, memory) when Lua performs its
158 return luaL_error(raw_state, "%s", error_buf);
162 /// Lua glue to call a C++ closure.
164 /// This Lua binding is actually a closure that we have constructed from the
165 /// state.push_cxx_closure() method. The closure contains the same upvalues
166 /// provided by the user plus an extra upvalue that contains the address of the
167 /// C++ function we have to call. All we do here is safely delegate the
168 /// execution to the wrapped C++ closure.
170 /// \param raw_state The Lua C API state.
172 /// \return The number of return values of the called closure.
174 cxx_closure_trampoline(lua_State* raw_state)
176 lutok::state state = lutok::state_c_gate::connect(raw_state);
181 lua_getstack(raw_state, 0, &debug);
182 lua_getinfo(raw_state, "u", &debug);
183 nupvalues = debug.nups;
186 lutok::cxx_function* function = state.to_userdata< lutok::cxx_function >(
187 state.upvalue_index(nupvalues));
188 return call_cxx_function_from_c(*function, raw_state);
192 /// Lua glue to call a C++ function.
194 /// This Lua binding is actually a closure that we have constructed from the
195 /// state.push_cxx_function() method. The closure has a single upvalue that
196 /// contains the address of the C++ function we have to call. All we do here is
197 /// safely delegate the execution to the wrapped C++ function.
199 /// \param raw_state The Lua C API state.
201 /// \return The number of return values of the called function.
203 cxx_function_trampoline(lua_State* raw_state)
205 lutok::state state = lutok::state_c_gate::connect(raw_state);
206 lutok::cxx_function* function = state.to_userdata< lutok::cxx_function >(
207 state.upvalue_index(1));
208 return call_cxx_function_from_c(*function, raw_state);
212 } // anonymous namespace
215 const int lutok::registry_index = LUA_REGISTRYINDEX;
218 /// Internal implementation for lutok::state.
219 struct lutok::state::impl {
220 /// The Lua internal state.
221 lua_State* lua_state;
223 /// Whether we own the state or not (to decide if we close it).
228 /// \param lua_ The Lua internal state.
229 /// \param owned_ Whether we own the state or not.
230 impl(lua_State* lua_, bool owned_) :
238 /// Initializes the Lua state.
240 /// You must share the same state object alongside the lifetime of your Lua
241 /// session. As soon as the object is destroyed, the session is terminated.
242 lutok::state::state(void)
244 lua_State* lua = luaL_newstate();
246 throw lutok::error("lua open failed");
247 _pimpl.reset(new impl(lua, true));
251 /// Initializes the Lua state from an existing raw state.
253 /// Instances constructed using this method do NOT own the raw state. This
254 /// means that, on exit, the state will not be destroyed.
256 /// \param raw_state_ The raw Lua state to wrap.
257 lutok::state::state(void* raw_state_) :
258 _pimpl(new impl(reinterpret_cast< lua_State* >(raw_state_), false))
263 /// Destructor for the Lua state.
265 /// Closes the session unless it has already been closed by calling the
266 /// close() method. It is recommended to explicitly close the session in the
268 lutok::state::~state(void)
270 if (_pimpl->owned && _pimpl->lua_state != NULL)
275 /// Terminates this Lua session.
277 /// It is recommended to call this instead of relying on the destructor to do
278 /// the cleanup, but it is not a requirement to use close().
280 /// \pre close() has not yet been called.
281 /// \pre The Lua stack is empty. This is not truly necessary but ensures that
282 /// our code is consistent and clears the stack explicitly.
284 lutok::state::close(void)
286 assert(_pimpl->lua_state != NULL);
287 assert(lua_gettop(_pimpl->lua_state) == 0);
288 lua_close(_pimpl->lua_state);
289 _pimpl->lua_state = NULL;
293 /// Wrapper around lua_getglobal.
295 /// \param name The second parameter to lua_getglobal.
297 /// \throw api_error If lua_getglobal fails.
299 /// \warning Terminates execution if there is not enough memory to manipulate
302 lutok::state::get_global(const std::string& name)
304 lua_pushcfunction(_pimpl->lua_state, protected_getglobal);
305 lua_pushstring(_pimpl->lua_state, name.c_str());
306 if (lua_pcall(_pimpl->lua_state, 1, 1, 0) != 0)
307 throw lutok::api_error::from_stack(*this, "lua_getglobal");
311 /// Pushes a reference to the global table onto the stack.
313 /// This is a wrapper around the incompatible differences between Lua 5.1 and
314 /// 5.2 to access to the globals table.
316 /// \post state(-1) Contains the reference to the globals table.
318 lutok::state::get_global_table(void)
320 #if LUA_VERSION_NUM >= 502
321 lua_pushvalue(_pimpl->lua_state, registry_index);
322 lua_pushinteger(_pimpl->lua_state, LUA_RIDX_GLOBALS);
323 lua_gettable(_pimpl->lua_state, -2);
324 lua_remove(_pimpl->lua_state, -2);
326 lua_pushvalue(_pimpl->lua_state, LUA_GLOBALSINDEX);
331 /// Wrapper around luaL_getmetafield.
333 /// \param index The second parameter to luaL_getmetafield.
334 /// \param name The third parameter to luaL_getmetafield.
336 /// \return The return value of luaL_getmetafield.
338 /// \warning Terminates execution if there is not enough memory to manipulate
341 lutok::state::get_metafield(const int index, const std::string& name)
343 return luaL_getmetafield(_pimpl->lua_state, index, name.c_str()) != 0;
347 /// Wrapper around lua_getmetatable.
349 /// \param index The second parameter to lua_getmetatable.
351 /// \return The return value of lua_getmetatable.
353 lutok::state::get_metatable(const int index)
355 return lua_getmetatable(_pimpl->lua_state, index) != 0;
359 /// Wrapper around lua_gettable.
361 /// \param index The second parameter to lua_gettable.
363 /// \throw api_error If lua_gettable fails.
365 /// \warning Terminates execution if there is not enough memory to manipulate
368 lutok::state::get_table(const int index)
370 assert(lua_gettop(_pimpl->lua_state) >= 2);
371 lua_pushcfunction(_pimpl->lua_state, protected_gettable);
372 lua_pushvalue(_pimpl->lua_state, index < 0 ? index - 1 : index);
373 lua_pushvalue(_pimpl->lua_state, -3);
374 if (lua_pcall(_pimpl->lua_state, 2, 1, 0) != 0)
375 throw lutok::api_error::from_stack(*this, "lua_gettable");
376 lua_remove(_pimpl->lua_state, -2);
380 /// Wrapper around lua_gettop.
382 /// \return The return value of lua_gettop.
384 lutok::state::get_top(void)
386 return lua_gettop(_pimpl->lua_state);
390 /// Wrapper around lua_insert.
392 /// \param index The second parameter to lua_insert.
394 lutok::state::insert(const int index)
396 lua_insert(_pimpl->lua_state, index);
400 /// Wrapper around lua_isboolean.
402 /// \param index The second parameter to lua_isboolean.
404 /// \return The return value of lua_isboolean.
406 lutok::state::is_boolean(const int index)
408 return lua_isboolean(_pimpl->lua_state, index);
412 /// Wrapper around lua_isfunction.
414 /// \param index The second parameter to lua_isfunction.
416 /// \return The return value of lua_isfunction.
418 lutok::state::is_function(const int index)
420 return lua_isfunction(_pimpl->lua_state, index);
424 /// Wrapper around lua_isnil.
426 /// \param index The second parameter to lua_isnil.
428 /// \return The return value of lua_isnil.
430 lutok::state::is_nil(const int index)
432 return lua_isnil(_pimpl->lua_state, index);
436 /// Wrapper around lua_isnumber.
438 /// \param index The second parameter to lua_isnumber.
440 /// \return The return value of lua_isnumber.
442 lutok::state::is_number(const int index)
444 return lua_isnumber(_pimpl->lua_state, index);
448 /// Wrapper around lua_isstring.
450 /// \param index The second parameter to lua_isstring.
452 /// \return The return value of lua_isstring.
454 lutok::state::is_string(const int index)
456 return lua_isstring(_pimpl->lua_state, index);
460 /// Wrapper around lua_istable.
462 /// \param index The second parameter to lua_istable.
464 /// \return The return value of lua_istable.
466 lutok::state::is_table(const int index)
468 return lua_istable(_pimpl->lua_state, index);
472 /// Wrapper around lua_isuserdata.
474 /// \param index The second parameter to lua_isuserdata.
476 /// \return The return value of lua_isuserdata.
478 lutok::state::is_userdata(const int index)
480 return lua_isuserdata(_pimpl->lua_state, index);
484 /// Wrapper around luaL_loadfile.
486 /// \param file The second parameter to luaL_loadfile.
488 /// \throw api_error If luaL_loadfile returns an error.
489 /// \throw file_not_found_error If the file cannot be accessed.
491 /// \warning Terminates execution if there is not enough memory.
493 lutok::state::load_file(const std::string& file)
495 if (::access(file.c_str(), R_OK) == -1)
496 throw lutok::file_not_found_error(file);
497 if (luaL_loadfile(_pimpl->lua_state, file.c_str()) != 0)
498 throw lutok::api_error::from_stack(*this, "luaL_loadfile");
502 /// Wrapper around luaL_loadstring.
504 /// \param str The second parameter to luaL_loadstring.
506 /// \throw api_error If luaL_loadstring returns an error.
508 /// \warning Terminates execution if there is not enough memory.
510 lutok::state::load_string(const std::string& str)
512 if (luaL_loadstring(_pimpl->lua_state, str.c_str()) != 0)
513 throw lutok::api_error::from_stack(*this, "luaL_loadstring");
517 /// Wrapper around lua_newtable.
519 /// \warning Terminates execution if there is not enough memory.
521 lutok::state::new_table(void)
523 lua_newtable(_pimpl->lua_state);
527 /// Wrapper around lua_newuserdata.
529 /// This is internal. The public type-safe interface of this method should be
532 /// \param size The second parameter to lua_newuserdata.
534 /// \return The return value of lua_newuserdata.
536 /// \warning Terminates execution if there is not enough memory.
538 lutok::state::new_userdata_voidp(const size_t size)
540 return lua_newuserdata(_pimpl->lua_state, size);
544 /// Wrapper around lua_next.
546 /// \param index The second parameter to lua_next.
548 /// \return True if there are more elements to process; false otherwise.
550 /// \warning Terminates execution if there is not enough memory.
552 lutok::state::next(const int index)
554 assert(lua_istable(_pimpl->lua_state, index));
555 assert(lua_gettop(_pimpl->lua_state) >= 1);
556 lua_pushcfunction(_pimpl->lua_state, protected_next);
557 lua_pushvalue(_pimpl->lua_state, index < 0 ? index - 1 : index);
558 lua_pushvalue(_pimpl->lua_state, -3);
559 if (lua_pcall(_pimpl->lua_state, 2, LUA_MULTRET, 0) != 0)
560 throw lutok::api_error::from_stack(*this, "lua_next");
561 const bool more = lua_toboolean(_pimpl->lua_state, -1);
562 lua_pop(_pimpl->lua_state, 1);
564 lua_remove(_pimpl->lua_state, -3);
566 lua_pop(_pimpl->lua_state, 1);
571 /// Wrapper around luaL_openlibs.
573 /// \throw api_error If luaL_openlibs fails.
575 /// \warning Terminates execution if there is not enough memory.
577 lutok::state::open_all(void)
579 luaL_openlibs(_pimpl->lua_state);
583 /// Wrapper around luaopen_base.
585 /// \throw api_error If luaopen_base fails.
587 /// \warning Terminates execution if there is not enough memory.
589 lutok::state::open_base(void)
591 lua_pushcfunction(_pimpl->lua_state, luaopen_base);
592 if (lua_pcall(_pimpl->lua_state, 0, 0, 0) != 0)
593 throw lutok::api_error::from_stack(*this, "luaopen_base");
597 /// Wrapper around luaopen_string.
599 /// \throw api_error If luaopen_string fails.
601 /// \warning Terminates execution if there is not enough memory.
603 lutok::state::open_string(void)
605 #if LUA_VERSION_NUM >= 502
606 luaL_requiref(_pimpl->lua_state, LUA_STRLIBNAME, luaopen_string, 1);
607 lua_pop(_pimpl->lua_state, 1);
609 lua_pushcfunction(_pimpl->lua_state, luaopen_string);
610 if (lua_pcall(_pimpl->lua_state, 0, 0, 0) != 0)
611 throw lutok::api_error::from_stack(*this, "luaopen_string");
616 /// Wrapper around luaopen_table.
618 /// \throw api_error If luaopen_table fails.
620 /// \warning Terminates execution if there is not enough memory.
622 lutok::state::open_table(void)
624 #if LUA_VERSION_NUM >= 502
625 luaL_requiref(_pimpl->lua_state, LUA_TABLIBNAME, luaopen_table, 1);
626 lua_pop(_pimpl->lua_state, 1);
628 lua_pushcfunction(_pimpl->lua_state, luaopen_table);
629 if (lua_pcall(_pimpl->lua_state, 0, 0, 0) != 0)
630 throw lutok::api_error::from_stack(*this, "luaopen_table");
635 /// Wrapper around lua_pcall.
637 /// \param nargs The second parameter to lua_pcall.
638 /// \param nresults The third parameter to lua_pcall.
639 /// \param errfunc The fourth parameter to lua_pcall.
641 /// \throw api_error If lua_pcall returns an error.
643 lutok::state::pcall(const int nargs, const int nresults, const int errfunc)
645 if (lua_pcall(_pimpl->lua_state, nargs, nresults, errfunc) != 0)
646 throw lutok::api_error::from_stack(*this, "lua_pcall");
650 /// Wrapper around lua_pop.
652 /// \param count The second parameter to lua_pop.
654 lutok::state::pop(const int count)
656 assert(count <= lua_gettop(_pimpl->lua_state));
657 lua_pop(_pimpl->lua_state, count);
658 assert(lua_gettop(_pimpl->lua_state) >= 0);
662 /// Wrapper around lua_pushboolean.
664 /// \param value The second parameter to lua_pushboolean.
666 lutok::state::push_boolean(const bool value)
668 lua_pushboolean(_pimpl->lua_state, value ? 1 : 0);
672 /// Wrapper around lua_pushcclosure.
674 /// This is not a pure wrapper around lua_pushcclosure because this has to do
675 /// extra magic to allow passing C++ functions instead of plain C functions.
677 /// \param function The C++ function to be pushed as a closure.
678 /// \param nvalues The number of upvalues that the function receives.
680 lutok::state::push_cxx_closure(cxx_function function, const int nvalues)
682 cxx_function *data = static_cast< cxx_function* >(
683 lua_newuserdata(_pimpl->lua_state, sizeof(cxx_function)));
685 lua_pushcclosure(_pimpl->lua_state, cxx_closure_trampoline, nvalues + 1);
689 /// Wrapper around lua_pushcfunction.
691 /// This is not a pure wrapper around lua_pushcfunction because this has to do
692 /// extra magic to allow passing C++ functions instead of plain C functions.
694 /// \param function The C++ function to be pushed.
696 lutok::state::push_cxx_function(cxx_function function)
698 cxx_function *data = static_cast< cxx_function* >(
699 lua_newuserdata(_pimpl->lua_state, sizeof(cxx_function)));
701 lua_pushcclosure(_pimpl->lua_state, cxx_function_trampoline, 1);
705 /// Wrapper around lua_pushinteger.
707 /// \param value The second parameter to lua_pushinteger.
709 lutok::state::push_integer(const int value)
711 lua_pushinteger(_pimpl->lua_state, value);
715 /// Wrapper around lua_pushnil.
717 lutok::state::push_nil(void)
719 lua_pushnil(_pimpl->lua_state);
723 /// Wrapper around lua_pushstring.
725 /// \param str The second parameter to lua_pushstring.
727 /// \warning Terminates execution if there is not enough memory.
729 lutok::state::push_string(const std::string& str)
731 lua_pushstring(_pimpl->lua_state, str.c_str());
735 /// Wrapper around lua_pushvalue.
737 /// \param index The second parameter to lua_pushvalue.
739 lutok::state::push_value(const int index)
741 lua_pushvalue(_pimpl->lua_state, index);
745 /// Wrapper around lua_rawget.
747 /// \param index The second parameter to lua_rawget.
749 lutok::state::raw_get(const int index)
751 lua_rawget(_pimpl->lua_state, index);
755 /// Wrapper around lua_rawset.
757 /// \param index The second parameter to lua_rawset.
759 /// \warning Terminates execution if there is not enough memory to manipulate
762 lutok::state::raw_set(const int index)
764 lua_rawset(_pimpl->lua_state, index);
768 /// Wrapper around lua_setglobal.
770 /// \param name The second parameter to lua_setglobal.
772 /// \throw api_error If lua_setglobal fails.
774 /// \warning Terminates execution if there is not enough memory to manipulate
777 lutok::state::set_global(const std::string& name)
779 lua_pushcfunction(_pimpl->lua_state, protected_setglobal);
780 lua_pushstring(_pimpl->lua_state, name.c_str());
781 lua_pushvalue(_pimpl->lua_state, -3);
782 if (lua_pcall(_pimpl->lua_state, 2, 0, 0) != 0)
783 throw lutok::api_error::from_stack(*this, "lua_setglobal");
784 lua_pop(_pimpl->lua_state, 1);
788 /// Wrapper around lua_setmetatable.
790 /// \param index The second parameter to lua_setmetatable.
792 lutok::state::set_metatable(const int index)
794 lua_setmetatable(_pimpl->lua_state, index);
798 /// Wrapper around lua_settable.
800 /// \param index The second parameter to lua_settable.
802 /// \throw api_error If lua_settable fails.
804 /// \warning Terminates execution if there is not enough memory to manipulate
807 lutok::state::set_table(const int index)
809 lua_pushcfunction(_pimpl->lua_state, protected_settable);
810 lua_pushvalue(_pimpl->lua_state, index < 0 ? index - 1 : index);
811 lua_pushvalue(_pimpl->lua_state, -4);
812 lua_pushvalue(_pimpl->lua_state, -4);
813 if (lua_pcall(_pimpl->lua_state, 3, 0, 0) != 0)
814 throw lutok::api_error::from_stack(*this, "lua_settable");
815 lua_pop(_pimpl->lua_state, 2);
819 /// Wrapper around lua_toboolean.
821 /// \param index The second parameter to lua_toboolean.
823 /// \return The return value of lua_toboolean.
825 lutok::state::to_boolean(const int index)
827 assert(is_boolean(index));
828 return lua_toboolean(_pimpl->lua_state, index);
832 /// Wrapper around lua_tointeger.
834 /// \param index The second parameter to lua_tointeger.
836 /// \return The return value of lua_tointeger.
838 lutok::state::to_integer(const int index)
840 assert(is_number(index));
841 return lua_tointeger(_pimpl->lua_state, index);
845 /// Wrapper around lua_touserdata.
847 /// This is internal. The public type-safe interface of this method should be
850 /// \param index The second parameter to lua_touserdata.
852 /// \return The return value of lua_touserdata.
854 /// \warning Terminates execution if there is not enough memory.
856 lutok::state::to_userdata_voidp(const int index)
858 return lua_touserdata(_pimpl->lua_state, index);
863 /// Wrapper around lua_tostring.
865 /// \param index The second parameter to lua_tostring.
867 /// \return The return value of lua_tostring.
869 /// \warning Terminates execution if there is not enough memory.
871 lutok::state::to_string(const int index)
873 assert(is_string(index));
874 const char *raw_string = lua_tostring(_pimpl->lua_state, index);
875 // Note that the creation of a string object below (explicit for clarity)
876 // implies that the raw string is duplicated and, henceforth, the string is
877 // safe even if the corresponding element is popped from the Lua stack.
878 return std::string(raw_string);
882 /// Wrapper around lua_upvalueindex.
884 /// \param index The first parameter to lua_upvalueindex.
886 /// \return The return value of lua_upvalueindex.
888 lutok::state::upvalue_index(const int index)
890 return lua_upvalueindex(index);
894 /// Gets the internal lua_State object.
896 /// \return The raw Lua state. This is returned as a void pointer to prevent
897 /// including the lua.hpp header file from our public interface. The only way
898 /// to call this method is by using the c_gate module, and c_gate takes care of
899 /// casting this object to the appropriate type.
901 lutok::state::raw_state(void)
903 return _pimpl->lua_state;