Merge remote-tracking branch 'root/develop' into develop

# Conflicts:
#	examples/usertype.cpp
#	sol.hpp
#	sol/debug.hpp
#	sol/default_construct.hpp
#	sol/demangle.hpp
#	sol/deprecate.hpp
#	sol/error.hpp
#	sol/function.hpp
#	sol/function_types.hpp
#	sol/object.hpp
#	sol/proxy.hpp
#	sol/reference.hpp
#	sol/resolve.hpp
#	sol/stack.hpp
#	sol/state.hpp
#	sol/table.hpp
#	sol/traits.hpp
#	sol/tuple.hpp
#	sol/types.hpp
#	sol/usertype.hpp
#	sol/usertype_traits.hpp
This commit is contained in:
ThePhD 2016-01-24 12:16:38 -05:00
commit 31e7857870
24 changed files with 220 additions and 37 deletions

View File

@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2013 Danny Y., Rapptz Copyright (c) 2013-2015 Rapptz and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of 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 this software and associated documentation files (the "Software"), to deal in

View File

@ -2,7 +2,7 @@
[![Build Status](https://travis-ci.org/Rapptz/sol.svg?branch=master)](https://travis-ci.org/Rapptz/sol) [![Build Status](https://travis-ci.org/Rapptz/sol.svg?branch=master)](https://travis-ci.org/Rapptz/sol)
Sol is a C++ library binding to Lua. It currently supports Lua 5.2. Sol aims to be easy to use and easy to add to a project. Sol is a C++ library binding to Lua. It currently supports Lua 5.2+. Sol aims to be easy to use and easy to add to a project.
At this time, the library is header-only for easy integration with projects. At this time, the library is header-only for easy integration with projects.
## Sneak Peek ## Sneak Peek
@ -30,7 +30,7 @@ struct vars {
int main() { int main() {
sol::state lua; sol::state lua;
lua.new_userdata<vars>("vars", "boop", &vars::boop); lua.new_usertype<vars>("vars", "boop", &vars::boop);
lua.script("beep = vars.new()\n" lua.script("beep = vars.new()\n"
"beep.boop = 1"); "beep.boop = 1");
assert(lua.get<vars>("beep").boop == 1); assert(lua.get<vars>("beep").boop == 1);
@ -39,6 +39,10 @@ int main() {
More examples are given in the examples directory. More examples are given in the examples directory.
## Creating a single header
For maximum ease of use, a script called `single.py` is provided. 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 ## Features
- Supports retrieval and setting of multiple types including `std::string`. - Supports retrieval and setting of multiple types including `std::string`.

View File

@ -50,7 +50,7 @@ args = parser.parse_args()
# general variables # general variables
include = [ '.', os.path.join('Catch', 'include')] include = [ '.', os.path.join('Catch', 'include')]
depends = [] depends = []
cxxflags = [ '-Wall', '-Wextra', '-pedantic', '-pedantic-errors', '-std=c++11' ] cxxflags = [ '-Wall', '-Wextra', '-pedantic', '-pedantic-errors', '-std=c++11', '-Wno-unused-variable' ]
ldflags = [] ldflags = []
script_dir = os.path.dirname(os.path.realpath(sys.argv[0])) script_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
sol_dir = os.path.join(script_dir, 'sol') sol_dir = os.path.join(script_dir, 'sol')

View File

@ -43,15 +43,15 @@ int main() {
lua.open_libraries(sol::lib::base, sol::lib::math); lua.open_libraries(sol::lib::base, sol::lib::math);
// the simplest way to create a class is through // the simplest way to create a class is through
// sol::state::new_usertype // sol::state::new_userdata
// the first template is the class type // the first template is the class type
// the rest are the constructor parameters // the rest are the constructor parameters
// using new_usertype you can only have one constructor // using new_userdata you can only have one constructor
// you must make sure that the name of the function // you must make sure that the name of the function
// goes before the member function pointer // goes before the member function pointer
lua.new_usertype<foo, std::string>("foo", "print", &foo::print, "test", &foo::test); lua.new_userdata<foo, std::string>("foo", "print", &foo::print, "test", &foo::test);
// making the class from lua is simple // making the class from lua is simple
// same with calling member functions // same with calling member functions
@ -63,8 +63,8 @@ int main() {
assert(y == 14); assert(y == 14);
// if you want a class to have more than one constructor // if you want a class to have more than one constructor
// the way to do so is through set_usertype and creating // the way to do so is through set_userdata and creating
// a usertype yourself with constructor types // a userdata yourself with constructor types
{ {
// Notice the brace: this means we're in a new scope // Notice the brace: this means we're in a new scope
@ -75,7 +75,7 @@ int main() {
// the first argument of construction is the name // the first argument of construction is the name
// second is the constructor types // second is the constructor types
// then the rest are function name and member function pointer pairs // then the rest are function name and member function pointer pairs
sol::usertype<vector> udata(ctor, "is_unit", &vector::is_unit); sol::userdata<vector> udata("vector", ctor, "is_unit", &vector::is_unit);
// then you must register it // then you must register it
lua.set_usertype("vector", udata); lua.set_usertype("vector", udata);
@ -83,7 +83,7 @@ int main() {
// have to keep it around // have to keep it around
// cleanup happens automagically // cleanup happens automagically
} }
// calling it is the same as new_usertype // calling it is the same as new_userdata
lua.script("v = vector.new()\n" lua.script("v = vector.new()\n"
"v = vector.new(12)\n" "v = vector.new(12)\n"
@ -92,7 +92,7 @@ int main() {
// You can even have C++-like member-variable-access // You can even have C++-like member-variable-access
// just pass is public member variables in the same style as functions // just pass is public member variables in the same style as functions
lua.new_usertype<variables>("variables", "low_gravity", &variables::low_gravity, "boost_level", &variables::boost_level); lua.new_userdata<variables>("variables", "low_gravity", &variables::low_gravity, "boost_level", &variables::boost_level);
// making the class from lua is simple // making the class from lua is simple
// same with calling member functions/variables // same with calling member functions/variables

164
single.py Normal file
View File

@ -0,0 +1,164 @@
#!/usr/bin/env python
import argparse
import os, sys
import re
import datetime as dt
# python 3 compatibility
try:
import cStringIO as sstream
except ImportError:
import io.StringIO as sstream
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('--quiet', help='suppress all output', action='store_true')
args = parser.parse_args()
script_path = os.path.normpath(os.path.dirname(os.path.realpath(__file__)))
working_dir = os.getcwd()
os.chdir(script_path)
intro = """// The MIT License (MIT)
// Copyright (c) 2013-2015 Rapptz 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 {time} UTC
// This header was generated with sol {version} (revision {revision})
// https://github.com/Rapptz/sol
#ifndef {guard}
#define {guard}
"""
module_path = os.path.join(script_path)
includes = set([])
standard_include = re.compile(r'#include <(.*?)>')
local_include = re.compile(r'#include "(.*?)"')
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(1))).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)
def get_revision():
return os.popen('git rev-parse --short HEAD').read().strip()
def get_version():
return os.popen('git describe --tags --abbrev=0').read().strip()
def process_file(filename, out):
global includes
filename = os.path.normpath(filename)
if filename in includes:
return
includes.add(filename)
if not args.quiet:
print('processing {}'.format(filename))
out.write('// beginning of {}\n\n'.format(filename))
empty_line_state = True
with open(filename, 'r') as f:
for line in f:
# skip comments
if line.startswith('//'):
continue
# skip include guard non-sense
if is_include_guard(line):
continue
# 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)
# see if it's an include file
name = get_include(line, base_path)
if name:
process_file(name, out)
continue
empty_line = len(line.strip()) == 0
if empty_line and empty_line_state:
continue
empty_line_state = empty_line
# line is fine
out.write(line)
out.write('// end of {}\n\n'.format(filename))
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))
processed_files = [os.path.join(script_path, 'sol', x) for x in ('state.hpp', 'object.hpp', 'function.hpp')]
result = ''
ss = sstream.StringIO()
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)
ss.write('#endif // {}\n'.format(include_guard))
result = ss.getvalue()
ss.close()
with open(args.output, 'w') as f:
f.write(result)

View File

@ -1,6 +1,6 @@
// The MIT License (MIT) // The MIT License (MIT)
// Copyright (c) 2013-2015 Danny Y., Rapptz // Copyright (c) 2013-2015 Rapptz and contributors
// Permission is hereby granted, free of charge, to any person obtaining a copy of // 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 // this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,6 @@
// The MIT License (MIT) // The MIT License (MIT)
// Copyright (c) 2013-2015 Danny Y., Rapptz // Copyright (c) 2013-2015 Rapptz and contributors
// Permission is hereby granted, free of charge, to any person obtaining a copy of // 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 // this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,6 @@
// The MIT License (MIT) // The MIT License (MIT)
// Copyright (c) 2013-2015 Danny Y., Rapptz // Copyright (c) 2013-2015 Rapptz and contributors
// Permission is hereby granted, free of charge, to any person obtaining a copy of // 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 // this software and associated documentation files (the "Software"), to deal in
@ -26,7 +26,7 @@
#include <array> #include <array>
#include <cstdlib> #include <cstdlib>
#if (defined(__GNUC__) || defined(__clang__)) && !defined(_MSC_VER) #if defined(__GNUC__) || defined(__clang__)
#include <cxxabi.h> #include <cxxabi.h>
#endif #endif
@ -59,7 +59,7 @@ inline std::string demangle(const std::type_info& id) {
while(found != std::string::npos) { while(found != std::string::npos) {
realname.erase(found, removals[r].size()); realname.erase(found, removals[r].size());
found = realname.find(removals[r]); found = realname.find(removals[r]);
} }
} }
for(std::size_t r = 0; r < replacements.size(); r+=2) { for(std::size_t r = 0; r < replacements.size(); r+=2) {

View File

@ -1,6 +1,6 @@
// The MIT License (MIT) // The MIT License (MIT)
// Copyright (c) 2013-2015 Danny Y., Rapptz // Copyright (c) 2013-2015 Rapptz and contributors
// Permission is hereby granted, free of charge, to any person obtaining a copy of // 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 // this software and associated documentation files (the "Software"), to deal in
@ -34,10 +34,10 @@
namespace sol { namespace sol {
namespace detail { namespace detail {
template <typename T> template <typename T>
struct SOL_DEPRECATED deprecate_type { struct SOL_DEPRECATED deprecate_type {
using type = T; using type = T;
}; };
} // detail } // detail
} // sol } // sol

View File

@ -1,6 +1,6 @@
// The MIT License (MIT) // The MIT License (MIT)
// Copyright (c) 2013-2015 Danny Y., Rapptz // Copyright (c) 2013-2015 Rapptz and contributors
// Permission is hereby granted, free of charge, to any person obtaining a copy of // 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 // this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,6 @@
// The MIT License (MIT) // The MIT License (MIT)
// Copyright (c) 2013-2015 Danny Y., Rapptz // Copyright (c) 2013-2015 Rapptz and contributors
// Permission is hereby granted, free of charge, to any person obtaining a copy of // 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 // this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,6 @@
// The MIT License (MIT) // The MIT License (MIT)
// Copyright (c) 2013-2015 Danny Y., Rapptz // Copyright (c) 2013-2015 Rapptz and contributors
// Permission is hereby granted, free of charge, to any person obtaining a copy of // 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 // this software and associated documentation files (the "Software"), to deal in
@ -47,7 +47,7 @@ struct functor {
functor(FxArgs&&... fxargs): item(nullptr), invocation(std::forward<FxArgs>(fxargs)...) {} functor(FxArgs&&... fxargs): item(nullptr), invocation(std::forward<FxArgs>(fxargs)...) {}
bool check () const { bool check () const {
return invocation != nullptr; return invocation != nullptr;
} }
template<typename... Args> template<typename... Args>

View File

@ -1,6 +1,6 @@
// The MIT License (MIT) // The MIT License (MIT)
// Copyright (c) 2013-2015 Danny Y., Rapptz // Copyright (c) 2013-2015 Rapptz and contributors
// Permission is hereby granted, free of charge, to any person obtaining a copy of // 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 // this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,10 @@
// The MIT License (MIT) // The MIT License (MIT)
<<<<<<< HEAD
// Copyright (c) 2013-2015 Danny Y., Rapptz // Copyright (c) 2013-2015 Danny Y., Rapptz
=======
// Copyright (c) 2013-2015 Rapptz and contributors
>>>>>>> root/develop
// Permission is hereby granted, free of charge, to any person obtaining a copy of // 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 // this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,10 @@
// The MIT License (MIT) // The MIT License (MIT)
<<<<<<< HEAD
// Copyright (c) 2013-2015 Danny Y., Rapptz // Copyright (c) 2013-2015 Danny Y., Rapptz
=======
// Copyright (c) 2013-2015 Rapptz and contributors
>>>>>>> root/develop
// Permission is hereby granted, free of charge, to any person obtaining a copy of // 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 // this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,6 @@
// The MIT License (MIT) // The MIT License (MIT)
// Copyright (c) 2013-2015 Danny Y., Rapptz // Copyright (c) 2013-2015 Rapptz and contributors
// Permission is hereby granted, free of charge, to any person obtaining a copy of // 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 // this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,10 @@
// The MIT License (MIT) // The MIT License (MIT)
<<<<<<< HEAD
// Copyright (c) 2013-2015 Danny Y., Rapptz // Copyright (c) 2013-2015 Danny Y., Rapptz
=======
// Copyright (c) 2013-2015 Rapptz and contributors
>>>>>>> root/develop
// Permission is hereby granted, free of charge, to any person obtaining a copy of // 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 // this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,6 @@
// The MIT License (MIT) // The MIT License (MIT)
// Copyright (c) 2013-2015 Danny Y., Rapptz // Copyright (c) 2013-2015 Rapptz and contributors
// Permission is hereby granted, free of charge, to any person obtaining a copy of // 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 // this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,6 @@
// The MIT License (MIT) // The MIT License (MIT)
// Copyright (c) 2013-2015 Danny Y., Rapptz // Copyright (c) 2013-2015 Rapptz and contributors
// Permission is hereby granted, free of charge, to any person obtaining a copy of // 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 // this software and associated documentation files (the "Software"), to deal in
@ -25,7 +25,6 @@
#include "table_core.hpp" #include "table_core.hpp"
namespace sol { namespace sol {
typedef table_core<false> table; typedef table_core<false> } // sol
} // sol
#endif // SOL_TABLE_HPP #endif // SOL_TABLE_HPP

View File

@ -1,6 +1,6 @@
// The MIT License (MIT) // The MIT License (MIT)
// Copyright (c) 2013-2015 Danny Y., Rapptz // Copyright (c) 2013-2015 Rapptz and contributors
// Permission is hereby granted, free of charge, to any person obtaining a copy of // 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 // this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,6 @@
// The MIT License (MIT) // The MIT License (MIT)
// Copyright (c) 2013-2015 Danny Y., Rapptz // Copyright (c) 2013-2015 Rapptz and contributors
// Permission is hereby granted, free of charge, to any person obtaining a copy of // 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 // this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,6 @@
// The MIT License (MIT) // The MIT License (MIT)
// Copyright (c) 2013-2015 Danny Y., Rapptz // Copyright (c) 2013-2015 Rapptz and contributors
// Permission is hereby granted, free of charge, to any person obtaining a copy of // 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 // this software and associated documentation files (the "Software"), to deal in
@ -25,6 +25,7 @@
#include "compatibility.hpp" #include "compatibility.hpp"
#include "traits.hpp" #include "traits.hpp"
#include <string> #include <string>
#include "traits.hpp"
namespace sol { namespace sol {
struct nil_t {}; struct nil_t {};
@ -32,6 +33,9 @@ const nil_t nil {};
inline bool operator==(nil_t, nil_t) { return true; } inline bool operator==(nil_t, nil_t) { return true; }
inline bool operator!=(nil_t, nil_t) { return false; } inline bool operator!=(nil_t, nil_t) { return false; }
struct void_type : types<void> {}; // This is important because it allows myobject.call( Void, ... ) to work
const void_type Void {};
template<typename... T> template<typename... T>
struct function_sig_t {}; struct function_sig_t {};
using function_t = function_sig_t<>; using function_t = function_sig_t<>;

View File

@ -1,6 +1,6 @@
// The MIT License (MIT) // The MIT License (MIT)
// Copyright (c) 2013-2015 Danny Y., Rapptz // Copyright (c) 2013-2015 Rapptz and contributors
// Permission is hereby granted, free of charge, to any person obtaining a copy of // 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 // this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,6 @@
// The MIT License (MIT) // The MIT License (MIT)
// Copyright (c) 2013-2015 Danny Y., Rapptz // Copyright (c) 2013-2015 Rapptz and contributors
// Permission is hereby granted, free of charge, to any person obtaining a copy of // 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 // this software and associated documentation files (the "Software"), to deal in