Skip to content

Commit

Permalink
This update allows for many more definition macros and teh use of a c…
Browse files Browse the repository at this point in the history
…onfiguration header to be combined with the single.py

Allow for configuration macros to aid in fixing #631
  • Loading branch information
ThePhD committed Apr 17, 2018
1 parent 2de6447 commit 479575c
Show file tree
Hide file tree
Showing 48 changed files with 1,849 additions and 1,682 deletions.
15 changes: 15 additions & 0 deletions .style.yapf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[style]
based_on_style = pep8
use_tabs = true
indent_width = 5

spaces_before_comment = 1
spaces_around_power_operator = true
space_between_ending_comma_and_closing_bracket = true

continuation_align_style = SPACE
split_before_first_argument = false
split_complex_comprehension = true
dedent_closing_brackets = false
coalesce_brackets = true
align_closing_bracket_with_visual_indent = false
Binary file modified docs/source/media/sol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/source/media/sol.psd
Binary file not shown.
182 changes: 109 additions & 73 deletions single.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,33 @@

# python 3 compatibility
try:
import cStringIO as sstream
import cStringIO as sstream
except ImportError:
from io import StringIO
from io import StringIO

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', nargs='+', help='name and location of where to place file (and forward declaration file)', metavar='file', default='sol.hpp')
parser = argparse.ArgumentParser(
usage='%(prog)s [options...]', description=description)
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]
forward_single_file = args.output[1]
else:
a,b = os.path.splitext(single_file)
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()
Expand Down Expand Up @@ -67,84 +75,100 @@
includes = set([])
standard_include = re.compile(r'#include <(.*?)>')
local_include = re.compile(r'#(\s*?)include "(.*?)"')
project_include = re.compile(r'#(\s*?)include <sol/(.*?)>')
pragma_once_cpp = re.compile(r'(\s*)#(\s*)pragma(\s+)once')
ifndef_cpp = re.compile(r'#ifndef SOL_.*?_HPP')
define_cpp = re.compile(r'#define SOL_.*?_HPP')
endif_cpp = re.compile(r'#endif // SOL_.*?_HPP')

def get_include(line, base_path):
local_match = local_include.match(line)
if local_match:
# local include found
full_path = os.path.normpath(os.path.join(base_path, local_match.group(2))).replace('\\', '/')
return full_path

return None
def get_include(line, base_path):
local_match = local_include.match(line)
if local_match:
# local include found
full_path = os.path.normpath(
os.path.join(base_path, local_match.group(2))).replace(
'\\', '/')
return full_path
project_match = project_include.match(line)
if project_match:
# local include found
full_path = os.path.normpath(
os.path.join(base_path, project_match.group(2))).replace(
'\\', '/')
return full_path
return None


def is_include_guard(line):
return ifndef_cpp.match(line) or define_cpp.match(line) or endif_cpp.match(line)
return ifndef_cpp.match(line) or define_cpp.match(
line) or endif_cpp.match(line) or pragma_once_cpp.match(line)


def get_revision():
return os.popen('git rev-parse --short HEAD').read().strip()
return os.popen('git rev-parse --short HEAD').read().strip()


def get_version():
return os.popen('git describe --tags --abbrev=0').read().strip()
return os.popen('git describe --tags --abbrev=0').read().strip()


def process_file(filename, out):
global includes
filename = os.path.normpath(filename)
relativefilename = filename.replace(script_path + os.sep, "").replace("\\", "/")
global includes
filename = os.path.normpath(filename)
relativefilename = filename.replace(script_path + os.sep, "").replace(
"\\", "/")

if filename in includes:
return

if filename in includes:
return
includes.add(filename)

includes.add(filename)
if not args.quiet:
print('processing {}'.format(filename))

if not args.quiet:
print('processing {}'.format(filename))

out.write('// beginning of {}\n\n'.format(relativefilename))
empty_line_state = True
out.write('// beginning of {}\n\n'.format(relativefilename))
empty_line_state = True

with open(filename, 'r', encoding='utf-8') as f:
for line in f:
# skip comments
if line.startswith('//'):
continue
with open(filename, 'r', encoding='utf-8') as f:
for line in f:
# skip comments
if line.startswith('//'):
continue

# skip include guard non-sense
if is_include_guard(line):
continue
# skip include guard non-sense
if is_include_guard(line):
continue

# get relative directory
base_path = os.path.dirname(filename)
# get relative directory
base_path = os.path.dirname(filename)

# check if it's a standard file
std = standard_include.search(line)
if std:
std_file = os.path.join('std', std.group(0))
if std_file in includes:
continue
includes.add(std_file)
# check if it's a standard file
std = standard_include.search(line)
if std:
std_file = os.path.join('std', std.group(0))
if std_file in includes:
continue
includes.add(std_file)

# see if it's an include file
name = get_include(line, base_path)
# see if it's an include file
name = get_include(line, base_path)

if name:
process_file(name, out)
continue
if name:
process_file(name, out)
continue

empty_line = len(line.strip()) == 0
empty_line = len(line.strip()) == 0

if empty_line and empty_line_state:
continue
if empty_line and empty_line_state:
continue

empty_line_state = empty_line
empty_line_state = empty_line

# line is fine
out.write(line)
# line is fine
out.write(line)

out.write('// end of {}\n\n'.format(relativefilename))
out.write('// end of {}\n\n'.format(relativefilename))


version = get_version()
Expand All @@ -153,49 +177,61 @@ def process_file(filename, out):
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']]
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')
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))
ss.write(
intro.format(
time=dt.datetime.utcnow(),
revision=revision,
version=version,
guard=include_guard))
for processed_file in processed_files:
process_file(processed_file, ss)
process_file(processed_file, ss)

ss.write('#endif // {}\n'.format(include_guard))
result = ss.getvalue()
ss.close()

if not args.quiet:
print('finished creating single header for sol\n')
print('finished creating single header for sol\n')

if not args.quiet:
print('Creating single forward declaration header for sol')
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))
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)
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')
print('finished creating single forward declaration header for sol\n')

with open(single_file, 'w', encoding='utf-8') as f:
if not args.quiet:
print('writing {}...'.format(single_file))
f.write(result)
if not args.quiet:
print('writing {}...'.format(single_file))
f.write(result)

with open(forward_single_file, 'w', encoding='utf-8') as f:
if not args.quiet:
print('writing {}...'.format(forward_single_file))
f.write(forward_result)
if not args.quiet:
print('writing {}...'.format(forward_single_file))
f.write(forward_result)
14 changes: 7 additions & 7 deletions sol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@
#define SOL_HPP

#if defined(UE_BUILD_DEBUG) || defined(UE_BUILD_DEVELOPMENT) || defined(UE_BUILD_TEST) || defined(UE_BUILD_SHIPPING) || defined(UE_SERVER)
#define SOL_INSIDE_UNREAL
#define SOL_INSIDE_UNREAL 1
#endif // Unreal Engine 4 bullshit

#ifdef SOL_INSIDE_UNREAL
#if defined(SOL_INSIDE_UNREAL) && SOL_INSIDE_UNREAL
#ifdef check
#define SOL_INSIDE_UNREAL_REMOVED_CHECK
#undef check
#endif
#endif // Unreal Engine 4 Bullshit

#ifdef __GNUC__
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wconversion"
#if __GNUC__ > 6
#pragma GCC diagnostic ignored "-Wnoexcept-type"
#endif
#elif defined __clang__
#elif defined(__clang__)
// we'll just let this alone for now
#elif defined _MSC_VER
#pragma warning( push )
Expand All @@ -61,14 +61,14 @@
#include "sol/variadic_args.hpp"
#include "sol/variadic_results.hpp"

#ifdef __GNUC__
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#elif defined _MSC_VER
#pragma warning( push )
#endif // g++

#ifdef SOL_INSIDE_UNREAL
#ifdef SOL_INSIDE_UNREAL_REMOVED_CHECK
#if defined(SOL_INSIDE_UNREAL) && SOL_INSIDE_UNREAL
#if defined(SOL_INSIDE_UNREAL_REMOVED_CHECK) && SOL_INSIDE_UNREAL_REMOVED_CHECK
#if DO_CHECK
#define check(expr) { if(UNLIKELY(!(expr))) { FDebug::LogAssertFailedMessage( #expr, __FILE__, __LINE__ ); _DebugBreakAndPromptForRemote(); FDebug::AssertFailed( #expr, __FILE__, __LINE__ ); CA_ASSUME(false); } }
#else
Expand Down
4 changes: 2 additions & 2 deletions sol/bind_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ namespace meta {
typedef R (T::*function_pointer_type)(Args..., ...) const volatile&&;
};

#ifdef SOL_NOEXCEPT_FUNCTION_TYPE
#if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE

template <typename R, typename... Args>
struct fx_traits<R(Args...) noexcept, false> : basic_traits<true, false, void, R, Args...> {
Expand Down Expand Up @@ -373,7 +373,7 @@ namespace meta {
typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile&&;
};

#ifdef SOL_NOEXCEPT_FUNCTION_TYPE
#if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE

template <typename R, typename... Args>
struct fx_traits<R __stdcall(Args...) noexcept, false> : basic_traits<true, false, void, R, Args...> {
Expand Down
10 changes: 5 additions & 5 deletions sol/call.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ namespace sol {
}
};

#ifdef SOL_NOEXCEPT_FUNCTION_TYPE
#if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE
template <bool is_index, bool is_variable, bool checked, int boost, bool clean_stack, typename C>
struct agnostic_lua_call_wrapper<detail::lua_CFunction_noexcept, is_index, is_variable, checked, boost, clean_stack, C> {
static int call(lua_State* L, detail::lua_CFunction_noexcept f) {
Expand Down Expand Up @@ -371,7 +371,7 @@ namespace sol {
template <typename Fx>
static int call(lua_State* L, Fx&& f) {
typedef std::conditional_t<std::is_void<T>::value, object_type, T> Ta;
#ifdef SOL_SAFE_USERTYPE
#if defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE
auto maybeo = stack::check_get<Ta*>(L, 1);
if (!maybeo || maybeo.value() == nullptr) {
return luaL_error(L, "sol: received nil for 'self' argument (use ':' for accessing member functions, make sure member variables are preceeded by the actual object with '.' syntax)");
Expand Down Expand Up @@ -401,7 +401,7 @@ namespace sol {
template <typename V>
static int call_assign(std::true_type, lua_State* L, V&& f) {
typedef std::conditional_t<std::is_void<T>::value, object_type, T> Ta;
#ifdef SOL_SAFE_USERTYPE
#if defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE
auto maybeo = stack::check_get<Ta*>(L, 1);
if (!maybeo || maybeo.value() == nullptr) {
if (is_variable) {
Expand Down Expand Up @@ -461,7 +461,7 @@ namespace sol {
template <typename V>
static int call(lua_State* L, V&& f) {
typedef std::conditional_t<std::is_void<T>::value, object_type, T> Ta;
#ifdef SOL_SAFE_USERTYPE
#if defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE
auto maybeo = stack::check_get<Ta*>(L, 1);
if (!maybeo || maybeo.value() == nullptr) {
if (is_variable) {
Expand Down Expand Up @@ -642,7 +642,7 @@ namespace sol {
typedef meta::pop_front_type_t<typename traits_type::free_args_list> args_list;
typedef T Ta;
typedef std::remove_pointer_t<object_type> Oa;
#ifdef SOL_SAFE_USERTYPE
#if defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE
auto maybeo = stack::check_get<Ta*>(L, 1);
if (!maybeo || maybeo.value() == nullptr) {
if (is_variable) {
Expand Down
Loading

0 comments on commit 479575c

Please sign in to comment.