Lines Matching +full:in +full:- +full:and +full:- +full:around
4 // Redistribution and use in source and binary forms, with or without
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.
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
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
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.
55 lua_getglobal(state, lua_tostring(state, -1)); in protected_getglobal()
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)].
72 lua_gettable(state, -2); in protected_gettable()
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)).
89 const int more = lua_next(state, -2) != 0; in protected_next()
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.
106 lua_setglobal(state, lua_tostring(state, -2)); in protected_setglobal()
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.
123 lua_settable(state, -3); in protected_settable()
130 /// Any errors reported by the C++ function are caught and reported to the
150 std::strncpy(error_buf, "Unhandled exception in Lua C++ hook", in call_cxx_function_from_c()
153 error_buf[sizeof(error_buf) - 1] = '\0'; in call_cxx_function_from_c()
154 // We raise the Lua error from outside the try/catch context and we use in call_cxx_function_from_c()
155 // a stack-based buffer to hold the message to ensure that we do not leak in call_cxx_function_from_c()
156 // any C++ objects (and, as a likely result, memory) when Lua performs its in call_cxx_function_from_c()
266 /// close() method. It is recommended to explicitly close the session in the
270 if (_pimpl->owned && _pimpl->lua_state != NULL) in ~state()
282 /// our code is consistent and clears the stack explicitly.
286 assert(_pimpl->lua_state != NULL); in close()
287 assert(lua_gettop(_pimpl->lua_state) == 0); in close()
288 lua_close(_pimpl->lua_state); in close()
289 _pimpl->lua_state = NULL; in close()
293 /// Wrapper around lua_getglobal.
304 lua_pushcfunction(_pimpl->lua_state, protected_getglobal); in get_global()
305 lua_pushstring(_pimpl->lua_state, name.c_str()); in get_global()
306 if (lua_pcall(_pimpl->lua_state, 1, 1, 0) != 0) in get_global()
313 /// This is a wrapper around the incompatible differences between Lua 5.1 and
316 /// \post state(-1) Contains the reference to the globals table.
321 lua_pushvalue(_pimpl->lua_state, registry_index); in get_global_table()
322 lua_pushinteger(_pimpl->lua_state, LUA_RIDX_GLOBALS); in get_global_table()
323 lua_gettable(_pimpl->lua_state, -2); in get_global_table()
324 lua_remove(_pimpl->lua_state, -2); in get_global_table()
326 lua_pushvalue(_pimpl->lua_state, LUA_GLOBALSINDEX); in get_global_table()
331 /// Wrapper around luaL_getmetafield.
343 return luaL_getmetafield(_pimpl->lua_state, index, name.c_str()) != 0; in get_metafield()
347 /// Wrapper around lua_getmetatable.
355 return lua_getmetatable(_pimpl->lua_state, index) != 0; in get_metatable()
359 /// Wrapper around lua_gettable.
370 assert(lua_gettop(_pimpl->lua_state) >= 2); in get_table()
371 lua_pushcfunction(_pimpl->lua_state, protected_gettable); in get_table()
372 lua_pushvalue(_pimpl->lua_state, index < 0 ? index - 1 : index); in get_table()
373 lua_pushvalue(_pimpl->lua_state, -3); in get_table()
374 if (lua_pcall(_pimpl->lua_state, 2, 1, 0) != 0) in get_table()
376 lua_remove(_pimpl->lua_state, -2); in get_table()
380 /// Wrapper around lua_gettop.
386 return lua_gettop(_pimpl->lua_state); in get_top()
390 /// Wrapper around lua_insert.
396 lua_insert(_pimpl->lua_state, index); in insert()
400 /// Wrapper around lua_isboolean.
408 return lua_isboolean(_pimpl->lua_state, index); in is_boolean()
412 /// Wrapper around lua_isfunction.
420 return lua_isfunction(_pimpl->lua_state, index); in is_function()
424 /// Wrapper around lua_isnil.
432 return lua_isnil(_pimpl->lua_state, index); in is_nil()
436 /// Wrapper around lua_isnumber.
444 return lua_isnumber(_pimpl->lua_state, index); in is_number()
448 /// Wrapper around lua_isstring.
456 return lua_isstring(_pimpl->lua_state, index); in is_string()
460 /// Wrapper around lua_istable.
468 return lua_istable(_pimpl->lua_state, index); in is_table()
472 /// Wrapper around lua_isuserdata.
480 return lua_isuserdata(_pimpl->lua_state, index); in is_userdata()
484 /// Wrapper around luaL_loadfile.
495 if (::access(file.c_str(), R_OK) == -1) in load_file()
497 if (luaL_loadfile(_pimpl->lua_state, file.c_str()) != 0) in load_file()
502 /// Wrapper around luaL_loadstring.
512 if (luaL_loadstring(_pimpl->lua_state, str.c_str()) != 0) in load_string()
517 /// Wrapper around lua_newtable.
523 lua_newtable(_pimpl->lua_state); in new_table()
527 /// Wrapper around lua_newuserdata.
529 /// This is internal. The public type-safe interface of this method should be
540 return lua_newuserdata(_pimpl->lua_state, size); in new_userdata_voidp()
544 /// Wrapper around lua_next.
554 assert(lua_istable(_pimpl->lua_state, index)); in next()
555 assert(lua_gettop(_pimpl->lua_state) >= 1); in next()
556 lua_pushcfunction(_pimpl->lua_state, protected_next); in next()
557 lua_pushvalue(_pimpl->lua_state, index < 0 ? index - 1 : index); in next()
558 lua_pushvalue(_pimpl->lua_state, -3); in next()
559 if (lua_pcall(_pimpl->lua_state, 2, LUA_MULTRET, 0) != 0) in next()
561 const bool more = lua_toboolean(_pimpl->lua_state, -1); in next()
562 lua_pop(_pimpl->lua_state, 1); in next()
564 lua_remove(_pimpl->lua_state, -3); in next()
566 lua_pop(_pimpl->lua_state, 1); in next()
571 /// Wrapper around luaL_openlibs.
579 luaL_openlibs(_pimpl->lua_state); in open_all()
583 /// Wrapper around luaopen_base.
591 lua_pushcfunction(_pimpl->lua_state, luaopen_base); in open_base()
592 if (lua_pcall(_pimpl->lua_state, 0, 0, 0) != 0) in open_base()
597 /// Wrapper around luaopen_string.
606 luaL_requiref(_pimpl->lua_state, LUA_STRLIBNAME, luaopen_string, 1); in open_string()
607 lua_pop(_pimpl->lua_state, 1); in open_string()
609 lua_pushcfunction(_pimpl->lua_state, luaopen_string); in open_string()
610 if (lua_pcall(_pimpl->lua_state, 0, 0, 0) != 0) in open_string()
616 /// Wrapper around luaopen_table.
625 luaL_requiref(_pimpl->lua_state, LUA_TABLIBNAME, luaopen_table, 1); in open_table()
626 lua_pop(_pimpl->lua_state, 1); in open_table()
628 lua_pushcfunction(_pimpl->lua_state, luaopen_table); in open_table()
629 if (lua_pcall(_pimpl->lua_state, 0, 0, 0) != 0) in open_table()
635 /// Wrapper around lua_pcall.
645 if (lua_pcall(_pimpl->lua_state, nargs, nresults, errfunc) != 0) in pcall()
650 /// Wrapper around lua_pop.
656 assert(count <= lua_gettop(_pimpl->lua_state)); in pop()
657 lua_pop(_pimpl->lua_state, count); in pop()
658 assert(lua_gettop(_pimpl->lua_state) >= 0); in pop()
662 /// Wrapper around lua_pushboolean.
668 lua_pushboolean(_pimpl->lua_state, value ? 1 : 0); in push_boolean()
672 /// Wrapper around lua_pushcclosure.
674 /// This is not a pure wrapper around lua_pushcclosure because this has to do
683 lua_newuserdata(_pimpl->lua_state, sizeof(cxx_function))); in push_cxx_closure()
685 lua_pushcclosure(_pimpl->lua_state, cxx_closure_trampoline, nvalues + 1); in push_cxx_closure()
689 /// Wrapper around lua_pushcfunction.
691 /// This is not a pure wrapper around lua_pushcfunction because this has to do
699 lua_newuserdata(_pimpl->lua_state, sizeof(cxx_function))); in push_cxx_function()
701 lua_pushcclosure(_pimpl->lua_state, cxx_function_trampoline, 1); in push_cxx_function()
705 /// Wrapper around lua_pushinteger.
711 lua_pushinteger(_pimpl->lua_state, value); in push_integer()
715 /// Wrapper around lua_pushnil.
719 lua_pushnil(_pimpl->lua_state); in push_nil()
723 /// Wrapper around lua_pushstring.
731 lua_pushstring(_pimpl->lua_state, str.c_str()); in push_string()
735 /// Wrapper around lua_pushvalue.
741 lua_pushvalue(_pimpl->lua_state, index); in push_value()
745 /// Wrapper around lua_rawget.
751 lua_rawget(_pimpl->lua_state, index); in raw_get()
755 /// Wrapper around lua_rawset.
764 lua_rawset(_pimpl->lua_state, index); in raw_set()
768 /// Wrapper around lua_setglobal.
779 lua_pushcfunction(_pimpl->lua_state, protected_setglobal); in set_global()
780 lua_pushstring(_pimpl->lua_state, name.c_str()); in set_global()
781 lua_pushvalue(_pimpl->lua_state, -3); in set_global()
782 if (lua_pcall(_pimpl->lua_state, 2, 0, 0) != 0) in set_global()
784 lua_pop(_pimpl->lua_state, 1); in set_global()
788 /// Wrapper around lua_setmetatable.
794 lua_setmetatable(_pimpl->lua_state, index); in set_metatable()
798 /// Wrapper around lua_settable.
809 lua_pushcfunction(_pimpl->lua_state, protected_settable); in set_table()
810 lua_pushvalue(_pimpl->lua_state, index < 0 ? index - 1 : index); in set_table()
811 lua_pushvalue(_pimpl->lua_state, -4); in set_table()
812 lua_pushvalue(_pimpl->lua_state, -4); in set_table()
813 if (lua_pcall(_pimpl->lua_state, 3, 0, 0) != 0) in set_table()
815 lua_pop(_pimpl->lua_state, 2); in set_table()
819 /// Wrapper around lua_toboolean.
828 return lua_toboolean(_pimpl->lua_state, index); in to_boolean()
832 /// Wrapper around lua_tointeger.
841 return lua_tointeger(_pimpl->lua_state, index); in to_integer()
845 /// Wrapper around lua_touserdata.
847 /// This is internal. The public type-safe interface of this method should be
858 return lua_touserdata(_pimpl->lua_state, index); in to_userdata_voidp()
863 /// Wrapper around lua_tostring.
874 const char *raw_string = lua_tostring(_pimpl->lua_state, index); in to_string()
876 // implies that the raw string is duplicated and, henceforth, the string is in to_string()
882 /// Wrapper around lua_upvalueindex.
898 /// to call this method is by using the c_gate module, and c_gate takes care of
903 return _pimpl->lua_state; in raw_state()