Skip to content

Commit

Permalink
Fix native Wren lists
Browse files Browse the repository at this point in the history
Fix moving Wren VM will corrupt the user pointer
Add support for Wren native maps
Update Wreb submodule to the latest master version
Update documentation and replace Hugo-Learn theme with Hugo-Learn theme
Add support for std::optional
Add support for std::deque
Refactor and format header files
Remove broken lcov for uploading test coverage
Move to GitHub actions
Allow wrenbind17::Variable instance to be pushed into Wren VM
Redesigned wrenbind17::Any from scrach and now uses the same mechanism as the rest of the code via push and pop helpers
Added API documentation
Updated Hugo to the latest version
Updated Doxybook2 to the latest version
  • Loading branch information
matusnovak committed Jul 15, 2020
1 parent 90dfa2d commit c72325a
Show file tree
Hide file tree
Showing 65 changed files with 4,081 additions and 2,439 deletions.
71 changes: 54 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,33 +81,23 @@ jobs:
shell: bash
run: |
if [ "$RUNNER_OS" == "Windows" ]; then
cmake --build ./build --target ALL_BUILD --config Debug
cmake --build ./build --config Debug
else
cmake --build ./build --target all --config Debug
cmake --build ./build --config Debug
fi
- name: Tests
shell: bash
run: cd build && ctest -C Debug --verbose

- name: Valgrind
if: ${{ matrix.os == 'ubuntu-latest' }}
shell: bash
run: |
valgrind --suppressions=./wren.supp ./build/WrenBind17_tests
sudo apt-get install -y lcov valgrind
valgrind --suppressions=./wren.supp ./build/WrenBind17_Tests
- name: Coverage
if: ${{ matrix.os == 'ubuntu-latest' }}
- name: Tests
shell: bash
run: |
lcov --directory ./build --capture --output-file coverage.info;
lcov --remove coverage.info '/usr/*' "${HOME}"'/.cache/*' '*tests*' '*catch2*' '*vm*' --output-file coverage.info;
lcov --list coverage.info;
bash <(curl -s https://codecov.io/bash) -f coverage.info || echo "Codecov did not collect coverage reports";
run: cd build && ctest -C Debug --verbose

- name: Create Changelog
id: create_changelog
if: startsWith(github.ref, 'refs/tags/v')
- name: Changelog
shell: bash
run: |
last_tag=$(git describe --tags --abbrev=0 @^ || true)
Expand All @@ -130,3 +120,50 @@ jobs:
omitNameDuringUpdate: true
prerelease: false
token: ${{ secrets.GITHUB_TOKEN }}

docs:
name: Documentation
needs: [build]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
with:
submodules: true

- name: Dependencies
shell: bash
run: |
sudo apt-get install doxygen zip unzip -y
wget https://github.com/gohugoio/hugo/releases/download/v0.74.1/hugo_extended_0.74.1_Linux-64bit.tar.gz
tar xvf hugo_extended_0.74.1_Linux-64bit.tar.gz
sudo chmod +x ./hugo
./hugo version
wget https://github.com/matusnovak/doxybook2/releases/download/v1.1.6/doxybook2-linux-amd64-v1.1.6.zip
unzip doxybook2-linux-amd64-v1.1.6.zip
sudo cp bin/doxybook2 /usr/local/bin/doxybook2
sudo chmod +x /usr/local/bin/doxybook2
- name: Generate documentation
shell: bash
run: |
doxygen
doxybook2 \
--input temp/xml \
--output docs/content \
--config docs/.doxybook/config.json
rm -rf docs/content/Examples
rm -rf docs/content/Pages
- name: Build static pages
shell: bash
run: |
cd docs
../hugo
- name: Deploy
if: startsWith(github.ref, 'refs/tags/v')
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/public
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
[submodule "libs/Catch2"]
path = libs/Catch2
url = https://github.com/catchorg/Catch2.git
[submodule "docs/themes/hugo-theme-learn"]
path = docs/themes/hugo-theme-learn
url = https://github.com/matcornic/hugo-theme-learn
[submodule "docs/themes/hugo-book"]
path = docs/themes/hugo-book
url = https://github.com/alex-shpak/hugo-book
61 changes: 21 additions & 40 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,61 +1,42 @@
cmake_minimum_required(VERSION 3.0)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/modules")

project(WrenBind17)

option(WRENBIND17_BUILD_TESTS "Build with tests" OFF)
option(WRENBIND17_BUILD_WREN "Build Wren library too" OFF)

if(WRENBIND17_BUILD_TESTS)
# Code Coverage Configuration
add_library(coverage_config INTERFACE)

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# Add required flags (GCC & LLVM/Clang)
target_compile_options(coverage_config INTERFACE
-O0 # no optimization
-g # generate debug info
--coverage # sets all required flags
)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
target_link_options(coverage_config INTERFACE --coverage)
else()
target_link_libraries(coverage_config INTERFACE --coverage)
endif()
endif()
endif()

# Add WrenBind17 header only library
add_library(${PROJECT_NAME} INTERFACE)
set(WRENBIND17_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(${PROJECT_NAME} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(${PROJECT_NAME} INTERFACE ${WRENBIND17_INCLUDE_DIR})

if(WRENBIND17_BUILD_TESTS OR WRENBIND17_BUILD_WREN)
# Wren
set(WREN_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libs/wren/src/include)
file(GLOB_RECURSE WREN_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/libs/wren/src/vm/*.c)
set_source_files_properties(${WREN_SOURCES} PROPERTIES LANGUAGE C)
add_library(Wren STATIC ${WREN_SOURCES})
target_include_directories(Wren PRIVATE ${WREN_INCLUDE_DIR})
target_include_directories(Wren PUBLIC ${WREN_INCLUDE_DIR})
target_compile_definitions(Wren PRIVATE WREN_OPT_META=0 WREN_OPT_RANDOM=0)
# Find Wren library
find_package(Wren REQUIRED)
endif()

if(WRENBIND17_BUILD_TESTS)
target_link_libraries(${PROJECT_NAME} INTERFACE coverage_config)
# Find Catch2 library
find_package(Catch2 REQUIRED)

# Add tests
enable_testing()
# Catch2
set(CATCH2_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libs/Catch2/single_include)

set(TEST_TARGET ${PROJECT_NAME}_tests)
file(GLOB TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/tests/*.cpp)
file(GLOB TEST_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/tests/*.hpp)
file(GLOB LIB_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/wrenbind17/*.hpp)
add_executable(${TEST_TARGET} ${TEST_SOURCES} ${TEST_HEADERS} ${LIB_HEADERS})
set_target_properties(${TEST_TARGET} PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF)
target_include_directories(${TEST_TARGET} PRIVATE ${CATCH2_INCLUDE_DIR})
target_link_libraries(${TEST_TARGET} PUBLIC Wren ${PROJECT_NAME})
target_link_libraries(${TEST_TARGET} PRIVATE coverage_config)
add_executable(${PROJECT_NAME}_Tests ${TEST_SOURCES} ${TEST_HEADERS} ${LIB_HEADERS})
set_target_properties(${PROJECT_NAME}_Tests PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF)
target_include_directories(${PROJECT_NAME}_Tests PRIVATE ${CATCH2_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME}_Tests PUBLIC Wren ${PROJECT_NAME})
if(UNIX AND NOT APPLE)
# Coverage info
target_compile_options(${PROJECT_NAME}_Tests PRIVATE --coverage -g -O0)
target_link_options(${PROJECT_NAME}_Tests PRIVATE --coverage)
endif()
if(MINGW)
target_compile_options(${TEST_TARGET} PRIVATE -Wa,-mbig-obj)
target_compile_options(${PROJECT_NAME}_Tests PRIVATE -Wa,-mbig-obj)
endif()
add_test(NAME ${TEST_TARGET} COMMAND ${TEST_TARGET})
add_test(NAME ${PROJECT_NAME}_Tests COMMAND ${PROJECT_NAME}_Tests)
endif()

42 changes: 21 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
MIT License

Copyright (c) 2019 Matus Novak

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.
MIT License
Copyright (c) 2019-2020 Matus Novak
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.
44 changes: 21 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
# WrenBind17

[![Build Status](https://travis-ci.com/matusnovak/wrenbind17.svg?branch=master)](https://travis-ci.com/matusnovak/wrenbind17) [![Build status](https://ci.appveyor.com/api/projects/status/fy974aj37cdyxc0i/branch/master?svg=true)](https://ci.appveyor.com/project/matusnovak/wrenbind17/branch/master) [![CircleCI](https://circleci.com/gh/matusnovak/wrenbind17.svg?style=svg)](https://circleci.com/gh/matusnovak/wrenbind17) [![codecov](https://codecov.io/gh/matusnovak/wrenbind17/branch/master/graph/badge.svg)](https://codecov.io/gh/matusnovak/wrenbind17)
[![build](https://github.com/matusnovak/wrenbind17/workflows/build/badge.svg?branch=master)](https://github.com/matusnovak/wrenbind17/actions)

WrenBind17 is a C++17 wrapper for [Wren programming language](http://wren.io/). This project was heavily inspired by [pybind11](https://github.com/pybind/pybind11) and by [Wren++](https://github.com/Nelarius/wrenpp). This library is header only and does not need any compilation steps. Simply include the `<wrenbind17/wrenbind17.hpp>` header in your application and you are good to go!
WrenBind17 is a C++17 wrapper for [Wren programming language](http://wren.io/). This project was heavily inspired by [pybind11](https://github.com/pybind/pybind11) and by [Wren++](https://github.com/Nelarius/wrenpp). This library is header only and does not need any compilation steps. Simply include the WrenBind17 header `<wrenbind17/wrenbind17.hpp>`, link the Wren library, and you are good to go.

## Features

* Header only.
* Works with Visual Studio 2017, MinGW-w64, Linux GCC, and Apple Clang on Mac OSX.
* C++17 so you don't need to use `decltype()` on class methods to bind them to Wren.
* [Foreign modules are automatically generated for you](https://matusnovak.github.io/wrenbind17/tutorial/hello_world.html). You don't need to write the extra foreign classes in separate file.
* Foreign modules are automatically generated for you. You don't need to write the extra foreign classes in separate file.
* **Supports strict type safety.** You won't be able to pass just any variable from Wren back to the C++, preventing you getting segmentation faults.
* Objects are wrapped in `std::shared_ptr` so you have easier access when passing objects around.
* **Objects are wrapped in std::shared_ptr so you have easier access when passing objects around.** This also enables easy object lifetime management.
* Easy binding system inspired by [pybind11](https://github.com/pybind/pybind11).
* [Works with exceptions](https://matusnovak.github.io/wrenbind17/tutorial/exceptions.html).
* [Upcasting to base types when passing C++ instances](https://matusnovak.github.io/wrenbind17/tutorial/upcasting.html).
* Works with exceptions.
* Upcasting to base types when passing C++ instances.
* Memory leak tested.
* Supports `std::variant`.
* Supports [std::map std::unordered_map](https://matusnovak.github.io/wrenbind17/tutorial/maps/) and [std::vector std::list](https://matusnovak.github.io/wrenbind17/tutorial/lists/) via helper classes (optional).
* [Easy binding of operators](https://matusnovak.github.io/wrenbind17/tutorial/overload-operators.html) such as `+`, `-`, `[]`, etc.
* [Long but easy to follow tutorial](https://matusnovak.github.io/wrenbind17/tutorial/installation.html).
* [Supports Fn.new{}](https://matusnovak.github.io/wrenbind17/tutorial/callbacks.html).
* [Supports inheritance (a workaround)](https://matusnovak.github.io/wrenbind17/tutorial/inheritance.html).
* [Supports modularity via look-up paths](https://matusnovak.github.io/wrenbind17/tutorial/modules.html).
* [Supports passing variables by move](https://matusnovak.github.io/wrenbind17/tutorial/call-wren.html)
* Supports STL containers such as `std::variant`, `std::optional`, `std::vector`, `std::list`, `std::deque`, `std::set`, `std::unordered_set`, `std::map`, `std::unordered_map` which can be handled either natively or as a foreign class.
* Easy binding of operators such as `+`, `-`, `[]`, etc.
* Long but easy to follow tutorial ([here](https://matusnovak.github.io/wrenbind17/tutorial/)).
* Supports native lists and native maps.
* Supports Fn.new{}.
* Supports inheritance (a workaround).
* Supports modularity via look-up paths.
* Supports passing variables by move.

## Limitations

* Passing by a reference to a Wren function will create a copy. Use a pointer if you do not wish to create copies and maintain single instance of a given class. This does not affect C++ member functions that return a reference, in that case it will be treated exactly same as a pointer.
* STL containers `std::unique_ptr`, `std::queue`, `std::stack` are not supported.

## Not yet implemented

* Lambdas (very tricky due to passing function pointers, most likely not ever be implemented).
* `..`, `...`, and `is` operator binding.
* Helper classes for binding `std::queue`, `std::deque`, `std::stack`, `std::set`, and `std::unordered_set`.
## TODO

* Lambdas
* `..`, `...`, and `is` operators
* lcov coverage (currently broken with gcc-9)

## Example

Expand Down Expand Up @@ -127,9 +127,7 @@ int main(int argc, char *argv[]) {
## Documentation
Tutorials can be found [**here**](https://matusnovak.github.io/wrenbind17/tutorial/installation/)
And the autogenerated API documentation via Doxygen [**here**](https://matusnovak.github.io/wrenbind17/modules/group__wrenbind17/)
Tutorials and API documentation can be found here: [https://matusnovak.github.io/wrenbind17/](https://matusnovak.github.io/wrenbind17/)
## Build
Expand All @@ -148,7 +146,7 @@ Pull requests are welcome
```
MIT License

Copyright (c) 2019 Matus Novak
Copyright (c) 2019-2020 Matus Novak

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 4 additions & 2 deletions docs/.doxybook/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
"indexGroupsName": "_index",
"indexNamespacesName": "_index",
"indexRelatedPagesName": "_index",
"indexExamplesName": "_index"
}
"indexExamplesName": "_index",
"mainPageInRoot": true,
"mainPageName": "_index"
}
7 changes: 0 additions & 7 deletions docs/.doxybook/templates/header.tmpl

This file was deleted.

15 changes: 8 additions & 7 deletions docs/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ baseURL = "https://matusnovak.github.io/wrenbind17"
editURL = "https://github.com/matusnovak/wrenbind17/tree/master/docs/content"
languageCode = "en-us"
title = "WrenBind17"
theme = "hugo-theme-learn"
pygmentscodefences = true
theme = "hugo-book"
pygmentsCodeFences = true

[[Languages.en.menu.shortcuts]]
name = "<i class='fab fa-fw fa-github'></i> GitHub repo"
identifier = "ds"
url = "https://github.com/matusnovak/wrenbind17/"
weight = 10
[params]
BookEditPath = 'tree/master/docs/content'
BookSearch = true
BookRepo = 'https://github.com/matusnovak/wrenbind17'
BookToC = true
BookMenuBundle = '/menu'
14 changes: 13 additions & 1 deletion docs/content/Tutorial/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@
title: Tutorial
---

{{% children %}}
# Tutorial

* [1. Installation]({{< relref "install.md" >}})
* [2. Hello World]({{< relref "hello_world.md" >}})
* [3. Call Wren function]({{< relref "call_wren.md" >}})
* [4. Supported types]({{< ref "types.md" >}})
* [5. Executing from file]({{< ref "execute_code.md" >}})
* [6. Custom types]({{< ref "custom_types.md" >}})
* [7. Class operators]({{< ref "operators.md" >}})
* [8. Modules and files]({{< ref "modules.md" >}})
* [9. Customize VM]({{< ref "customize.md" >}})
* [10. Fn.new and callbacks]({{< ref "fn.md" >}})
* [11. STL containers]({{< ref "stl.md" >}})
19 changes: 0 additions & 19 deletions docs/content/Tutorial/abstract-classes.md

This file was deleted.

0 comments on commit c72325a

Please sign in to comment.