diff --git a/README.md b/README.md index c5880380..fa481e86 100644 --- a/README.md +++ b/README.md @@ -53,9 +53,14 @@ ThePhD Lua Workshop 2016 - Mashape, San Francisco, CA [Deck](https://github.com/ThePhD/sol2/blob/develop/docs/presentations/ThePhD%20-%20No%20Overhead%20C%20Abstraction%20-%202016.10.14.pdf) +"Wrapping Lua C in C++ - Efficiently, Nicely, and with a Touch of Magic" +ThePhD +Boston C++ Meetup November 2017 - CiC, Boston, MA +[Deck](https://github.com/ThePhD/sol2/blob/develop/docs/presentations/ThePhD%20-%20Wrapping%20Lua%20C%20in%20C%2B%2B%20-%202017.11.8.pdf) + ## Creating a single header -You can grab a single header out of the library [here](https://github.com/ThePhD/sol2/tree/develop/single/sol). For stable version, check the releases tab on github for a provided single header file for maximum ease of use. A script called `single.py` is provided in the repository if there's some bleeding edge change that hasn't been published on the releases page. You can run this script to create a single file version of the library so you can only include that part of it. Check `single.py --help` for more info. +You can grab a single header (and the single forward header) out of the library [here](https://github.com/ThePhD/sol2/tree/develop/single/sol). For stable version, check the releases tab on github for a provided single header file for maximum ease of use. A script called `single.py` is provided in the repository if there's some bleeding edge change that hasn't been published on the releases page. You can run this script to create a single file version of the library so you can only include that part of it. Check `single.py --help` for more info. ## Features diff --git a/single.py b/single.py index 6ca40ba2..9a085f78 100644 --- a/single.py +++ b/single.py @@ -15,10 +15,18 @@ description = "Converts sol to a single file for convenience." # command line parser parser = argparse.ArgumentParser(usage='%(prog)s [options...]', description=description) -parser.add_argument('--output', '-o', help='name and location of where to place file', metavar='file', default='sol.hpp') +parser.add_argument('--output', '-o', nargs='+', help='name and location of where to place file (and forward declaration file)', metavar='file', default='sol.hpp') parser.add_argument('--quiet', help='suppress all output', action='store_true') args = parser.parse_args() +single_file = '' +forward_single_file = '' +single_file = args.output[0] +if len(args.output) > 1: + forward_single_file = args.output[1] +else: + a,b = os.path.splitext(single_file) + forward_single_file = a + '_forward' + b script_path = os.path.normpath(os.path.dirname(os.path.realpath(__file__))) working_dir = os.getcwd() os.chdir(script_path) @@ -142,14 +150,17 @@ def process_file(filename, out): version = get_version() revision = get_revision() include_guard = 'SOL_SINGLE_INCLUDE_HPP' - -if not args.quiet: - print('Creating single header for sol') - print('Current version: {version} (revision {revision})\n'.format(version = version, revision = revision)) - +forward_include_guard = 'SOL_SINGLE_INCLUDE_FORWARD_HPP' processed_files = [os.path.join(script_path, x) for x in ['sol.hpp']] +forward_processed_files = [os.path.join(script_path, x) for x in ['sol/forward.hpp']] result = '' +forward_result = '' + + +if not args.quiet: + print('Current version: {version} (revision {revision})\n'.format(version = version, revision = revision)) + print('Creating single header for sol') ss = StringIO() ss.write(intro.format(time=dt.datetime.utcnow(), revision=revision, version=version, guard=include_guard)) @@ -160,6 +171,27 @@ ss.write('#endif // {}\n'.format(include_guard)) result = ss.getvalue() ss.close() -with open(args.output, 'w', encoding='utf-8') as f: +if not args.quiet: + print('finished creating single header for sol\n') + +if not args.quiet: + print('Creating single forward declaration header for sol') + +includes = set([]) +forward_ss = StringIO() +forward_ss.write(intro.format(time=dt.datetime.utcnow(), revision=revision, version=version, guard=forward_include_guard)) +for forward_processed_file in forward_processed_files: + process_file(forward_processed_file, forward_ss) + +forward_ss.write('#endif // {}\n'.format(forward_include_guard)) +forward_result = forward_ss.getvalue() +forward_ss.close() + +if not args.quiet: + print('finished creating single forward declaration header for sol\n') + +with open(single_file, 'w', encoding='utf-8') as f: f.write(result) +with open(forward_single_file, 'w', encoding='utf-8') as f: + f.write(forward_result) diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index 6c666778..0ef4b1a3 100644 --- a/single/sol/sol.hpp +++ b/single/sol/sol.hpp @@ -20,8 +20,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // This file was generated with a script. -// Generated 2017-12-08 06:22:13.819358 UTC -// This header was generated with sol v2.19.0 (revision 36b8d50) +// Generated 2017-12-09 07:45:45.246313 UTC +// This header was generated with sol v2.19.0 (revision 5f68853) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP diff --git a/single/sol/sol_forward.hpp b/single/sol/sol_forward.hpp new file mode 100644 index 00000000..63f6445b --- /dev/null +++ b/single/sol/sol_forward.hpp @@ -0,0 +1,301 @@ +// The MIT License (MIT) + +// Copyright (c) 2013-2017 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. + +// This file was generated with a script. +// Generated 2017-12-09 07:45:45.424818 UTC +// This header was generated with sol v2.19.0 (revision 5f68853) +// https://github.com/ThePhD/sol2 + +#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP +#define SOL_SINGLE_INCLUDE_FORWARD_HPP + +// beginning of sol/forward.hpp + +// beginning of sol/feature_test.hpp + +#if (defined(__cplusplus) && __cplusplus == 201703L) || (defined(_MSC_VER) && _MSC_VER > 1900 && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && _MSVC_LANG > 201402L))) +#ifndef SOL_CXX17_FEATURES +#define SOL_CXX17_FEATURES 1 +#endif // C++17 features macro +#endif // C++17 features check + +#if defined(__cpp_noexcept_function_type) || ((defined(_MSC_VER) && _MSC_VER > 1911) && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L))) +#ifndef SOL_NOEXCEPT_FUNCTION_TYPE +#define SOL_NOEXCEPT_FUNCTION_TYPE 1 +#endif // noexcept is part of a function's type +#endif + +#if defined(_WIN32) || defined(_MSC_VER) +#ifndef SOL_CODECVT_SUPPORT +#define SOL_CODECVT_SUPPORT 1 +#endif // sol codecvt support +#elif defined(__GNUC__) +#if __GNUC__ >= 5 +#ifndef SOL_CODECVT_SUPPORT +#define SOL_CODECVT_SUPPORT 1 +#endif // codecvt support +#endif // g++ 5.x.x (MinGW too) +#else +#endif // Windows/VC++ vs. g++ vs Others + +#ifdef _MSC_VER +#if defined(_DEBUG) && !defined(NDEBUG) + +#ifndef SOL_IN_DEBUG_DETECTED +#define SOL_IN_DEBUG_DETECTED 1 +#endif + +#endif // VC++ Debug macros + +#ifndef _CPPUNWIND +#ifndef SOL_NO_EXCEPTIONS +#define SOL_NO_EXCEPTIONS 1 +#endif +#endif // Automatic Exceptions + +#ifndef _CPPRTTI +#ifndef SOL_NO_RTTI +#define SOL_NO_RTTI 1 +#endif +#endif // Automatic RTTI +#elif defined(__GNUC__) || defined(__clang__) + +#if !defined(NDEBUG) && !defined(__OPTIMIZE__) + +#ifndef SOL_IN_DEBUG_DETECTED +#define SOL_IN_DEBUG_DETECTED 1 +#endif + +#endif // Not Debug && g++ optimizer flag + +#ifndef __EXCEPTIONS +#ifndef SOL_NO_EXCEPTIONS +#define SOL_NO_EXCEPTIONS 1 +#endif +#endif // No Exceptions + +#ifndef __GXX_RTTI +#ifndef SOL_NO_RTII +#define SOL_NO_RTTI 1 +#endif +#endif // No RTTI + +#endif // vc++ || clang++/g++ + +#if defined(SOL_CHECK_ARGUMENTS) + +#if !defined(SOL_SAFE_GETTER) +#define SOL_SAFE_GETTER 1 +#endif + +#if !defined(SOL_SAFE_USERTYPE) +#define SOL_SAFE_USERTYPE 1 +#endif + +#if !defined(SOL_SAFE_REFERENCES) +#define SOL_SAFE_REFERENCES 1 +#endif + +#if !defined(SOL_SAFE_FUNCTION) +#define SOL_SAFE_FUNCTION 1 +#endif + +#if !defined(SOL_SAFE_FUNCTION_CALLS) +#define SOL_SAFE_FUNCTION_CALLS 1 +#endif + +#if !defined(SOL_SAFE_PROXIES) +#define SOL_SAFE_PROXIES 1 +#endif + +#if !defined(SOL_SAFE_NUMERICS) +#define SOL_SAFE_NUMERICS 1 +#endif + +#endif // Turn on Safety for all if top-level macro is defined + +#ifdef SOL_IN_DEBUG_DETECTED + +#if !defined(SOL_SAFE_REFERENCES) +#define SOL_SAFE_REFERENCES 1 +#endif + +#if !defined(SOL_SAFE_USERTYPE) +#define SOL_SAFE_USERTYPE 1 +#endif + +#if !defined(SOL_SAFE_FUNCTION_CALLS) +#define SOL_SAFE_FUNCTION_CALLS 1 +#endif + +#endif // Turn on all debug safety features for VC++ / g++ / clang++ and similar + +#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) || defined(__OBJC__) || defined(nil) +#if !defined(SOL_NO_NIL) +#define SOL_NO_NIL 1 +#endif +#endif // avoiding nil defines / keywords + +namespace sol { +namespace detail { + const bool default_safe_function_calls = +#ifdef SOL_SAFE_FUNCTION_CALLS + true; +#else + false; +#endif +} +} // namespace sol::detail + +// end of sol/feature_test.hpp + +namespace sol { + + template + class basic_reference; + using reference = basic_reference; + using main_reference = basic_reference; + class stack_reference; + + struct proxy_base_tag; + template + struct proxy_base; + template + struct proxy; + + template + class usertype; + template + class simple_usertype; + template + class basic_table_core; + template + using table_core = basic_table_core; + template + using main_table_core = basic_table_core; + template + using stack_table_core = basic_table_core; + template + using basic_table = basic_table_core; + typedef table_core table; + typedef table_core global_table; + typedef main_table_core main_table; + typedef main_table_core main_global_table; + typedef stack_table_core stack_table; + typedef stack_table_core stack_global_table; + template + struct basic_environment; + using environment = basic_environment; + using main_environment = basic_environment; + using stack_environment = basic_environment; + template + class basic_function; + template + class basic_protected_function; + using unsafe_function = basic_function; + using safe_function = basic_protected_function; + using main_unsafe_function = basic_function; + using main_safe_function = basic_protected_function; + using stack_unsafe_function = basic_function; + using stack_safe_function = basic_protected_function; + using stack_aligned_unsafe_function = basic_function; + using stack_aligned_safe_function = basic_protected_function; + using protected_function = safe_function; + using main_protected_function = main_safe_function; + using stack_protected_function = stack_safe_function; + using stack_aligned_protected_function = stack_aligned_safe_function; +#ifdef SOL_SAFE_FUNCTION + using function = protected_function; + using main_function = main_protected_function; + using stack_function = stack_protected_function; +#else + using function = unsafe_function; + using main_function = main_unsafe_function; + using stack_function = stack_unsafe_function; +#endif + using stack_aligned_function = stack_aligned_unsafe_function; + using stack_aligned_stack_handler_function = basic_protected_function; + + struct unsafe_function_result; + struct protected_function_result; + using safe_function_result = protected_function_result; +#ifdef SOL_SAFE_FUNCTION + using function_result = safe_function_result; +#else + using function_result = unsafe_function_result; +#endif + + template + class basic_object; + template + class basic_userdata; + template + class basic_lightuserdata; + template + class basic_coroutine; + template + class basic_thread; + + using object = basic_object; + using userdata = basic_userdata; + using lightuserdata = basic_lightuserdata; + using thread = basic_thread; + using coroutine = basic_coroutine; + using main_object = basic_object; + using main_userdata = basic_userdata; + using main_lightuserdata = basic_lightuserdata; + using main_coroutine = basic_coroutine; + using stack_object = basic_object; + using stack_userdata = basic_userdata; + using stack_lightuserdata = basic_lightuserdata; + using stack_thread = basic_thread; + using stack_coroutine = basic_coroutine; + + struct stack_proxy_base; + struct stack_proxy; + struct variadic_args; + struct variadic_results; + struct stack_count; + struct this_state; + struct this_main_state; + struct this_environment; + + template + struct as_table_t; + template + struct as_container_t; + template + struct nested; + template + struct light; + template + struct user; + template + struct as_args_t; + template + struct protect_t; + template + struct filter_wrapper; +} // namespace sol + +// end of sol/forward.hpp + +#endif // SOL_SINGLE_INCLUDE_FORWARD_HPP