mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Fixes #580
Adds some code for #579 to warn of bad errors Update documentation and examples, as well as fix fPIC with static builds on Linux
This commit is contained in:
parent
dcb2b22ea6
commit
2e648638ef
|
@ -83,11 +83,11 @@ endif()
|
|||
# # # General project output locations
|
||||
if (PLATFORM MATCHES "x86" OR CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/x86/lib")
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/x86/lib")
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/x86/bin")
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/x86/bin")
|
||||
else()
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/x64/lib")
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/x64/lib")
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/x64/bin")
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/x64/bin")
|
||||
endif()
|
||||
|
||||
|
@ -174,7 +174,7 @@ set(SOL2_DOCS_FOUND FALSE)
|
|||
if (PYTHONINTERP_FOUND)
|
||||
if (SINGLE)
|
||||
set(SOL2_SINGLE_FOUND TRUE)
|
||||
add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/include/single/sol/sol.hpp" "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/include/single/sol/sol_forward.hpp"
|
||||
add_custom_command(OUTPUT include/single/sol/sol.hpp "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/include/single/sol/sol_forward.hpp"
|
||||
COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_SOURCE_DIR}/single.py" --output "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/include/single/sol/sol.hpp"
|
||||
DEPENDS ${SOL2_HEADER_SOURCES})
|
||||
add_custom_target(sol2_single_header
|
||||
|
|
|
@ -183,14 +183,16 @@ else ()
|
|||
# we can simply reuse the makefile here
|
||||
# so define it as an external project and then just have the proper
|
||||
# build/install/test commands
|
||||
# make sure to apply -pagezero_size 10000 -image_base 100000000
|
||||
# make sure to apply -pagezero_size 10000 -image_base 100000000 (done later for XCode Targets)
|
||||
set(LUA_JIT_MAKE_BUILD_MODIFICATIONS "LUAJIT_T=${LUA_JIT_EXE_FILENAME}")
|
||||
list(APPEND LUA_JIT_MAKE_BUILD_MODIFICATIONS "LUAJIT_A=${LUA_JIT_LIB_FILENAME}")
|
||||
set(LUA_JIT_MAKE_CFLAGS_MODIFICATIONS "CFLAGS= ")
|
||||
if (BUILD_LUA_AS_DLL)
|
||||
list(APPEND LUA_JIT_MAKE_BUILD_MODIFICATIONS "LUAJIT_SO=${LUA_JIT_DLL_FILENAME}" "TARGET_SONAME=${LUA_JIT_DLL_FILENAME}" "TARGET_DYLIBNAME=${LUA_JIT_DLL_FILENAME}" "TARGET_DLLNAME=${LUA_JIT_DLL_FILENAME}")
|
||||
list(APPEND LUA_JIT_MAKE_BUILD_MODIFICATIONS "BUILDMODE=dynamic")
|
||||
else()
|
||||
list(APPEND LUA_JIT_MAKE_BUILD_MODIFICATIONS "BUILDMODE=static")
|
||||
set(LUA_JIT_MAKE_CFLAGS_MODIFICATIONS "${LUA_JIT_MAKE_CFLAGS_MODIFICATIONS}-fPIC ")
|
||||
endif()
|
||||
|
||||
set(LUA_JIT_PREBUILT_DLL ${LUA_JIT_DLL_FILENAME})
|
||||
|
@ -201,9 +203,10 @@ else ()
|
|||
list(APPEND LUA_JIT_MAKE_BUILD_MODIFICATIONS "HOST_SYS=Windows" "TARGET_SYS=Windows")
|
||||
endif()
|
||||
if (PLATFORM MATCHES "x86")
|
||||
list(APPEND LUA_JIT_MAKE_BUILD_MODIFICATIONS "CFLAGS=-m32" "LDFLAGS=-m32")
|
||||
set(LUA_JIT_MAKE_CFLAGS_MODIFICATIONS "${LUA_JIT_MAKE_CFLAGS_MODIFICATIONS}-m32 ")
|
||||
endif()
|
||||
|
||||
list(APPEND LUA_JIT_MAKE_BUILD_MODIFICATIONS ${LUA_JIT_MAKE_CFLAGS_MODIFICATIONS})
|
||||
|
||||
set(LUA_JIT_BUILD_COMMAND BUILD_COMMAND "${MAKE_PROGRAM}" ${LUA_JIT_MAKE_BUILD_MODIFICATIONS})
|
||||
endif()
|
||||
|
||||
|
|
|
@ -44,4 +44,130 @@ Lua - Lua.org:
|
|||
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.
|
||||
|
||||
|
||||
.. _MIT: http://opensource.org/licenses/MIT
|
||||
ogonek - libogonek/ogonek:
|
||||
--------------------------
|
||||
|
||||
Creative Commons Legal Code
|
||||
|
||||
CC0 1.0 Universal
|
||||
|
||||
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
||||
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
||||
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
||||
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
||||
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
||||
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
||||
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
||||
HEREUNDER.
|
||||
|
||||
Statement of Purpose
|
||||
|
||||
The laws of most jurisdictions throughout the world automatically confer
|
||||
exclusive Copyright and Related Rights (defined below) upon the creator
|
||||
and subsequent owner(s) (each and all, an "owner") of an original work of
|
||||
authorship and/or a database (each, a "Work").
|
||||
|
||||
Certain owners wish to permanently relinquish those rights to a Work for
|
||||
the purpose of contributing to a commons of creative, cultural and
|
||||
scientific works ("Commons") that the public can reliably and without fear
|
||||
of later claims of infringement build upon, modify, incorporate in other
|
||||
works, reuse and redistribute as freely as possible in any form whatsoever
|
||||
and for any purposes, including without limitation commercial purposes.
|
||||
These owners may contribute to the Commons to promote the ideal of a free
|
||||
culture and the further production of creative, cultural and scientific
|
||||
works, or to gain reputation or greater distribution for their Work in
|
||||
part through the use and efforts of others.
|
||||
|
||||
For these and/or other purposes and motivations, and without any
|
||||
expectation of additional consideration or compensation, the person
|
||||
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
||||
is an owner of Copyright and Related Rights in the Work, voluntarily
|
||||
elects to apply CC0 to the Work and publicly distribute the Work under its
|
||||
terms, with knowledge of his or her Copyright and Related Rights in the
|
||||
Work and the meaning and intended legal effect of CC0 on those rights.
|
||||
|
||||
1. Copyright and Related Rights. A Work made available under CC0 may be
|
||||
protected by copyright and related or neighboring rights ("Copyright and
|
||||
Related Rights"). Copyright and Related Rights include, but are not
|
||||
limited to, the following:
|
||||
|
||||
i. the right to reproduce, adapt, distribute, perform, display,
|
||||
communicate, and translate a Work;
|
||||
ii. moral rights retained by the original author(s) and/or performer(s);
|
||||
iii. publicity and privacy rights pertaining to a person's image or
|
||||
likeness depicted in a Work;
|
||||
iv. rights protecting against unfair competition in regards to a Work,
|
||||
subject to the limitations in paragraph 4(a), below;
|
||||
v. rights protecting the extraction, dissemination, use and reuse of data
|
||||
in a Work;
|
||||
vi. database rights (such as those arising under Directive 96/9/EC of the
|
||||
European Parliament and of the Council of 11 March 1996 on the legal
|
||||
protection of databases, and under any national implementation
|
||||
thereof, including any amended or successor version of such
|
||||
directive); and
|
||||
vii. other similar, equivalent or corresponding rights throughout the
|
||||
world based on applicable law or treaty, and any national
|
||||
implementations thereof.
|
||||
|
||||
2. Waiver. To the greatest extent permitted by, but not in contravention
|
||||
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
||||
irrevocably and unconditionally waives, abandons, and surrenders all of
|
||||
Affirmer's Copyright and Related Rights and associated claims and causes
|
||||
of action, whether now known or unknown (including existing as well as
|
||||
future claims and causes of action), in the Work (i) in all territories
|
||||
worldwide, (ii) for the maximum duration provided by applicable law or
|
||||
treaty (including future time extensions), (iii) in any current or future
|
||||
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
||||
including without limitation commercial, advertising or promotional
|
||||
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
||||
member of the public at large and to the detriment of Affirmer's heirs and
|
||||
successors, fully intending that such Waiver shall not be subject to
|
||||
revocation, rescission, cancellation, termination, or any other legal or
|
||||
equitable action to disrupt the quiet enjoyment of the Work by the public
|
||||
as contemplated by Affirmer's express Statement of Purpose.
|
||||
|
||||
3. Public License Fallback. Should any part of the Waiver for any reason
|
||||
be judged legally invalid or ineffective under applicable law, then the
|
||||
Waiver shall be preserved to the maximum extent permitted taking into
|
||||
account Affirmer's express Statement of Purpose. In addition, to the
|
||||
extent the Waiver is so judged Affirmer hereby grants to each affected
|
||||
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
||||
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
||||
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
||||
maximum duration provided by applicable law or treaty (including future
|
||||
time extensions), (iii) in any current or future medium and for any number
|
||||
of copies, and (iv) for any purpose whatsoever, including without
|
||||
limitation commercial, advertising or promotional purposes (the
|
||||
"License"). The License shall be deemed effective as of the date CC0 was
|
||||
applied by Affirmer to the Work. Should any part of the License for any
|
||||
reason be judged legally invalid or ineffective under applicable law, such
|
||||
partial invalidity or ineffectiveness shall not invalidate the remainder
|
||||
of the License, and in such case Affirmer hereby affirms that he or she
|
||||
will not (i) exercise any of his or her remaining Copyright and Related
|
||||
Rights in the Work or (ii) assert any associated claims and causes of
|
||||
action with respect to the Work, in either case contrary to Affirmer's
|
||||
express Statement of Purpose.
|
||||
|
||||
4. Limitations and Disclaimers.
|
||||
|
||||
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
||||
surrendered, licensed or otherwise affected by this document.
|
||||
b. Affirmer offers the Work as-is and makes no representations or
|
||||
warranties of any kind concerning the Work, express, implied,
|
||||
statutory or otherwise, including without limitation warranties of
|
||||
title, merchantability, fitness for a particular purpose, non
|
||||
infringement, or the absence of latent or other defects, accuracy, or
|
||||
the present or absence of errors, whether or not discoverable, all to
|
||||
the greatest extent permissible under applicable law.
|
||||
c. Affirmer disclaims responsibility for clearing rights of other persons
|
||||
that may apply to the Work or any use thereof, including without
|
||||
limitation any person's Copyright and Related Rights in the Work.
|
||||
Further, Affirmer disclaims responsibility for obtaining any necessary
|
||||
consents, permissions or other rights required for any use of the
|
||||
Work.
|
||||
d. Affirmer understands and acknowledges that Creative Commons is not a
|
||||
party to this document and has no duty or obligation with respect to
|
||||
this CC0 or use of the Work.
|
||||
|
||||
|
||||
.. _MIT: http://opensource.org/licenses/MIT
|
||||
|
|
|
@ -216,7 +216,7 @@ Is set as a :doc:`userdata + usertype<../api/usertype>`.
|
|||
|
||||
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/userdata.cpp
|
||||
:linenos:
|
||||
:lines: 1-57
|
||||
:lines: 1-57,97-
|
||||
|
||||
``std::unique_ptr``/``std::shared_ptr``'s reference counts / deleters will :doc:`be respected<../api/unique_usertype_traits>`.
|
||||
|
||||
|
@ -236,7 +236,7 @@ You can retrieve the userdata in the same way as everything else. Importantly, n
|
|||
C++ classes put into Lua
|
||||
------------------------
|
||||
|
||||
See this :doc:`section here<cxx-in-lua>` and after perhaps see if :doc:`simple usertypes suit your needs<../api/simple_usertype>`. Also check out some `a basic example`_, `special functions`_ and `initializers`_,
|
||||
See this :doc:`section here<cxx-in-lua>`. Also check out a `basic example`_, `special functions example`_ and `initializers example`_! There are many more examples that show off the usage of classes in C++, so please peruse them all carefully as it can be as simple or as complex as your needs are.
|
||||
|
||||
|
||||
.. _namespacing:
|
||||
|
|
|
@ -22,6 +22,18 @@
|
|||
|
||||
# # # sol2 Examples
|
||||
|
||||
# # require_from_dll example
|
||||
# just add the subdirectory
|
||||
add_subdirectory(require_dll_example)
|
||||
|
||||
# # interop examples
|
||||
#add_subdirectory(interop/kaguya)
|
||||
#add_subdirectory(interop/tolua)
|
||||
#add_subdirectory(interop/LuaBridge)
|
||||
#add_subdirectory(interop/luwra)
|
||||
|
||||
# # single-source compilable examples
|
||||
|
||||
file(GLOB EXAMPLES_SRC *.cpp tutorials/quick_n_dirty/*.cpp)
|
||||
source_group(examples FILES ${EXAMPLES_SRC})
|
||||
|
||||
|
@ -74,8 +86,6 @@ function (MAKE_EXAMPLE example_source_file is_single)
|
|||
install(TARGETS ${example_name} RUNTIME DESTINATION bin)
|
||||
endfunction(MAKE_EXAMPLE)
|
||||
|
||||
add_subdirectory(require_dll_example)
|
||||
|
||||
foreach(example_source_file ${EXAMPLES_SRC})
|
||||
MAKE_EXAMPLE(${example_source_file} FALSE)
|
||||
endforeach()
|
||||
|
|
|
@ -48,7 +48,7 @@ function(make_require_from_dll_example target_lib is_single)
|
|||
target_compile_features(${example_lib_name} PRIVATE ${CXX_FEATURES})
|
||||
target_compile_definitions(${example_lib_name} PUBLIC MY_OBJECT_DLL PRIVATE MY_OBJECT_BUILD)
|
||||
if(CMAKE_DL_LIBS)
|
||||
target_link_libraries(${example_lib_name} PRIVATE ${CMAKE_DL_LIBS})
|
||||
target_link_libraries(${example_lib_name} PUBLIC ${CMAKE_DL_LIBS})
|
||||
endif()
|
||||
if (CI)
|
||||
target_compile_definitions(${example_lib_name} PRIVATE SOL2_CI)
|
||||
|
@ -88,7 +88,8 @@ function(make_require_from_dll_example target_lib is_single)
|
|||
|
||||
if (TESTS_EXAMPLES)
|
||||
if ((NOT is_single) OR (is_single AND TESTS_SINGLE))
|
||||
add_test(NAME ${example_name} COMMAND ${example_name})
|
||||
get_target_property(example_working_dir ${example_name} RUNTIME_OUTPUT_DIRECTORY)
|
||||
add_test(NAME ${example_name} COMMAND ${example_name} WORKING_DIRECTORY "${example_working_dir}")
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
|
|
@ -77,18 +77,48 @@ namespace sol {
|
|||
type t = type_of(L, result.stack_index());
|
||||
std::string err = "sol: ";
|
||||
err += to_string(result.status());
|
||||
err += " error:";
|
||||
err += " error";
|
||||
#ifndef SOL_NO_EXCEPTIONS
|
||||
std::exception_ptr eptr = std::current_exception();
|
||||
if (eptr) {
|
||||
err += " with a ";
|
||||
try {
|
||||
std::rethrow_exception(eptr);
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
err += "std::exception -- ";
|
||||
err.append(ex.what());
|
||||
}
|
||||
catch (const std::string& message) {
|
||||
err += "thrown message -- ";
|
||||
err.append(message);
|
||||
}
|
||||
catch (const char* message) {
|
||||
err += "thrown message -- ";
|
||||
err.append(message);
|
||||
}
|
||||
catch (...) {
|
||||
err.append("thrown but unknown type, cannot serialize into error message");
|
||||
}
|
||||
}
|
||||
#endif // serialize exception information if possible
|
||||
if (t == type::string) {
|
||||
err += " ";
|
||||
err += ": ";
|
||||
string_view serr = stack::get<string_view>(L, result.stack_index());
|
||||
err.append(serr.data(), serr.size());
|
||||
}
|
||||
#ifdef SOL_NO_EXCEPTIONS
|
||||
// replacing information of stack error into pfr
|
||||
if (t != type::none) {
|
||||
lua_pop(L, 1);
|
||||
int target = result.stack_index();
|
||||
if (result.pop_count() > 0) {
|
||||
stack::remove(L, target, result.pop_count());
|
||||
}
|
||||
int pushed = stack::push(L, err);
|
||||
int top = lua_gettop(L);
|
||||
int towards = top - target;
|
||||
if (towards != 0) {
|
||||
lua_rotate(L, top, towards);
|
||||
}
|
||||
stack::push(L, err);
|
||||
#else
|
||||
// just throw our error
|
||||
throw error(detail::direct_error, err);
|
||||
|
|
|
@ -640,7 +640,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
inline const std::string& to_string(call_status c) {
|
||||
static const std::array<std::string, 8> names{ {
|
||||
static const std::array<std::string, 10> names{ {
|
||||
"ok",
|
||||
"yielded",
|
||||
"runtime",
|
||||
|
@ -649,6 +649,8 @@ namespace sol {
|
|||
"gc",
|
||||
"syntax",
|
||||
"file",
|
||||
"CRITICAL_EXCEPTION_FAILURE",
|
||||
"CRITICAL_INDETERMINATE_STATE_FAILURE"
|
||||
} };
|
||||
switch (c) {
|
||||
case call_status::ok:
|
||||
|
@ -668,16 +670,37 @@ namespace sol {
|
|||
case call_status::file:
|
||||
return names[7];
|
||||
}
|
||||
return names[0];
|
||||
if (static_cast<std::ptrdiff_t>(c) == -1) {
|
||||
// One of the many cases where a critical exception error has occurred
|
||||
return names[8];
|
||||
}
|
||||
return names[9];
|
||||
}
|
||||
|
||||
inline bool is_indeterminate_call_failure(call_status c) {
|
||||
switch (c) {
|
||||
case call_status::ok:
|
||||
case call_status::yielded:
|
||||
case call_status::runtime:
|
||||
case call_status::memory:
|
||||
case call_status::handler:
|
||||
case call_status::gc:
|
||||
case call_status::syntax:
|
||||
case call_status::file:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline const std::string& to_string(load_status c) {
|
||||
static const std::array<std::string, 8> names{ {
|
||||
static const std::array<std::string, 7> names{ {
|
||||
"ok",
|
||||
"memory",
|
||||
"gc",
|
||||
"syntax",
|
||||
"file",
|
||||
"CRITICAL_EXCEPTION_FAILURE",
|
||||
"CRITICAL_INDETERMINATE_STATE_FAILURE"
|
||||
} };
|
||||
switch (c) {
|
||||
case load_status::ok:
|
||||
|
@ -691,7 +714,11 @@ namespace sol {
|
|||
case load_status::file:
|
||||
return names[4];
|
||||
}
|
||||
return names[0];
|
||||
if (static_cast<int>(c) == -1) {
|
||||
// One of the many cases where a critical exception error has occurred
|
||||
return names[5];
|
||||
}
|
||||
return names[6];
|
||||
}
|
||||
|
||||
inline const std::string& to_string(load_mode c) {
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
namespace sol {
|
||||
namespace usertype_detail {
|
||||
#ifdef SOL_USE_BOOST
|
||||
template <typename K, typename V, typename H = std::hash<K>, typename E = std::equal_to<>>
|
||||
template <typename K, typename V, typename H = boost::hash<K>, typename E = std::equal_to<>>
|
||||
using map_t = boost::unordered_map<K, V, H, E>;
|
||||
#else
|
||||
template <typename K, typename V, typename H = std::hash<K>, typename E = std::equal_to<>>
|
||||
|
|
Loading…
Reference in New Issue
Block a user