Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua via sol2 #2216

Merged
merged 138 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 136 commits
Commits
Show all changes
138 commits
Select commit Hold shift + click to select a range
5619017
Add Lua build to matrix
olanti-p Nov 29, 2022
e7522ea
Add Lua sources
olanti-p Nov 29, 2022
4dcb573
Add sol2 v3.3.0 sources
olanti-p Nov 29, 2022
e0262ea
Set up Lua infrastructure
olanti-p Nov 29, 2022
f451fbd
Run Lua scripts at loading stage
olanti-p Dec 1, 2022
295e328
Prevent scripts from messing with globals table
olanti-p Dec 1, 2022
9013de0
Prevent scripts from messing with mod lists
olanti-p Dec 1, 2022
678cfb5
Fix non-Lua build
olanti-p Dec 1, 2022
c2d2e40
Fix non-Lua build for real
olanti-p Dec 1, 2022
a274da9
When checking all mods, check Lua mods only in Lua builds
olanti-p Dec 1, 2022
e642180
Stop world loading in non-Lua build if mod requires Lua
olanti-p Dec 1, 2022
9ee7841
Fix inverted check
olanti-p Dec 1, 2022
0f50152
Astyle
olanti-p Dec 1, 2022
79a2801
Add wip docs
olanti-p Dec 2, 2022
10b47fc
Add a bunch of tests that check Lua error and C++ exception interop
olanti-p Dec 2, 2022
c92f47b
CMake Lua build
olanti-p Dec 2, 2022
5775611
Lua in CMake build in Github Actions
olanti-p Dec 2, 2022
2414e06
Add Lua to msvc build
olanti-p Dec 2, 2022
7b569fc
Add Lua to android build
olanti-p Dec 2, 2022
1aa928f
Fix duplicated bindings registration
olanti-p Dec 4, 2022
6c50741
Clean up Lua state in exit_handler()
olanti-p Dec 3, 2022
1ce80f7
Bindings for Tripoint
olanti-p Dec 3, 2022
e8d5834
Add bindings for item and itype_id
olanti-p Dec 3, 2022
1da933a
Run Lua functions after game loads
olanti-p Dec 3, 2022
d848143
Add bindings for map and map item iteration
olanti-p Dec 3, 2022
54ba84a
Add hooks for iuse functions
olanti-p Dec 4, 2022
04f509c
Run Lua functions on tinymap after mapgen
olanti-p Dec 4, 2022
6df840e
Log lua output to dedicated in-memory log
olanti-p Dec 5, 2022
50240d8
Lua console
olanti-p Dec 5, 2022
3eb1a78
Reload some parts of Lua code on demand, reset game.current_mod after…
olanti-p Dec 5, 2022
4642970
Add bindings for getting/setting terrain
olanti-p Dec 5, 2022
7a99f95
More bindings
olanti-p Dec 5, 2022
9fd3d70
Fix marking tables as readonly
olanti-p Dec 5, 2022
90012b2
Hack: pairs() for read-only tables
olanti-p Dec 5, 2022
384f5fc
MOAR bindings
olanti-p Dec 5, 2022
7ab30ed
Add Smart House Remotes mod
olanti-p Dec 6, 2022
4686d7c
Fix gcc build
olanti-p Dec 6, 2022
5b014fc
Fix OSX build
olanti-p Dec 6, 2022
754444a
Fix typos, fix LUA=0 build
olanti-p Dec 6, 2022
29d0503
Fix get_all_mods.py grabbing Lua mods for non-Lua tests
olanti-p Dec 7, 2022
53d7800
Fix Lua state deallocation after tests has been run
olanti-p Dec 7, 2022
a914ceb
Simplify addition of new hooks in catalua.cpp
olanti-p Dec 7, 2022
7a2217f
Implement save/load for global mod state
olanti-p Dec 7, 2022
cbbc63f
Add example mod that saves and loads state
olanti-p Dec 7, 2022
4b4f3fd
Fix LUA=0 build again
olanti-p Dec 7, 2022
0747cb0
Show Lua API version in debug log and in game report
olanti-p Dec 11, 2022
4013ae2
In LUA=0 builds, prevent loading worlds that depend on Lua and show w…
olanti-p Dec 11, 2022
cf93e7b
Update docs
olanti-p Dec 11, 2022
a5707b2
Fix some clang lints
olanti-p Dec 12, 2022
bb4923f
Bind faction_id
olanti-p Dec 13, 2022
f114789
[WiP] Lua doc generator - constructors
olanti-p Dec 13, 2022
aac3099
Lua doc generator - member vars and functions
olanti-p Dec 14, 2022
984835b
Fixup constructor
olanti-p Dec 14, 2022
315dfdf
Lua doc generator - base classes
olanti-p Dec 14, 2022
f40078e
Lua doc generator - overloads
olanti-p Dec 14, 2022
3354c91
Lua doc generator - prettier docs
olanti-p Dec 14, 2022
e4873de
Lua doc generator - tuples
olanti-p Dec 14, 2022
31af8e9
Lua doc generator - don't show nil return
olanti-p Dec 14, 2022
8494521
Lua doc generator - more docced bindings
olanti-p Dec 14, 2022
ba43214
Lua doc generator - fix ref/const in return type
olanti-p Dec 14, 2022
2afdbfe
Lua doc generator - split up bindings to functions
olanti-p Dec 14, 2022
dec163e
Encapsulate some code
olanti-p Dec 14, 2022
2890b69
Redister std::string_view in docs
olanti-p Dec 14, 2022
2084ea3
LDC: separate macro for documenting vs values
olanti-p Dec 14, 2022
ea81203
make_readonly_table: accept state_view
olanti-p Dec 14, 2022
bee4fdd
LDG: enums and string_ids
olanti-p Dec 14, 2022
55ad902
LDG: sol::optional
olanti-p Dec 14, 2022
3a4d8b7
LDG: libraries
olanti-p Dec 14, 2022
055c05f
Check that userlib/userenum has been finalized
olanti-p Dec 14, 2022
29eef3a
LDG: library constants
olanti-p Dec 14, 2022
4d591d7
Bind game api & debug functions
olanti-p Dec 14, 2022
3ecde5c
Switch over to new bindings
olanti-p Dec 14, 2022
eec9812
Fix compilation
olanti-p Apr 11, 2023
ff352cf
Fix LUA=0 build
olanti-p Apr 11, 2023
a941ff4
Move hooks into a sub-table
olanti-p Apr 11, 2023
095f773
Fix test
olanti-p Apr 11, 2023
591732f
Update SaveLoad Lua Test mod, mark it obsolete
olanti-p Apr 11, 2023
06b2b98
Update Smart House Remotes mod
olanti-p Apr 11, 2023
fa496aa
Rename function to better match its purpose
olanti-p Apr 11, 2023
4812789
Register examples for hooks so they show up in docs
olanti-p Apr 11, 2023
f764b1a
Astyle
olanti-p Apr 11, 2023
6e4896e
Fix rename
olanti-p Apr 11, 2023
ad7fa4c
Fully implement Lua table (de-)serialization
olanti-p Apr 12, 2023
091f906
Update SaveLoad Lua Test mod
olanti-p Apr 12, 2023
29e4376
Fix g++ build
olanti-p Apr 12, 2023
7b2aa29
No, it wasn't fine
olanti-p Apr 12, 2023
22ed2d7
Extract lua doc output filename to PATH_INFO
olanti-p Apr 12, 2023
d0518de
Update docs
olanti-p Apr 12, 2023
5559ac1
Warn on accidental direct inclusion of sol/sol.hpp (thanks, vscode)
olanti-p Apr 12, 2023
1ee1cdf
Fix invalid int_id definition
olanti-p Apr 12, 2023
13b2a34
Add string_id(int_id) constructor
olanti-p Apr 12, 2023
fb3a4e1
Add bindings for int_id, implement manual conversions
olanti-p Apr 12, 2023
5487215
Fix doc generation for const pointers that are not const char*
olanti-p Apr 12, 2023
8c63a53
Split up luna into its own header
olanti-p Apr 12, 2023
252f376
Explicit type for color_id enum
olanti-p Apr 12, 2023
d28ad92
Move luna doc definitions to header
olanti-p Apr 12, 2023
75d77bd
Allow splitting catalua_bindings.cpp
olanti-p Apr 12, 2023
9a457c1
Split up catalua_bindings.cpp into 3 files
olanti-p Apr 12, 2023
d2d798f
Make console fullscreen
olanti-p Apr 12, 2023
332a30f
Rename function to match its purpose
olanti-p Apr 12, 2023
523987e
Extract comparison operator hack into header
olanti-p Apr 12, 2023
f7da807
Better names + docs
olanti-p Apr 12, 2023
0a2b3b7
Mark changes done to sol.hpp
olanti-p Apr 12, 2023
ed46b46
Fix msvc build
olanti-p Apr 12, 2023
ac2c8de
Build releases with LUA=1
olanti-p Apr 12, 2023
4b439cf
Fix avatar.get_pos_ms
olanti-p Apr 12, 2023
3592658
Print typeid() if no luna registration found
olanti-p Apr 12, 2023
a234336
Revert "Fix msvc build"
olanti-p Apr 12, 2023
9a380a2
Split up into more functions
olanti-p Apr 12, 2023
ce0a32f
Alternative msvc fix
olanti-p Apr 12, 2023
fd092ac
More msvc fixes
olanti-p Apr 12, 2023
e2a22cf
Add comments to the documentation
olanti-p Apr 13, 2023
13f4cd7
Convert *ter_at to int_id
olanti-p Apr 13, 2023
6a1d247
GCC fix
olanti-p Apr 13, 2023
1c3cb5d
Add regression test
olanti-p Apr 13, 2023
7773805
Fix typo
olanti-p Apr 13, 2023
8378017
More hooks and bindings
olanti-p Apr 13, 2023
2c470c5
Fix msvc build, again
olanti-p Apr 13, 2023
9674921
Merge branch 'upload' into lua
olanti-p Jul 3, 2023
13b3499
Merge branch 'upload' into lua
olanti-p Aug 2, 2023
a899e67
Bind l10n api
olanti-p Aug 2, 2023
fa886e0
Update src/catalua_bindings.cpp
olanti-p Aug 2, 2023
45336c2
Extract strings from Lua code
olanti-p Aug 4, 2023
fe0ea72
Write Lua backtrace on debugmsg
olanti-p Aug 4, 2023
9267d54
Fix: start backtrace with level 0
olanti-p Aug 4, 2023
562ea32
Add comment
olanti-p Aug 4, 2023
41d5ada
Lunadoc: support this_state and function
olanti-p Aug 4, 2023
359ab46
Recurrent hooks with customizable interval
olanti-p Aug 4, 2023
d3b68f9
Less calendar checks
olanti-p Aug 4, 2023
823b888
Special fix for special compiler
olanti-p Aug 4, 2023
a7f2106
Fix LUA=0 build
olanti-p Aug 4, 2023
346087e
Use locale API in SHR mod
olanti-p Aug 16, 2023
73ab926
Add docs on binding new stuff to Lua
olanti-p Aug 18, 2023
72eb165
Fix typo
olanti-p Aug 18, 2023
38c9f4c
Elaborate on implementing `enum_traits<T>`
olanti-p Aug 18, 2023
722c05d
Mark "Smart House Remotes" as obsolete
olanti-p Aug 23, 2023
9d88af0
Update doc/LUA_SUPPORT.md
scarf005 Aug 24, 2023
c8aaac3
Restrict some of the fun functionality
olanti-p Aug 25, 2023
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
19 changes: 17 additions & 2 deletions .github/workflows/matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
cmake: 0
tiles: 0
sound: 0
lua: 0
test-stage: 1
title: GCC 12, Ubuntu, Curses
native: linux64
Expand All @@ -39,14 +40,25 @@ jobs:
cmake: 1
tiles: 1
sound: 1
lua: 1
languages: all
native: linux64
title: GCC 12, Ubuntu, Tiles, CMake, Languages
title: GCC 12, Ubuntu, Tiles, Sound, Lua, CMake, Languages
- compiler: g++-12
os: ubuntu-22.04
cmake: 0
tiles: 1
sound: 1
lua: 1
test-stage: 1
title: GCC 11, Ubuntu, Tiles, Sound, Lua
native: linux64
- compiler: g++-11
os: ubuntu-22.04
cmake: 0
tiles: 1
sound: 0
lua: 0
sanitize: address
native: linux64
title: GCC 12, Ubuntu, Tiles, NoSound, ASan
Expand All @@ -55,6 +67,7 @@ jobs:
cmake: 0
tiles: 1
sound: 0
lua: 0
sanitize: address,undefined
native: linux64
title: Clang 14, Ubuntu, Tiles, NoSound, ASan, UBSan
Expand All @@ -63,10 +76,11 @@ jobs:
cmake: 0
tiles: 1
sound: 1
lua: 1
test-stage: 1
native: osx
grep_clang_version_rxp: "14\\.[0-9]+\\.[0-9]+"
title: Clang 14, macOS 12, Tiles, Localize
title: Clang 14, macOS 12, Tiles, Sound, Localize, Lua
name: ${{ matrix.title }}
runs-on: ${{ matrix.os }}
env:
Expand All @@ -76,6 +90,7 @@ jobs:
OS: ${{ matrix.os }}
TILES: ${{ matrix.tiles }}
SOUND: ${{ matrix.sound }}
LUA: ${{ matrix.lua }}
SANITIZE: ${{ matrix.sanitize }}
TEST_STAGE: ${{ matrix.test-stage }}
LANGUAGES: ${{ matrix.languages }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push-translation-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: "Install Python3"
run: |
sudo apt install python3-pip
sudo pip3 install polib
sudo pip3 install polib luaparser
- name: "Checkout"
uses: actions/checkout@v3
- name: "Generate translation template"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,14 @@ jobs:
- name: Build CBN (linux)
if: runner.os == 'Linux' && matrix.mxe == 'none' && matrix.android == 'none'
run: |
make -j$((`nproc`+0)) TILES=${{ matrix.tiles }} SOUND=${{ matrix.tiles }} RELEASE=1 LANGUAGES=all PCH=0 bindist
make -j$((`nproc`+0)) TILES=${{ matrix.tiles }} SOUND=${{ matrix.tiles }} LUA=1 RELEASE=1 LANGUAGES=all PCH=0 bindist
mv cataclysmbn-unstable.tar.gz cbn-${{ matrix.artifact }}-${{ needs.release.outputs.timestamp }}.tar.gz
- name: Build CBN (windows)
if: matrix.mxe != 'none'
env:
PLATFORM: /opt/mxe/usr/bin/${{ matrix.mxe }}-w64-mingw32.static.gcc11-
run: |
make -j$((`nproc`+0)) CROSS="${PLATFORM}" TILES=1 SOUND=1 RELEASE=1 LANGUAGES=all PCH=0 bindist
make -j$((`nproc`+0)) CROSS="${PLATFORM}" TILES=1 SOUND=1 LUA=1 RELEASE=1 LANGUAGES=all PCH=0 bindist
mv cataclysmbn-unstable.zip cbn-${{ matrix.artifact }}-${{ needs.release.outputs.timestamp }}.zip
- name: Build CBN (windows msvc)
if: runner.os == 'Windows'
Expand All @@ -244,7 +244,7 @@ jobs:
- name: Build CBN (osx)
if: runner.os == 'macOS'
run: |
make -j3 TILES=${{ matrix.tiles }} SOUND=${{ matrix.tiles }} RELEASE=1 LANGUAGES=all USE_HOME_DIR=1 OSX_MIN=11 PCH=0 dmgdist COMPILER=clang++
make -j3 TILES=${{ matrix.tiles }} SOUND=${{ matrix.tiles }} LUA=1 RELEASE=1 LANGUAGES=all USE_HOME_DIR=1 OSX_MIN=11 PCH=0 dmgdist COMPILER=clang++
mv CataclysmBN-unstable.dmg cbn-${{ matrix.artifact }}-${{ needs.release.outputs.timestamp }}.dmg
- name: Set up JDK 8 (android)
if: runner.os == 'Linux' && matrix.android != 'none' && matrix.mxe == 'none'
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ SET(CMAKE_TLS_VERIFY ON)
option(TILES "Build graphical tileset version." "OFF")
option(CURSES "Build curses version." "ON")
option(SOUND "Support for in-game sounds & music." "OFF")
option(LUA "Support for in-game scripting with Lua." "OFF")
option(BACKTRACE "Support for printing stack backtraces on crash" "ON")
option(LIBBACKTRACE "Print backtrace with libbacktrace." "OFF")
option(USE_HOME_DIR "Use user's home directory for save files." "ON")
Expand Down Expand Up @@ -201,6 +202,7 @@ ENDIF (CMAKE_BUILD_TYPE STREQUAL Debug)
MESSAGE(STATUS "TILES : ${TILES}")
MESSAGE(STATUS "CURSES : ${CURSES}")
MESSAGE(STATUS "SOUND : ${SOUND}")
MESSAGE(STATUS "LUA : ${LUA}")
MESSAGE(STATUS "BACKTRACE : ${BACKTRACE}")
MESSAGE(STATUS "USE_HOME_DIR : ${USE_HOME_DIR}\n")

Expand Down
4 changes: 4 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ PLF List and PLF Colony (src/list.h, src/colony.h) are licensed under the zLib l

getpost (tools/json_tools/format/getpost.h) is licensed under the MIT license, see file for text of license.

Lua (src/lua/*) is licensed under the MIT license, see src_lua/LICENSE.md for text of license.

sol2 (src/sol/*) is licensed under the MIT license, see src/sol/sol.hpp for text of license.



fmtlib (src/fmtlib_*) is licensed under the MIT license (https://github.com/fmtlib/fmt/blob/master/LICENSE.rst). The full license text is as follows:
Expand Down
36 changes: 30 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# LTO Set to 1 to enable link-time optimization.
# TILES Set to 1 to enable tiles. Requires SDL.
# SOUND Set to 1 to enable sounds. Requires SDL.
# LUA Set to 1 to enable Lua.
#
# Platforms:
# Linux/Cygwin native
Expand Down Expand Up @@ -166,8 +167,11 @@ CHKJSON_BIN = $(BUILD_PREFIX)chkjson
BINDIST_DIR = $(BUILD_PREFIX)bindist
BUILD_DIR = $(CURDIR)
SRC_DIR = src
LUA_SRC_DIR = $(SRC_DIR)/lua
ASTYLE_BINARY = astyle

CXXFLAGS += -I$(SRC_DIR) -I$(LUA_SRC_DIR)

# Enable astyle by default
ifndef ASTYLE
ASTYLE = 1
Expand Down Expand Up @@ -264,8 +268,10 @@ endif
# when preprocessor defines change, but the source doesn't
ODIR = $(BUILD_PREFIX)obj
ODIRTILES = $(BUILD_PREFIX)obj/tiles
ODIRLUA = $(BUILD_PREFIX)obj/lua
W32ODIR = $(BUILD_PREFIX)objwin
W32ODIRTILES = $(W32ODIR)/tiles
W32ODIRLUA = $(W32ODIR)/lua

ifdef AUTO_BUILD_PREFIX
BUILD_PREFIX = $(if $(RELEASE),release-)$(if $(DEBUG_SYMBOLS),symbol-)$(if $(TILES),tiles-)$(if $(SOUND),sound-)$(if $(BACKTRACE),back-$(if $(LIBBACKTRACE),libbacktrace-))$(if $(SANITIZE),sanitize-)$(if $(MAPSIZE),map-$(MAPSIZE)-)$(if $(USE_XDG_DIR),xdg-)$(if $(USE_HOME_DIR),home-)$(if $(DYNAMIC_LINKING),dynamic-)$(if $(MSYS2),msys2-)
Expand Down Expand Up @@ -573,6 +579,7 @@ ifeq ($(TARGETSYSTEM),WINDOWS)
BINDIST = $(W32BINDIST)
BINDIST_CMD = $(W32BINDIST_CMD)
ODIR = $(W32ODIR)
ODIRLUA = $(W32ODIRLUA)
ifeq ($(DYNAMIC_LINKING), 1)
# Windows isn't sold with programming support, these are static to remove MinGW dependency.
LDFLAGS += -static-libgcc -static-libstdc++
Expand Down Expand Up @@ -794,6 +801,7 @@ TESTSRC := $(wildcard tests/*.cpp)
TESTHDR := $(wildcard tests/*.h)
JSON_FORMATTER_SOURCES := tools/format/format.cpp src/json.cpp
CHKJSON_SOURCES := src/chkjson/chkjson.cpp src/json.cpp
LUA_SOURCES := $(wildcard $(LUA_SRC_DIR)/*.c)
CLANG_TIDY_PLUGIN_SOURCES := \
$(wildcard tools/clang-tidy-plugin/*.cpp tools/clang-tidy-plugin/*/*.cpp)
TOOLHDR := $(wildcard tools/*/*.h)
Expand All @@ -815,6 +823,13 @@ ifeq ($(TARGETSYSTEM),WINDOWS)
endif
OBJS = $(sort $(patsubst %,$(ODIR)/%,$(_OBJS)))

ifeq ($(LUA), 1)
DEFINES += -DLUA
LUA_OBJS = $(sort $(LUA_SOURCES:$(LUA_SRC_DIR)/%.c=$(ODIRLUA)/%.o))
else
LUA_OBJS =
endif

ifdef LANGUAGES
L10N = localization
endif
Expand Down Expand Up @@ -872,12 +887,12 @@ endif
all: version $(CHECKS) $(TARGET) $(L10N) $(TESTS)
@

$(TARGET): $(OBJS)
$(TARGET): $(OBJS) $(LUA_OBJS)
ifeq ($(VERBOSE),1)
+$(LD) $(W32FLAGS) -o $(TARGET) $(OBJS) $(LDFLAGS)
+$(LD) $(W32FLAGS) -o $(TARGET) $(OBJS) $(LUA_OBJS) $(LDFLAGS)
else
@echo "Linking $@..."
@+$(LD) $(W32FLAGS) -o $(TARGET) $(OBJS) $(LDFLAGS)
@+$(LD) $(W32FLAGS) -o $(TARGET) $(OBJS) $(LUA_OBJS) $(LDFLAGS)
@echo Done!
endif

Expand All @@ -892,12 +907,12 @@ endif
$(PCH_P): $(PCH_H)
-$(CXX) $(CPPFLAGS) $(DEFINES) $(subst -Werror,,$(CXXFLAGS)) -c $(PCH_H) -o $(PCH_P)

$(BUILD_PREFIX)$(TARGET_NAME).a: $(OBJS)
$(BUILD_PREFIX)$(TARGET_NAME).a: $(OBJS) $(LUA_OBJS)
ifeq ($(VERBOSE),1)
$(AR) rcs $(BUILD_PREFIX)$(TARGET_NAME).a $(filter-out $(ODIR)/main.o $(ODIR)/messages.o,$(OBJS))
$(AR) rcs $(BUILD_PREFIX)$(TARGET_NAME).a $(filter-out $(ODIR)/main.o $(ODIR)/messages.o,$(OBJS)) $(LUA_OBJS)
else
@echo "Creating $@..."
@$(AR) rcs $(BUILD_PREFIX)$(TARGET_NAME).a $(filter-out $(ODIR)/main.o $(ODIR)/messages.o,$(OBJS))
@$(AR) rcs $(BUILD_PREFIX)$(TARGET_NAME).a $(filter-out $(ODIR)/main.o $(ODIR)/messages.o,$(OBJS)) $(LUA_OBJS)
endif

.PHONY: version
Expand All @@ -911,6 +926,7 @@ version:

# Unconditionally create the object dir on every invocation.
$(shell mkdir -p $(ODIR))
$(shell mkdir -p $(ODIRLUA))

$(ODIR)/%.o: $(SRC_DIR)/%.cpp $(PCH_P)
ifeq ($(VERBOSE), 1)
Expand All @@ -928,6 +944,14 @@ else
@$(RC) $(RFLAGS) $< -o $@
endif

$(ODIRLUA)/%.o: $(LUA_SRC_DIR)/%.c
ifeq ($(VERBOSE), 1)
$(CXX) -xc -std=c11 -c $< -o $@
else
@echo $(@F)
@$(CXX) -xc -std=c11 -c $< -o $@
endif
scarf005 marked this conversation as resolved.
Show resolved Hide resolved

src/version.h: version

src/version.cpp: src/version.h
Expand Down
8 changes: 7 additions & 1 deletion build-scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,13 @@ else
# Use a blacklist of mods that currently fail to load cleanly. Hopefully this list will
# shrink over time.
blacklist=build-scripts/mod_test_blacklist
mods="$(./build-scripts/get_all_mods.py $blacklist)"
if [ "$LUA" == "1" ]
then
do_lua="1"
else
do_lua="0"
fi
mods="$(./build-scripts/get_all_mods.py $blacklist $do_lua)"
run_tests ./tests/cata_test --user-dir=all_modded --mods="$mods" '~*'
fi
fi
Expand Down
7 changes: 6 additions & 1 deletion build-scripts/get_all_mods.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import glob
import json

blacklist_filename, = sys.argv[1:]
assert(len(sys.argv) == 3)
blacklist_filename = sys.argv[1]
do_lua = sys.argv[2] == "1"

with open(blacklist_filename) as blacklist_file:
blacklist = {s.rstrip('\n') for s in blacklist_file.readlines()}

Expand All @@ -26,6 +29,8 @@ def add_mods(mods):
mod_info = json.load(open(info))
for e in mod_info:
if e["type"] == "MOD_INFO":
if not do_lua and "lua_api_version" in e:
continue
ident = e["id"]
if not ident in blacklist:
all_mod_dependencies[ident] = e.get("dependencies", [])
Expand Down
2 changes: 1 addition & 1 deletion build-scripts/requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if [ -n "$CATA_CLANG_TIDY" ]; then
fi

if [ -n "$LANGUAGES" ]; then
pip install --user polib
pip install --user polib luaparser
fi

# Influenced by https://github.com/zer0main/battleship/blob/master/build/windows/requirements.sh
Expand Down
1 change: 1 addition & 0 deletions data/mods/saveload_lua_test/finalize.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gdebug.log_info("SLT: finalize")
51 changes: 51 additions & 0 deletions data/mods/saveload_lua_test/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
gdebug.log_info("SLT: main")

local mod = game.mod_runtime[ game.current_mod ]
local storage = game.mod_storage[ game.current_mod ]

--[[
If we keep all our data simple and in mod.storage,
we won't even have to register save/load hooks,
it'll be saved/loaded automatically.
]]--
mod.storage = storage

--[[
The following values are default, they'll be assigned on
new game start or on game init before save is loaded.
]]
-- Numeric data
storage.num = 12.3
-- Usertype
storage.tri = Tripoint.new(3, 4, 5)
-- String
storage.tri_as_str = tostring( Tripoint.new(3, 4, 5) )

--[[
If we want to build complex state out of loaded data
we may create a hook that would read loaded data from mod_storage
and create our complex state in the mod_runtime.
]]--
mod.on_game_load_hook = function()
gdebug.log_info("SLT: on_load")

if storage.num then
gdebug.log_info( "Data found! num = ", storage.num )
end
if storage.tri then
gdebug.log_info( "Data found! tri = ", storage.tri )
end
end

--[[
If we have complex enough state (e.g. recursive tables, or with custom metatables)
we may create a hook that would write a simplified version into mod_storage,
so the hardcoded JSON serializer would be able to handle it.
]]--
mod.on_game_save_hook = function()
gdebug.log_info("SLT: on_save")

if storage.num then
gdebug.log_info("Saving NUM value = ", storage.num)
end
end
14 changes: 14 additions & 0 deletions data/mods/saveload_lua_test/modinfo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"type": "MOD_INFO",
"id": "saveload_lua_test",
"name": "SaveLoad Lua Test",
"authors": [ "Olanti" ],
"description": "Mod for testing Lua save/load API.",
"category": "content",
"lua_api_version": 1,
"//": "It's not really obsolete, but it's useful only for devs and modders, and not for player.",
"obsolete": true,
"dependencies": [ "bn" ]
}
]
11 changes: 11 additions & 0 deletions data/mods/saveload_lua_test/preload.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
gdebug.log_info("SLT: preload")

local mod = game.mod_runtime[ game.current_mod ]

game.hooks.on_game_load[ #game.hooks.on_game_load + 1 ] = function( ... )
return mod.on_game_load_hook( ... )
end

game.hooks.on_game_save[ #game.hooks.on_game_save + 1 ] = function( ... )
return mod.on_game_save_hook( ... )
end
4 changes: 4 additions & 0 deletions data/mods/smart_house_remotes/finalize.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
gdebug.log_info("SHR: finalize.")

-- We're not finalizing anything.
-- Besides, there's no finalizing API available yet.
Loading