diff --git a/.travis.yml b/.travis.yml index 7333e3b0..6a103736 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,12 @@ addons: apt: sources: - ubuntu-toolchain-r-test + - llvm-toolchain-trusty-5.0 + - sourceline: 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-5.0 main' + key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' packages: - - g++-4.9 - - g++-5 - - g++-6 + - g++-7 + - g++-8 coverity_scan: project: name: "ChaiScript/ChaiScript" @@ -22,7 +24,7 @@ matrix: include: - os: linux sudo: false - env: GCC_VER="4.9" + env: GCC_VER="7" compiler: gcc # - os: linux #sudo: false @@ -30,19 +32,20 @@ matrix: #compiler: gcc - os: linux sudo: false - env: GCC_VER="5" CPPCHECK=1 CMAKE_OPTIONS="-D RUN_FUZZY_TESTS:BOOL=TRUE" + env: GCC_VER="7" CPPCHECK=1 CMAKE_OPTIONS="-D RUN_FUZZY_TESTS:BOOL=TRUE" compiler: gcc - os: linux sudo: false - env: GCC_VER="6" CPPCHECK=1 COVERAGE=1 CMAKE_OPTIONS="-D RUN_FUZZY_TESTS:BOOL=TRUE" + env: GCC_VER="8" CPPCHECK=1 COVERAGE=1 CMAKE_OPTIONS="-D RUN_FUZZY_TESTS:BOOL=TRUE" compiler: gcc - - os: osx - compiler: clang - osx_image: xcode8 - - os: osx - compiler: clang - osx_image: xcode8 - env: CMAKE_OPTIONS="-D DYNLOAD_ENABLED:BOOL=FALSE -D MULTITHREAD_SUPPORT_ENABLED:BOOL=FALSE -D USE_STD_MAKE_SHARED:BOOL=TRUE" BUILD_ONLY=1 + #- os: osx + # compiler: clang + # osx_image: xcode10 + # env: CLANG_VER="5.0" + #- os: osx + # compiler: clang + # osx_image: xcode10 + # env: CLANG_VER="5.0" CMAKE_OPTIONS="-D DYNLOAD_ENABLED:BOOL=FALSE -D MULTITHREAD_SUPPORT_ENABLED:BOOL=FALSE -D USE_STD_MAKE_SHARED:BOOL=TRUE" BUILD_ONLY=1 env: global: @@ -52,6 +55,7 @@ env: before_install: - if [ "${GCC_VER}" != "" ]; then export CXX="g++-$GCC_VER" CC="gcc-$GCC_VER" GCOV="gcov-$GCC_VER" ; fi + #- if [ "${CLANG_VER}" != "" ]; then export CXX="clang++-$CLANG_VER"; fi - pip install --user cpp-coveralls script: diff --git a/CMakeLists.txt b/CMakeLists.txt index 3cfec822..7e1e754b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,9 @@ if(NOT ${CMAKE_VERSION} VERSION_LESS "3.1") cmake_policy(SET CMP0054 NEW) endif() +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + project(chaiscript) option(MULTITHREAD_SUPPORT_ENABLED "Multithreaded Support Enabled" TRUE) @@ -423,7 +426,7 @@ if(BUILD_TESTING) target_link_libraries(multifile_test ${LIBS}) add_test(NAME MultiFile_Test COMMAND multifile_test) - install(TARGETS test_module RUNTIME DESTINATION bin LIBRARY DESTINATION lib/chaiscript) + install(TARGETS test_module RUNTIME DESTINATION bin LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/chaiscript") endif() endif() @@ -436,7 +439,7 @@ if(BUILD_LIBFUZZ_TESTER) endif() -install(TARGETS chai chaiscript_stdlib-${CHAI_VERSION} ${MODULES} RUNTIME DESTINATION bin LIBRARY DESTINATION lib/chaiscript) +install(TARGETS chai chaiscript_stdlib-${CHAI_VERSION} ${MODULES} RUNTIME DESTINATION bin LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/chaiscript") install(DIRECTORY include/chaiscript DESTINATION include PATTERN "*.hpp" @@ -457,6 +460,6 @@ install(DIRECTORY samples DESTINATION share/chaiscript configure_file(contrib/pkgconfig/chaiscript.pc.in lib/pkgconfig/chaiscript.pc @ONLY) install(FILES "${chaiscript_BINARY_DIR}/lib/pkgconfig/chaiscript.pc" - DESTINATION lib/pkgconfig) + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") diff --git a/appveyor.yml b/appveyor.yml index 19187929..a5528862 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,10 +1,9 @@ version: 6.1.x.{build} -image: - - Visual Studio 2017 +image: + - Visual Studio 2017 environment: matrix: - - VS_VERSION: "Visual Studio 14" - - VS_VERSION: "Visual Studio 15" + - VS_VERSION: "Visual Studio 15" build_script: - cmd: >- mkdir build diff --git a/cheatsheet.md b/cheatsheet.md index 907fe329..27669a23 100644 --- a/cheatsheet.md +++ b/cheatsheet.md @@ -11,20 +11,18 @@ ChaiScript tries to follow the [Semantic Versioning](http://semver.org/) scheme. # Initializing ChaiScript ``` -chaiscript::ChaiScript chai; // loads stdlib from loadable module on file system -chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); // compiles in stdlib +chaiscript::ChaiScript chai; // initializes ChaiScript, adding the standard ChaiScript types (map, string, ...) ``` Note that ChaiScript cannot be used as a global / static object unless it is being compiled with `CHAISCRIPT_NO_THREADS`. - # Adding Things To The Engine ## Adding a Function / Method / Member ### General -``` +```cpp chai.add(chaiscript::fun(&function_name), "function_name"); chai.add(chaiscript::fun(&Class::method_name), "method_name"); chai.add(chaiscript::fun(&Class::member_name), "member_name"); @@ -32,7 +30,7 @@ chai.add(chaiscript::fun(&Class::member_name), "member_name"); ### Bound Member Functions -``` +```cpp chai.add(chaiscript::fun(&Class::method_name, Class_instance_ptr), "method_name"); chai.add(chaiscript::fun(&Class::member_name, Class_instance_ptr), "member_name"); ``` @@ -41,18 +39,18 @@ chai.add(chaiscript::fun(&Class::member_name, Class_instance_ptr), "member_name" #### Preferred -``` +```cpp chai.add(chaiscript::fun(&function_with_overloads), "function_name"); ``` #### Alternative -``` +```cpp chai.add(chaiscript::fun(std::static_cast(&function_with_overloads)), "function_name"); ``` This overload technique is also used when exposing base member using derived type -``` +```cpp struct Base { int data; @@ -66,9 +64,9 @@ chai.add(chaiscript::fun(static_cast(&Derived::data)), "data"); ### Lambda -``` +```cpp chai.add( - chaiscript::fun( + chaiscript::fun>( [](bool type) { if (type) { return "x"; } else { return "y"; } @@ -77,7 +75,7 @@ chai.add( ### Constructors -``` +```cpp chai.add(chaiscript::constructor(), "MyType"); chai.add(chaiscript::constructor(), "MyType"); ``` @@ -86,7 +84,7 @@ chai.add(chaiscript::constructor(), "MyType"); It's not strictly necessary to add types, but it helps with many things. Cloning, better errors, etc. -``` +```cpp chai.add(chaiscript::user_type(), "MyClass"); ``` @@ -109,27 +107,27 @@ add_type_conversion(type("string"), type("Type_Info"), fun(s) { return type(s); Invoking a C++ type conversion possible with `static_cast` -``` +```cpp chai.add(chaiscript::type_conversion()); ``` Calling a user defined type conversion that takes a lambda -``` +```cpp chai.add(chaiscript::type_conversion([](const TestBaseType &t_bt) { /* return converted thing */ })); ``` ### Class Hierarchies -If you want objects to be convertable between base and derived classes, you must tell ChaiScritp about the relationship. +If you want objects to be convertable between base and derived classes, you must tell ChaiScript about the relationship. -``` +```cpp chai.add(chaiscript::base_class()); ``` If you have multiple classes in your inheritance graph, you will probably want to tell ChaiScript about all relationships. -``` +```cpp chai.add(chaiscript::base_class()); chai.add(chaiscript::base_class()); chai.add(chaiscript::base_class()); @@ -170,7 +168,8 @@ chai.set_global(chaiscript::var(somevar), "somevar"); // global non-const, overw Namespaces will not be populated until `import` is called. This saves memory and computing costs if a namespace is not imported into every ChaiScript instance. -``` + +```cpp chai.register_namespace([](chaiscript::Namespace& math) { math["pi"] = chaiscript::const_var(3.14159); math["sin"] = chaiscript::var(chaiscript::fun([](const double x) { return sin(x); })); }, @@ -186,7 +185,7 @@ print(math.pi) // prints 3.14159 # Using STL ChaiScript recognize many types from STL, but you have to add specific instantiation yourself. -``` +```cpp typedef std::vector> data_list; data_list my_list{ make_pair(0, "Hello"), make_pair(1, "World") }; chai.add(chaiscript::bootstrap::standard_library::vector_type("DataList")); @@ -204,7 +203,7 @@ chai.eval(R"_( ## General -``` +```cpp chai.eval("print(\"Hello World\")"); chai.eval(R"(print("Hello World"))"); ``` @@ -215,13 +214,13 @@ Returns values are of the type `Boxed_Value` which is meant to be opaque to the ### Prefered -``` +```cpp chai.eval("5.3 + 2.1"); // returns 7.4 as a C++ double ``` ### Alternative -``` +```cpp auto v = chai.eval("5.3 + 2.1"); chai.boxed_cast(v); // extracts double value from boxed_value and applies known conversions chaiscript::boxed_cast(v); // free function version, does not know about conversions @@ -229,7 +228,7 @@ chaiscript::boxed_cast(v); // free function version, does not know about ### Converting Between Algebraic Types -``` +```cpp chaiscript::Boxed_Number(chai.eval("5.3 + 2.1")).get_as(); // works with any number type // which is equivalent to, but much more automatic than: static_cast(chai.eval("5.3+2.1")); // this version only works if we know that it's a double @@ -259,7 +258,7 @@ int main() ## Sharing Values -``` +```cpp double &d = chai.eval("var i = 5.2; i"); // d is now a reference to i in the script std::shared_ptr d = chai.eval("var i = 5.2; i"); // same result but reference counted @@ -269,7 +268,7 @@ chai.eval("print(i)"); // prints 3 ## Catching Eval Errors -``` +```cpp try { chai.eval("2.3 + \"String\""); } catch (const chaiscript::exception::eval_error &e) { @@ -279,7 +278,7 @@ try { ## Catching Errors Thrown From Script -``` +```cpp try { chai.eval("throw(runtime_error(\"error\"))", chaiscript::exception_specification()); } catch (const double e) { @@ -294,19 +293,19 @@ try { ## Sharing Functions -``` +```cpp auto p = chai.eval>("to_string"); p(5); // calls chaiscript's 'to_string' function, returning std::string("5") ``` Note: backtick treats operators as normal functions -``` +```cpp auto p = chai.eval>(`+`); p(5, 6); // calls chaiscript's '+' function, returning 11 ``` -``` +```cpp auto p = chai.eval>("fun(x,y) { to_string(x) + to_string(y); }"); p(3,4.2); // evaluates the lambda function, returning the string "34.2" to C++ ``` @@ -391,11 +390,23 @@ switch (myvalue) { ## Built in Types +There are a number of build-in types that are part of ChaiScript. + +### Vectors and Maps + ``` var v = [1,2,3u,4ll,"16", `+`]; // creates vector of heterogenous values var m = ["a":1, "b":2]; // map of string:value pairs + +// Add a value to the vector by value. +v.push_back(123); + +// Add an object to the vector by reference. +v.push_back_ref(m); ``` +### Numbers + Floating point values default to `double` type and integers default to `int` type. All C++ suffixes such as `f`, `ll`, `u` as well as scientific notation are supported @@ -566,28 +577,11 @@ If both a 2 parameter and a 3 parameter signature match, the 3 parameter functio * `__LINE__` Current file line number * `__FILE__` Full path of current file * `__CLASS__` Name of current class - * `__FUNC__` Mame of current function + * `__FUNC__` Name of current function # Built In Functions -## Disabling Built-Ins - -When constructing a ChaiScript object, a vector of parameters can be passed in to disable or enable various built-in methods. - -Current options: - -``` -enum class Options -{ - Load_Modules, - No_Load_Modules, - External_Scripts, - No_External_Scripts -}; -``` - - ## Evaluation ``` @@ -603,3 +597,6 @@ Both `use` and `eval_file` search the 'usepaths' passed to the ChaiScript constr * `from_json` converts a JSON string into its strongly typed (map, vector, int, double, string) representations * `to_json` converts a ChaiScript object (either a `Object` or one of map, vector, int, double, string) tree into its JSON string representation + +## Extras +ChaiScript itself does not provide a link to the math functions defined in ``. You can either add them yourself, or use the [ChaiScript_Extras](https://github.com/ChaiScript/ChaiScript_Extras) helper library. (Which also provides some additional string functions.) diff --git a/include/chaiscript/chaiscript_threading.hpp b/include/chaiscript/chaiscript_threading.hpp index 3875f9cf..9bfa44fc 100644 --- a/include/chaiscript/chaiscript_threading.hpp +++ b/include/chaiscript/chaiscript_threading.hpp @@ -107,7 +107,7 @@ namespace chaiscript /// does there is no possible way to recover static std::unordered_map &t() noexcept { - thread_local std::unordered_map my_t; + static thread_local std::unordered_map my_t; return my_t; } }; diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 2a68341c..702d5cbc 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -156,7 +156,7 @@ namespace chaiscript m_engine.add(fun( - [=](const dispatch::Proxy_Function_Base &t_fun, const std::vector &t_params) -> Boxed_Value { + [this](const dispatch::Proxy_Function_Base &t_fun, const std::vector &t_params) -> Boxed_Value { Type_Conversions_State s(this->m_engine.conversions(), this->m_engine.conversions().conversion_saves()); return t_fun(Function_Params{t_params}, s); }), "call"); @@ -168,7 +168,7 @@ namespace chaiscript m_engine.add(fun([this](const std::string &t_type_name){ return m_engine.get_type(t_type_name, true); }), "type"); m_engine.add(fun( - [=](const Type_Info &t_from, const Type_Info &t_to, const std::function &t_func) { + [this](const Type_Info &t_from, const Type_Info &t_to, const std::function &t_func) { m_engine.add(chaiscript::type_conversion(t_from, t_to, t_func)); } ), "add_type_conversion"); @@ -386,9 +386,9 @@ namespace chaiscript } - /// \brief Loads and parses a file. If the file is already, it is not reloaded - /// The use paths specified at ChaiScript construction time are searched for the - /// requested file. + /// \brief Loads and parses a file. If the file is already open, it is not + /// reloaded. The use paths specified at ChaiScript construction time are + /// searched for the requested file. /// /// \param[in] t_filename Filename to load and evaluate Boxed_Value use(const std::string &t_filename) diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 52110bde..d38e5aa3 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -331,7 +331,6 @@ namespace chaiscript Boxed_Value fn(this->children[0]->eval(t_ss)); - using ConstFunctionTypePtr = const dispatch::Proxy_Function_Base *; try { return (*t_ss->boxed_cast(fn))(Function_Params{params}, t_ss.conversions()); } diff --git a/readme.md b/readme.md index 8323a128..88f8a516 100644 --- a/readme.md +++ b/readme.md @@ -29,7 +29,7 @@ Introduction ChaiScript is one of the only embedded scripting language designed from the ground up to directly target C++ and take advantage of modern C++ development -techniques, working with the developer like he expects it to work. Being a +techniques, working with the developer how they would expect it to work. Being a native C++ application, it has some advantages over existing embedded scripting languages: @@ -48,6 +48,19 @@ templates. It has been tested with gcc 4.9 and clang 3.6 (with libcxx). For more information see the build [dashboard](http://chaiscript.com/ChaiScript-BuildResults/index.html). +Installation using vcpkg +======================== + +You can download and install ChaiScript using the [vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager: + + git clone https://github.com/Microsoft/vcpkg.git + cd vcpkg + ./bootstrap-vcpkg.sh + ./vcpkg integrate install + vcpkg install chaiscript + +The ChaiScript port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository. + Usage ===== diff --git a/releasenotes.md b/releasenotes.md index cdccd888..a622566e 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -5,6 +5,9 @@ Current Version: 6.1.1 ### Changes since 6.1.0 * Handle the returning of `&` to `*` types. This specifically comes up with `std::vector` and similar containers + * Update CMake to use `LIBDIR` instead of `lib` #502 by @guoyunhe + * Add documentation for installing ChaiScript with vcpkg #500 by @grdowns + * Fix warning for implicit 'this' lambda capture in C++20 #495 by @Josh-Thompson ### Changes since 6.0.0 @@ -18,7 +21,6 @@ Current Version: 6.1.1 * Support for C++17 compilers! * Support for UTF8 BOM #439 @AlekMosingiewicz @MarioLiebisch - ### Changes since 5.8.6 *6.0.0 is a massive rework compared to 5.x. It now requires a C++14 enabled compiler*