Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: true
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: Inline
AllowShortLoopsOnASingleLine: false
Expand Down
46 changes: 42 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
- name: Configure CMake
shell: bash
working-directory: ${{github.workspace}}/build
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DINKCPP_PY=ON

# Build using CMake and OS toolkit
- name: Build
Expand Down Expand Up @@ -125,6 +125,17 @@ jobs:
name: ${{ matrix.artifact }}-unreal
path: build/comp_unreal/

- name: Install PythonLib
working-directory: ${{github.workspace}}/build
shell: bash
run: cmake --install . --config $BUILD_TYPE --prefix comp_py --component unreal

- name: Upload Binary Artifact
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.artifact }}-py
path: build/comp_py/

# Make sure Inkproof has everything it needs to run our executable
- name: Setup Ink Proof
if: ${{ matrix.proof }}
Expand Down Expand Up @@ -170,6 +181,33 @@ jobs:
name: ${{ matrix.artifact }}-www
path: proofing/ink-proof/out


build-python:
name: Build Python package
needs: compilation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: install build
run: >-
python3 -m
pip install
build
--user
- name: Build python release
run: python3 -m build
- name: Upload Python files
uses: actions/upload-artifact@v3
with:
name: python-package-distribution
path: dist/

clang-format:
name: "Check Formatting"
runs-on: ubuntu-latest
Expand All @@ -178,13 +216,13 @@ jobs:
- uses: actions/checkout@v3
- name: Fetch master branch
run: |
git fetch origin master --depth 1
git fetch origin master
- name: Check clang-format
run: |
diff=$(git clang-format-14 --style file -q --diff origin/master)
diff=$(git clang-format-14 --extensions c,cpp,h,hpp --style file -q --diff origin/master)
echo $diff
if [ "$diff" != "" ]; then
echo run git clang-format --style file master
echo run git clang-format --extensions c,cpp,h,hpp --style file master
echo or upstream/master depending on your setup
clang
fi
Expand Down
16 changes: 12 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,27 @@ jobs:
release:
name: Release pushed tag
runs-on: ubuntu-22.04
enviroment:
name: pypi
url: https://pypi.org/p/inkcpp-py
permissions:
id-token: write
steps:
- uses: actions/checkout@v3
- name: Download artifacts
uses: marcofaggian/[email protected]
with:
names: linux-cl linux-lib linux-unreal macos-cl macos-lib macos-unreal win64-cl win64-lib win64-unreal
paths: linux-cl linux-lib linux-unreal macos-cl macos-lib macos-unreal win64-cl win64-lib win64-unreal
names: linux-cl linux-lib linux-unreal macos-cl macos-lib macos-unreal win64-cl win64-lib win64-unreal python-package-distribution
paths: linux-cl linux-lib linux-unreal macos-cl macos-lib macos-unreal win64-cl win64-lib win64-unreal dist/
workflow: build.yml
branch: master
- name: Zip
run: |
for f in linux-cl linux-lib linux-unreal macos-cl macos-lib macos-unreal win64-cl win64-lib win64-unreal; do zip -r $f $f; done
for f in linux-cl linux-lib linux-unreal macos-cl macos-lib macos-unreal win64-cl win64-lib win64-unreal win6; do zip -r $f $f; done
- name: List
run: tree
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -35,4 +42,5 @@ jobs:
--repo="$GITHUB_REPOSITORY" \
--title="${GITHUB_REPOSITORY#*/} ${tag#v}" \
--generate-notes \
"$tag" "linux-cl.zip" "linux-lib.zip" "linux-unreal.zip" "macos-cl.zip" "macos-lib.zip" "macos-unreal.zip" "win64-cl.zip" "win64-lib.zip" "win64-unreal.zip"
"$tag" "linux-cl.zip" "linux-lib.zip" "linux-unreal.zip" "macos-cl.zip" "macos-lib.zip" "macos-unreal.zip" "win64-cl.zip" "win64-lib.zip" "win64-unreal.zip"

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Ink files
inkcpp_cl/*.ink
*.json
!inkcpp_py/sources.json

# Visual Studio code
*.code-workspace
Expand All @@ -16,4 +17,4 @@ Documentation/*
Build/*
build/*
bin/
Bin/
Bin/
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[submodule "proofing/ink-proof"]
path = proofing/ink-proof
url = https://github.com/chromy/ink-proof.git
shallow = true
[submodule "inkcpp_py/pybind11"]
path = inkcpp_py/pybind11
url = https://github.com/pybind/pybind11.git
branch = stable
shallow = true
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,29 @@ cmake_minimum_required(VERSION 3.16)
enable_testing()

# Project setup
project(inkcpp VERSION 0.1)
project(inkcpp VERSION 0.1.1)
SET(CMAKE_CXX_STANDARD 20)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_INSTALL_LIBRARY_DIR lib)
SET(CMAKE_INSTALL_INCLUDE_DIR include)

# Add subdirectories
set(INKCPP_PY OFF CACHE BOOL "Build python bindings")
set(WHEEL_BUILD OFF CACHE BOOL "Set for build wheel python lib (do not forgett INKCPP_PY")

if (INKCPP_PY)
add_compile_options(-fPIC)
add_subdirectory(inkcpp_py)
endif(INKCPP_PY)
add_subdirectory(shared)
add_subdirectory(inkcpp)
add_subdirectory(inkcpp_compiler)
if (NOT WHEEL_BUILD)
add_subdirectory(inkcpp_cl)
add_subdirectory(inkcpp_test)
add_subdirectory(unreal)
endif(NOT WHEEL_BUILD)



install(TARGETS inkcpp inkcpp_compiler inkcpp_shared
Expand Down
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ Without the `-p` flag, it'll just compile the JSON/Ink file into InkCPP's binary

All features of ink 1.1 are supported, and checked with [ink-proof](https://github.com/chromy/ink-proof).

In addition a UE Plugin inclusive BluePrints are provided and python bindings based on [pybind11](https://github.com/pybind/pybind11).

KeyFeatures: snapshots, observers, binding ink functions, support ink [function fallback](https://github.com/inkle/ink/blob/master/Documentation/RunningYourInk.md#fallbacks-for-external-functions)

## Unreal Plugin

The current version of the UE plugin can be downloaded from the [release page](https://github.com/brwarner/inkcpp/releases/latest) with te corresponding name of the OS (e.g. win64-unreal).
The current version of the UE plugin can be downloaded from the [release page](https://github.com/JBenda/inkcpp/releases/latest) with te corresponding name of the OS (e.g. win64-unreal).
Place the content of this file at your plugin folder of your UE project and at the next start up it will be intigrated.

A example project can be found [here](https://cloud.julian-benda.de/index.php/s/cRMBGBWbHPCcdwb).
Expand Down Expand Up @@ -125,7 +127,7 @@ To install the different components use `cmake --install . --component <lib|cl|u
+ `cl` command line application
+ `unreal` UE-plugin

For a more in depth installation description please checkout the (wiki)[https://github.com/brwarner/inkcpp/wiki/building].
For a more in depth installation description please checkout the [wiki](https://github.com/brwarner/inkcpp/wiki/building).


### Troubleshooting
Expand All @@ -140,9 +142,20 @@ Run `ctest` from the build folder to execute unit tests configured with CMake. U
Right now this only executes the internal unit tests which test the functions of particular classes. Soon it'll run more complex tests on .ink files using ink-proof.


## Next Steps
## Python Bindings

The easy way to start is installing it with pip: `pip install inkcpp_py`.
An example can be found at [./inkcpp_py/example.py].
To build it from source use:

```sh
git clone --recurse-submodules https://github.com/JBenda/inkcpp.git
pip install inkcpp
```

The python bindnigs are defined in `inkcpp_py` subfolder.

I am currently working toward a 1.0 release. You can track my progress here: https://github.com/brwarner/inkcpp/projects/1
A downloadable version of the `inkcpp_py` lib can be found at the [release page](https://github.com/JBenda/inkcpp/releases/latest) with the name `<os>_py` eg `linux_py`.

## Dependencies
The compiler depends on Nlohmann's JSON library and the C++ STL.
Expand Down
109 changes: 56 additions & 53 deletions inkcpp/functional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,73 +5,76 @@
#include "string_table.h"

#ifdef INK_ENABLE_UNREAL
#include "InkVar.h"
# include "InkVar.h"
#endif

namespace ink::runtime::internal
{
template<>
int32_t function_base::pop<int32_t>(basic_eval_stack* stack, list_table& lists)
{
value val = stack->pop();
inkAssert(val.type() == value_type::int32, "Type missmatch!");
return val.get<value_type::int32>();
}
template<>
ink::runtime::value
function_base::pop<ink::runtime::value>(basic_eval_stack* stack, list_table& lists)
{
value val = stack->pop();
return val.to_interface_value(lists);
}

template<>
const char* function_base::pop<const char*>(basic_eval_stack* stack, list_table& lists)
{
value val = stack->pop();
inkAssert(val.type() == value_type::string, "Type missmatch!");
return val.get<value_type::string>().str;
}
template<>
int32_t function_base::pop<int32_t>(basic_eval_stack* stack, list_table& lists)
{
value val = stack->pop();
inkAssert(val.type() == value_type::int32, "Type missmatch!");
return val.get<value_type::int32>();
}

template<>
void function_base::push<int32_t>(basic_eval_stack* stack, const int32_t& v)
{
stack->push(value{}.set<value_type::int32>(v));
}
template<>
const char* function_base::pop<const char*>(basic_eval_stack* stack, list_table& lists)
{
value val = stack->pop();
inkAssert(val.type() == value_type::string, "Type missmatch!");
return val.get<value_type::string>().str;
}

void function_base::push_void(basic_eval_stack* stack)
{
stack->push(values::null);
}
template<>
void function_base::push<int32_t>(basic_eval_stack* stack, const int32_t& v)
{
stack->push(value{}.set<value_type::int32>(v));
}

void function_base::push_void(basic_eval_stack* stack) { stack->push(values::null); }

void function_base::push_string(basic_eval_stack* stack, const char* dynamic_string)
{
stack->push(value{}.set<value_type::string>(dynamic_string, true));
}
void function_base::push_string(basic_eval_stack* stack, const char* dynamic_string)
{
stack->push(value{}.set<value_type::string>(dynamic_string, true));
}

char* function_base::allocate(string_table& strings, size_t len)
{
return strings.create(len);
}
char* function_base::allocate(string_table& strings, size_t len) { return strings.create(len); }

// Generate template implementations for all significant types
// Generate template implementations for all significant types

#ifdef INK_ENABLE_STL
template<>
std::string function_base::pop<std::string>(basic_eval_stack* stack, list_table& lists) {
return std::string(pop<const char*>(stack, lists));
}
template<>
std::string function_base::pop<std::string>(basic_eval_stack* stack, list_table& lists)
{
return std::string(pop<const char*>(stack, lists));
}
#endif
#ifdef INK_ENABLE_UNREAL
template<>
FInkVar function_base::pop<FInkVar>(basic_eval_stack* stack, list_table& lists)
{
return FInkVar(stack->pop().to_interface_value(lists));
}

template<>
void function_base::push<ink::runtime::value>(basic_eval_stack* stack, const ink::runtime::value& value)
{
internal::value val{};
if(val.set(value)) {
stack->push(val);
} else {
inkFail("unable to set variable?");
}
}
template<>
FInkVar function_base::pop<FInkVar>(basic_eval_stack* stack, list_table& lists)
{
return FInkVar(stack->pop().to_interface_value(lists));
}
#endif
template<>
void function_base::push<ink::runtime::value>(
basic_eval_stack* stack, const ink::runtime::value& value
)
{
internal::value val{};
if (val.set(value)) {
stack->push(val);
} else {
inkFail("unable to set variable?");
}
}
} // namespace ink::runtime::internal
Loading