* New abbreviated types are in osd and util namespaces, and also in global namespace for things that #include "emu.h"
* Get rid of import of cstdint types to global namespace (C99 does this anyway)
* Remove the cstdint types from everything in emu
* Get rid of U64/S64 macros
* Fix a bug in dps16 caused by incorrect use of macro
* Fix debugcon not checking for "do " prefix case-insensitively
* Fix a lot of messed up tabulation
* More constexpr
* Fix up many __names
// The MIT License (MIT) // Copyright (c) 2013-2016 Rapptz, ThePhD and contributors// Permission is hereby granted, free of charge, to any person obtaining a copy of// this software and associated documentation files (the "Software"), to deal in// the Software without restriction, including without limitation the rights to// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of// the Software, and to permit persons to whom the Software is furnished to do so,// subject to the following conditions:// The above copyright notice and this permission notice shall be included in all// copies or substantial portions of the Software.// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.#ifndef SOL_PROTECTED_FUNCTION_HPP#define SOL_PROTECTED_FUNCTION_HPP#include"reference.hpp"#include"stack.hpp"#include"protected_function_result.hpp"#include<cstdint>#include<algorithm>namespacesol{namespacedetail{inlinereference&handler_storage(){staticsol::referenceh;returnh;}structhandler{constreference⌖intstackindex;handler(constreference&target):target(target),stackindex(0){if(target.valid()){stackindex=lua_gettop(target.lua_state())+1;target.push();}}boolvalid()const{returnstackindex!=0;}~handler(){if(valid()){lua_remove(target.lua_state(),stackindex);}}};}template<typenamebase_t>classbasic_protected_function:publicbase_t{public:staticreference&get_default_handler(){returndetail::handler_storage();}staticvoidset_default_handler(constreference&ref){detail::handler_storage()=ref;}staticvoidset_default_handler(reference&&ref){detail::handler_storage()=std::move(ref);}private:call_statusluacall(std::ptrdiff_targcount,std::ptrdiff_tresultcount,detail::handler&h)const{returnstatic_cast<call_status>(lua_pcallk(base_t::lua_state(),static_cast<int>(argcount),static_cast<int>(resultcount),h.stackindex,0,nullptr));}template<std::size_t...I,typename...Ret>autoinvoke(types<Ret...>,std::index_sequence<I...>,std::ptrdiff_tn,detail::handler&h)const{luacall(n,sizeof...(Ret),h);returnstack::pop<std::tuple<Ret...>>(base_t::lua_state());}template<std::size_tI,typenameRet>Retinvoke(types<Ret>,std::index_sequence<I>,std::ptrdiff_tn,detail::handler&h)const{luacall(n,1,h);returnstack::pop<Ret>(base_t::lua_state());}template<std::size_tI>voidinvoke(types<void>,std::index_sequence<I>,std::ptrdiff_tn,detail::handler&h)const{luacall(n,0,h);}protected_function_resultinvoke(types<>,std::index_sequence<>,std::ptrdiff_tn,detail::handler&h)const{intstacksize=lua_gettop(base_t::lua_state());intpoststacksize=stacksize;intfirstreturn=1;intreturncount=0;call_statuscode=call_status::ok;#ifndef SOL_NO_EXCEPTIONSautoonexcept=[&](constchar*error){h.stackindex=0;if(h.target.valid()){h.target.push();stack::push(base_t::lua_state(),error);lua_call(base_t::lua_state(),1,1);}else{stack::push(base_t::lua_state(),error);}};try{#endif // No Exceptionsfirstreturn=(std::max)(1,static_cast<int>(stacksize-n-static_cast<int>(h.valid())));code=luacall(n,LUA_MULTRET,h);poststacksize=lua_gettop(base_t::lua_state())-static_cast<int>(h.valid());returncount=poststacksize-(firstreturn-1);#ifndef SOL_NO_EXCEPTIONS}// Handle C++ errors thrown from C++ functions bound inside of luacatch(constchar*error){onexcept(error);firstreturn=lua_gettop(base_t::lua_state());returnprotected_function_result(base_t::lua_state(),firstreturn,0,1,call_status::runtime);}catch(conststd::exception&error){onexcept(error.what());firstreturn=lua_gettop(base_t::lua_state());returnprotected_function_result(base_t::lua_state(),firstreturn,0,1,call_status::runtime);}catch(...){onexcept("caught (...) unknown error during protected_function call");firstreturn=lua_gettop(base_t::lua_state());returnprotected_function_result(base_t::lua_state(),firstreturn,0,1,call_status::runtime);}#endif // No Exceptionsreturnprotected_function_result(base_t::lua_state(),firstreturn,returncount,returncount,code);}public:referenceerror_handler;basic_protected_function()=default;template<typenameT,meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>,basic_protected_function>>,meta::neg<std::is_same<base_t,stack_reference>>,std::is_base_of<base_t,meta::unqualified_t<T>>>=meta::enabler>basic_protected_function(T&&r)noexcept:base_t(std::forward<T>(r)){#ifdef SOL_CHECK_ARGUMENTSif(!is_function<meta::unqualified_t<T>>::value){autopp=stack::push_pop(*this);stack::check<basic_protected_function>(base_t::lua_state(),-1,type_panic);}#endif // Safety}basic_protected_function(constbasic_protected_function&)=default;basic_protected_function&operator=(constbasic_protected_function&)=default;basic_protected_function(basic_protected_function&&)=default;basic_protected_function&operator=(basic_protected_function&&)=default;basic_protected_function(constbasic_function<base_t>&b,referenceeh=get_default_handler()):base_t(b),error_handler(std::move(eh)){}basic_protected_function(basic_function<base_t>&&b,referenceeh=get_default_handler()):base_t(std::move(b)),error_handler(std::move(eh)){}basic_protected_function(conststack_reference&r,referenceeh=get_default_handler()):basic_protected_function(r.lua_state(),r.stack_index(),std::move(eh)){}basic_protected_function(stack_reference&&r,referenceeh=get_default_handler()):basic_protected_function(r.lua_state(),r.stack_index(),std::move(eh)){}template<typenameSuper>basic_protected_function(proxy_base<Super>&&p,referenceeh=get_default_handler()):basic_protected_function(p.operatorbasic_function<base_t>(),std::move(eh)){}template<typenameSuper>basic_protected_function(constproxy_base<Super>&p,referenceeh=get_default_handler()):basic_protected_function(static_cast<basic_function<base_t>>(p),std::move(eh)){}basic_protected_function(lua_State*L,intindex=-1,referenceeh=get_default_handler()):base_t(L,index),error_handler(std::move(eh)){#ifdef SOL_CHECK_ARGUMENTSstack::check<basic_protected_function>(L,index,type_panic);#endif // Safety}template<typename...Args>protected_function_resultoperator()(Args&&...args)const{returncall<>(std::forward<Args>(args)...);}template<typename...Ret,typename...Args>decltype(auto)operator()(types<Ret...>,Args&&...args)const{returncall<Ret...>(std::forward<Args>(args)...);}template<typename...Ret,typename...Args>decltype(auto)call(Args&&...args)const{detail::handlerh(error_handler);base_t::push();intpushcount=stack::multi_push_reference(base_t::lua_state(),std::forward<Args>(args)...);returninvoke(types<Ret...>(),std::make_index_sequence<sizeof...(Ret)>(),pushcount,h);}};}// sol#endif // SOL_FUNCTION_HPP