Skip to content

Commit

Permalink
Use simplesquirrel library for creating Squirrel API binds (#2792)
Browse files Browse the repository at this point in the history
Incorporates a SuperTux fork of the `simplesquirrel` library. Most important feature of this library in the context of SuperTux is the ability to easily expose functions, classes (which can include properties) and other entries to Squirrel in one or a few lines.

Every exposed class, variable and function has been migrated to incorporate this change. As a result, the `scripting/` directory, which included all scripting functions, classes and variables, as well as the API wrapper, has been removed, since it is no longer needed for the new binds.

Some scripting functions have been deprecated (currently only via a tag in comment, later to be migrated to docmentation) for several reasons:
* Some `get_` and `set_` functions have been deprecated, since a class property has been added and should replace their usage.
* Functions with the names `get_pos_x` or `get_pos_y` have been replaced with `get_x` and `get_y` for consistency, thus are now deprecated.

This way of creating Squirrel binds would allow for way more flexibility in exposing functions, classes and properties.

**Additionally:**

* Removed the `camera()` function, as it only printed the camera position, which is already accessible through methods from the `Camera` itself.
* `Granito` and `GranitoBig` are now scriptable.

## Documentation

Doxygen scripting documentation is now generated for the entire codebase as well, since scripting classes might be found anywhere.

The `@scripting` tag for classes, functions, constants and variables indicates the item should be added to the scripting documentation. Otherwise, it should be ignored.

Added support for the following:

* Enumerators
* Member variables
* Listing of base and derived classes

# TODO

- [x] Expand usage of simplesquirrel functions, instead of ones in `SquirrelVM`, to reduce code duplication.
- [x] Update the scripting API documentation/reference generator to incorporate all changes.

Closes #2736.

Co-authored-by: Tobias Markus <[email protected]>
Co-authored-by: MatusGuy <[email protected]>
  • Loading branch information
3 people authored Jul 6, 2024
1 parent c62ffdd commit 19e2884
Show file tree
Hide file tree
Showing 227 changed files with 8,132 additions and 29,357 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
submodules: recursive

- name: Clone SDL Android repo
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/bsd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
with:
# Fetch the whole tree so git describe works
fetch-depth: 0
submodules: true
submodules: recursive

- name: Build in FreeBSD
if: ${{ matrix.vm_os == 'freebsd' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gnulinux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
with:
# Fetch the whole tree so git describe works
fetch-depth: 0
submodules: true
submodules: recursive

- name: Install 64-bit dependencies
if: ${{ matrix.arch == 64 }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
with:
# Fetch the whole tree so git describe works
fetch-depth: 0
submodules: true
submodules: recursive

- name: Install macos dependencies
if: ${{ matrix.os == 'macos-12' }}
Expand Down
21 changes: 16 additions & 5 deletions .github/workflows/scripting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ on:
push:
branches: [ "master" ]
paths:
- src/scripting/*.hpp
- src/
workflow_dispatch:

jobs:
Expand Down Expand Up @@ -56,31 +56,42 @@ jobs:
cmake --version
mkdir build
cd build
cmake .. -DBUILD_SCRIPTING_DOCUMENTATION=ON
cmake .. -DBUILD_DOCUMENTATION_WITH_SCRIPTING=ON
make
- name: Generate scripting reference
working-directory: tools/scripting_docs_gen/build
run: |
doxygen docs/scripting/Doxyfile
doxygen docs/Doxyfile
rm ../../../wiki/Scripting*.md
./ScriptingDocsGen --dir docs/scripting/doxygen/xml \
./ScriptingDocsGen --dir docs/doxygen/xml \
--home ../../../wiki/templates/ScriptingHome.md \
--page ../../../wiki/templates/ScriptingPage.md \
--output ../../../wiki
- name: Check for changes
working-directory: wiki
run: |
REF_UPDATED=true
if git diff --exit-code; then
REF_UPDATED=false
fi
echo "REFERENCE_UPDATED=$(echo $REF_UPDATED)" >> $GITHUB_ENV
- name: Install SSH key
if: ${{ env.REFERENCE_UPDATED == 'true' }}
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.wiki_repo_key }}
known_hosts: ${{ secrets.wiki_repo_hosts }}

- name: Push changes to wiki
if: ${{ env.REFERENCE_UPDATED == 'true' }}
working-directory: wiki
run: |
git --version
git status
git config --global user.email "supertux-bot"
git config --global user.email "SuperTux-bot@users.noreply.github.com"
git config --global user.name "SuperTux Bot"
git add .
git commit -m "Update scripting reference (SuperTux/supertux@${{ github.sha }})"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu-touch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
with:
# Fetch the whole tree so git describe works
fetch-depth: 0
submodules: true
submodules: recursive

- name: Install clickable
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
with:
# Fetch the whole tree so git describe works
fetch-depth: 0
submodules: true
submodules: recursive

- name: Install emscripten tools
run: |
Expand Down
16 changes: 13 additions & 3 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
with:
# Fetch the whole tree so git describe works
fetch-depth: 0
submodules: true
submodules: recursive

- name: Use cached dependencies
id: cache-dependencies
Expand Down Expand Up @@ -105,13 +105,23 @@ jobs:
"./$Env:BUILD_TYPE/run_tests.exe"
- name: Package MSI Installer
shell: pwsh
working-directory: build
env:
BUILD_TYPE: ${{ matrix.build_type }}
run: |
cpack -C $Env:BUILD_TYPE
mkdir upload
mv *.msi upload/
if ($LASTEXITCODE -ne 0)
{
$code = $LASTEXITCODE
type ./_CPack_Packages/win64/WIX/wix.log
exit $code
}
else
{
mkdir upload
mv *.msi upload/
}
- name: Upload MSI Installer
uses: actions/upload-artifact@v4
Expand Down
9 changes: 3 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "external/tinygettext"]
path = external/tinygettext
url = https://github.com/SuperTux/tinygettext.git
[submodule "external/squirrel"]
path = external/squirrel
url = https://github.com/albertodemichelis/squirrel.git
[submodule "external/sexp-cpp"]
path = external/sexp-cpp
url = https://github.com/SuperTux/sexp-cpp.git
Expand All @@ -19,9 +16,9 @@
[submodule "external/fmt"]
path = external/fmt
url = https://github.com/fmtlib/fmt.git
[submodule "tools/miniswig"]
path = tools/miniswig
url = https://github.com/WindstilleTeam/miniswig
[submodule "external/glm"]
path = external/glm
url = https://github.com/g-truc/glm.git
[submodule "external/simplesquirrel"]
path = external/simplesquirrel
url = https://github.com/SuperTux/simplesquirrel
10 changes: 2 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ include(SuperTux/ProvideOpenAL)
include(SuperTux/ProvideOggVorbis)
include(SuperTux/ProvidePhysfs)
include(SuperTux/ProvideCurl)
include(SuperTux/ProvideSquirrel)
include(SuperTux/ProvideSimpleSquirrel)
include(SuperTux/ProvideTinygettext)
include(SuperTux/ProvideSDL2_ttf)
include(SuperTux/ProvideDiscord)
Expand All @@ -187,7 +187,6 @@ include(SuperTux/ProvideOpenGL)
include(SuperTux/BuildVersion)
include(SuperTux/BuildDocumentation)
include(SuperTux/BuildMessagePot)
include(SuperTux/BuildMiniswigWrapper)

## Build list of sources for supertux binary
file(GLOB SUPERTUX_SOURCES_C RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} external/obstack/*.c external/findlocale/findlocale.c)
Expand All @@ -205,10 +204,6 @@ list(SORT SUPERTUX_SOURCES_C)
list(SORT SUPERTUX_SOURCES_CXX)
list(SORT SUPERTUX_RESOURCES)

if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp)
set(SUPERTUX_SOURCES_CXX ${SUPERTUX_SOURCES_CXX} ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp)
endif()

## On Windows, add an icon
if(WIN32)
if(MINGW)
Expand Down Expand Up @@ -269,8 +264,7 @@ endif()

## Link supertux binary with squirrel and other libraries

target_link_libraries(supertux2_lib PUBLIC LibSquirrel)
target_link_libraries(supertux2_lib PUBLIC LibSqstdlib)
target_link_libraries(supertux2_lib PUBLIC LibSimpleSquirrel)
target_link_libraries(supertux2_lib PUBLIC LibTinygettext)
target_link_libraries(supertux2_lib PUBLIC LibSexp)
target_link_libraries(supertux2_lib PUBLIC LibSavePNG)
Expand Down
17 changes: 0 additions & 17 deletions data/scripts/default.nut
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,6 @@
* and variables you define here can be used in all threads
*/

//Create Level table
Level <- {
finish=Level_finish,
has_active_sequence=Level_has_active_sequence,
spawn=Level_spawn,
spawn_transition=Level_spawn_transition,
set_start_point=Level_set_start_point,
set_start_pos=Level_set_start_pos,
set_respawn_point=Level_set_respawn_point,
set_respawn_pos=Level_set_respawn_pos,
flip_vertically=Level_flip_vertically,
toggle_pause=Level_toggle_pause,
pause_target_timer=Level_pause_target_timer,
resume_target_timer=Level_resume_target_timer
};


function end_level()
{
play_music("music/misc/leveldone.ogg");
Expand Down
1 change: 1 addition & 0 deletions external/simplesquirrel
Submodule simplesquirrel added at e7eab2
1 change: 0 additions & 1 deletion external/squirrel
Submodule squirrel deleted from b31e5b
2 changes: 1 addition & 1 deletion mk/cmake/SuperTux/BuildCPack.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
option(DISABLE_CPACK_BUNDLING "Build an .app bundle without CPack" OFF)

include(InstallRequiredSystemLibraries)
set(DIRS ${Boost_LIBRARY_DIRS} ${CMAKE_CURRENT_BINARY_DIR}/external/squirrel ${CMAKE_CURRENT_BINARY_DIR}/external/tinygettext)
set(DIRS ${CMAKE_CURRENT_BINARY_DIR}/external/tinygettext ${CMAKE_CURRENT_BINARY_DIR}/external/simplesquirrel)

if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT DISABLE_CPACK_BUNDLING)
set(INFOPLIST_CFBUNDLEEXECUTABLE "SuperTux")
Expand Down
25 changes: 7 additions & 18 deletions mk/cmake/SuperTux/BuildDocumentation.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@
# Adapted from https://tty1.net/blog/2014/cmake-doxygen_en.html
# add a target to generate API documentation with Doxygen
option(BUILD_DOCUMENTATION "Build API documentation using Doxygen" ${DOXYGEN_FOUND})
option(BUILD_SCRIPTING_DOCUMENTATION "Build scripting API documentation using Doxygen" ${DOXYGEN_FOUND})
option(BUILD_DOCUMENTATION_WITH_SCRIPTING "Build API documentation, including scripting API, using Doxygen" OFF)

# CMakeLists, including this file from a different directory, can define PROJECT_SOURCE_DIR as the path to the SuperTux source.
if(NOT DEFINED PROJECT_SOURCE_DIR)
# If not set, use the current source directory.
set(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
endif()

if(BUILD_DOCUMENTATION)
if(BUILD_DOCUMENTATION OR BUILD_DOCUMENTATION_WITH_SCRIPTING)
find_package(Doxygen REQUIRED)

set(doxyfile_in ${PROJECT_SOURCE_DIR}/Doxyfile.in)
if(BUILD_DOCUMENTATION_WITH_SCRIPTING)
set(doxyfile_in ${PROJECT_SOURCE_DIR}/mk/doxygen/Doxyfile_scripting.in)
else()
set(doxyfile_in ${PROJECT_SOURCE_DIR}/mk/doxygen/Doxyfile.in)
endif()
set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/docs/Doxyfile)

configure_file(${doxyfile_in} ${doxyfile} @ONLY)
Expand All @@ -25,19 +29,4 @@ if(BUILD_DOCUMENTATION)
VERBATIM)
endif()

if(BUILD_SCRIPTING_DOCUMENTATION)
find_package(Doxygen REQUIRED)

set(doxyfile_in ${PROJECT_SOURCE_DIR}/mk/doxygen/Doxyfile_scripting.in)
set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/docs/scripting/Doxyfile)

configure_file(${doxyfile_in} ${doxyfile} @ONLY)

add_custom_target(scripting_doc
COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating scripting API documentation with Doxygen"
VERBATIM)
endif()

# EOF #
27 changes: 0 additions & 27 deletions mk/cmake/SuperTux/BuildMiniswigWrapper.cmake

This file was deleted.

14 changes: 14 additions & 0 deletions mk/cmake/SuperTux/ProvideSimpleSquirrel.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
if(EMSCRIPTEN)
set(SQ_DISABLE_INSTALLER ON)
endif()

add_subdirectory("${CMAKE_SOURCE_DIR}/external/simplesquirrel/")

if(MSVC)
add_library(LibSimpleSquirrel ALIAS simplesquirrel_static)
else()
add_library(LibSimpleSquirrel ALIAS simplesquirrel)
endif()

# Set variables
set(SQUIRREL_PREFIX ${CMAKE_BINARY_DIR}/external/simplesquirrel/libs/squirrel)
Loading

0 comments on commit 19e2884

Please sign in to comment.