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

Add an option to disable all Lua extensions. #1102

Merged
merged 11 commits into from
Dec 16, 2024
22 changes: 17 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ endif (WIN32)
project (server C)
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

set (USING_LUA TRUE)
if (WITHOUT_LUA)
SET (USING_LUA FALSE)
endif (WITHOUT_LUA)

if (MSVC)
find_package (PDCurses)
if (NOT PDCURSES_FOUND)
Expand All @@ -33,9 +38,20 @@ if (NOT CURSES_FOUND)
endif (NOT CURSES_FOUND)

find_package (EXPAT REQUIRED)
find_package (Lua 5.2 REQUIRED)
find_package (Utf8Proc REQUIRED)

if (USING_LUA)
find_package (Lua 5.2 REQUIRED)
else(USING_LUA)
message("Building without Lua")
endif(USING_LUA)

if (LUA_FOUND)
find_program(TOLUA_EXECUTABLE tolua REQUIRED)
find_library(TOLUA_LIBRARY tolua REQUIRED)
find_path(TOLUA_INCLUDE_DIR NAMES tolua.h HINTS ${LUA_INCLUDE_DIR} REQUIRED)
endif (LUA_FOUND)

find_library(SQLITE3_LIBRARY sqlite3 REQUIRED)
find_path(SQLITE3_INCLUDE_DIR NAMES sqlite3.h REQUIRED)

Expand All @@ -45,10 +61,6 @@ find_path(CJSON_INCLUDE_DIR NAMES cJSON.h PATH_SUFFIXES cjson REQUIRED)
find_library(INIPARSER_LIBRARY iniparser REQUIRED)
find_path(INIPARSER_INCLUDE_DIR NAMES iniparser.h PATH_SUFFIXES iniparser REQUIRED)

find_program(TOLUA_EXECUTABLE tolua REQUIRED)
find_library(TOLUA_LIBRARY tolua REQUIRED)
find_path(TOLUA_INCLUDE_DIR NAMES tolua.h HINTS ${LUA_INCLUDE_DIR} REQUIRED)

if (MSVC)
set (HAVE_STRDUP 0)
set (HAVE_STRLCAT 0)
Expand Down
5 changes: 2 additions & 3 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"variables": [
Expand Down Expand Up @@ -44,7 +43,7 @@
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\build\\${name}",
"installRoot": "${projectDir}\\install\\${name}",
"cmakeCommandArgs": "",
"cmakeCommandArgs": "-DWITHOUT_LUA=1",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ],
Expand Down Expand Up @@ -77,4 +76,4 @@
"cmakeToolchain": "${env.VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake"
}
]
}
}
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ install all of them:
liblua5.2-dev libtolua-dev libncurses5-dev libsqlite3-dev \
libcjson-dev libiniparser-dev libexpat1-dev libutf8proc-dev

If your system for some reason doesn't have Lua or the tolua library,
you can run configure with the --no-lua option to build the code
without Lua extensions. This is very much untested, and it breaks any items
or spells that have their actions implemented as Lua scripts, as well
as the Lua integration tests.

## How to check out and build the Eressea server

This repository relies heavily on the use of submodules, and it pulls in
Expand Down
4 changes: 2 additions & 2 deletions configure
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
git submodule update --init
ln -sf conf/eressea.ini
s/cmake-init
ln -sf conf/eressea.ini .
s/cmake-init "$@"
echo "configuration complete. run s/build to build the server"
3 changes: 3 additions & 0 deletions res/translations/strings.en.po
Original file line number Diff line number Diff line change
Expand Up @@ -4142,6 +4142,9 @@ msgstr "Tshrrrk..."
msgid "growl2"
msgstr "Shhhhhh..."

msgid "growl3"
msgstr "Raaaar..."

msgctxt "skill"
msgid "bow"
msgstr "bow"
Expand Down
66 changes: 26 additions & 40 deletions s/cmake-init
Original file line number Diff line number Diff line change
@@ -1,48 +1,33 @@
#!/bin/sh

WITHOUT_LUA=OFF
ERESSEA_DB=memory
pkg-config --exists sqlite3 && ERESSEA_DB=sqlite

GETOPT=getopt
GETOPT_LONG=1

if [ "Darwin" = "$(uname)" ] ; then
if [ -x "/usr/local/opt/gnu-getopt/bin/getopt" ] ; then
GETOPT="/usr/local/opt/gnu-getopt/bin/getopt"
else
GETOPT_LONG=0
fi
fi

if [ $GETOPT_LONG -eq 1 ]; then
options=$(${GETOPT} -o d: -l db: -- "$@")
else # assume GNU getopt (long arguments)
options=$(${GETOPT} d: "$@")
fi

# Parse command line arguments
usage()
{
echo "usage: $0 --help --db=DB"
}
options=$(getopt -a -l help,no-lua,db: 'hd:' "$@")
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
eval set -- "$options"
until [ -z "$1" ] ; do
case $1 in
-d|--db)
ERESSEA_DB=$2
shift
;;
--) shift; break;;
(-*) echo "$0: error - unrecognized option $1" 1>&2; exit 1;;
(*) break;;
esac
shift
done
while [ ! -z "$1" ] ; do
if [ "$1" = "--with-db" ] ; then
ERESSEA_DB=db
elif [ "$1" = "--with-sqlite" ] ; then
ERESSEA_DB=sqlite
elif [ "$1" = "--with-memory" ] ; then
ERESSEA_DB=memory
fi
shift 1

while true; do
case "$1" in
--no-lua)
WITHOUT_LUA=ON ;;
--help | -h)
usage
;;
--db | -d)
ERESSEA_DB="$2"
shift
;;
--)
break
;;
esac
shift
done

git submodule update --init
Expand Down Expand Up @@ -77,11 +62,12 @@ SET (ERESSEA_DB "$ERESSEA_DB" CACHE STRING "Database driver")
SET (CMAKE_BUILD_TYPE "$BUILD" CACHE STRING "")
SET (CMAKE_LIBRARY_PATH "$LIBRARY_PATH" CACHE PATH "")
SET (CMAKE_PREFIX_PATH "$PREFIX_PATH" CACHE PATH "")
SET (WITHOUT_LUA $WITHOUT_LUA CACHE BOOL "")
HEREDOC

set -e

cd $BIN_DIR
cmake -C config.cmake .. $*
cmake -C config.cmake ..
cd $OLDPWD

2 changes: 1 addition & 1 deletion scripts/eressea/xmlconf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local rules = 'conf'

if config.rules then
rules = rules .. '/' .. config.rules
assert(0 == eressea.config.read(rules .. '/config.json', config.install), "could not read JSON data")
assert(0 == eressea.config.read(rules .. '/config.json', config.install), "could not read JSON data from " .. rules)
end

eressea.game.reset()
67 changes: 37 additions & 30 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,17 @@ add_subdirectory(triggers)
add_subdirectory(modules)
add_subdirectory(races)

macro(ADD_LUA_MODULE MODULE_NAME FILES)
add_library (${MODULE_NAME} SHARED ${FILES})
set_target_properties(${MODULE_NAME}
PROPERTIES
PREFIX ""
if (TOLUA_EXECUTABLE)
set (_TOLUA_FILES
log.pkg.c
locale.pkg.c
config.pkg.c
process.pkg.c
game.pkg.c
eressea.pkg.c
settings.pkg.c
)
endmacro(ADD_LUA_MODULE)

set (_TOLUA_FILES
log.pkg.c
locale.pkg.c
config.pkg.c
process.pkg.c
game.pkg.c
eressea.pkg.c
settings.pkg.c
)

if (TOLUA_EXECUTABLE)
macro(TOLUA_BINDING _NAME _FILES)
set(_PKGFILE ${_NAME}.pkg)
set(_SRCFILE ${_PKGFILE}.c)
Expand Down Expand Up @@ -154,11 +146,12 @@ set(CHECK_SRC
checker.c
)

if (LUA_FOUND)
set(SERVER_SRC
bind_building.c
bind_config.c
bind_eressea.c
bind_faction.c
bind_gmtool.c
bind_locale.c
bind_message.c
bind_monsters.c
Expand All @@ -172,18 +165,26 @@ set(SERVER_SRC
bindings.c
console.c
helpers.c
signals.c
main.c
)
)
else(LUA_FOUND)
set(SERVER_SRC
processing.c
)
endif(LUA_FOUND)

if (CURSES_FOUND)
set (SERVER_SRC ${SERVER_SRC}
bind_gmtool.c
bind_config.c
gmtool.c
listbox.c
)
endif(CURSES_FOUND)

set (SERVER_SRC ${SERVER_SRC}
main.c
signals.c
)

add_library(version STATIC ${VERSION_SRC})
if(DEFINED ERESSEA_VERSION)
target_compile_definitions(version PRIVATE ERESSEA_VERSION="${ERESSEA_VERSION}")
Expand Down Expand Up @@ -216,20 +217,26 @@ endif (HAVE_LIBM)

add_library(game ${ERESSEA_SRC})
target_include_directories (game PUBLIC ${INIPARSER_INCLUDE_DIR})
target_include_directories (game PUBLIC ${TOLUA_INCLUDE_DIR})
target_include_directories (game PUBLIC ${LUA_INCLUDE_DIR})
target_link_libraries(game ${EXTRA_LIBS} parser version)

add_executable(eressea ${SERVER_SRC})
target_link_libraries(eressea
game
${TOLUA_LIBRARY}
${LUA_LIBRARIES}
${STORAGE_LIBRARIES}
${CJSON_LIBRARY}
${INIPARSER_LIBRARY}
)

if (LUA_FOUND)
target_compile_definitions(game PRIVATE HAVE_LUA)
target_compile_definitions(eressea PRIVATE HAVE_LUA)
target_include_directories (game PUBLIC ${TOLUA_INCLUDE_DIR})
target_include_directories (game PUBLIC ${LUA_INCLUDE_DIR})
target_link_libraries(eressea
${TOLUA_LIBRARY}
${LUA_LIBRARIES}
)

add_test(NAME lua-core
COMMAND eressea -v1 ../scripts/run-tests.lua
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests)
Expand All @@ -242,6 +249,7 @@ add_test(NAME lua-e3
COMMAND eressea -v1 ../scripts/run-tests-e3.lua
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests)
set_property(TEST lua-e3 PROPERTY RUN_SERIAL)
set_tests_properties(lua-core lua-e2 lua-e3 PROPERTIES LABELS "lua;ci-only")

find_program(LUAROCKS_EXECUTABLE luarocks)
if(LUAROCKS_EXECUTABLE)
Expand All @@ -252,7 +260,7 @@ string(REPLACE ";" "\;" LUA_CPATH "${LR_CPATH}")
set_tests_properties(lua-core lua-e2 lua-e3 PROPERTIES ENVIRONMENT "LUA_PATH=${LUA_PATH};LUA_CPATH=${LUA_CPATH}")
endif(LUAROCKS_EXECUTABLE)

set_tests_properties(lua-core lua-e2 lua-e3 PROPERTIES LABELS "lua;ci-only")
endif (LUA_FOUND)

set(TESTS_SRC
alchemy.test.c
Expand Down Expand Up @@ -357,18 +365,17 @@ target_include_directories (game PUBLIC ${UTF8PROC_INCLUDE_DIR})
target_include_directories (game PRIVATE ${SQLITE3_INCLUDE_DIR})
target_link_libraries(eressea ${SQLITE3_LIBRARY})
target_link_libraries(test_eressea ${SQLITE3_LIBRARY})
target_compile_definitions(game PRIVATE USE_SQLITE)

if (READLINE_FOUND)
target_include_directories (eressea PRIVATE ${READLINE_INCLUDE_DIR})
target_link_libraries(eressea ${READLINE_LIBRARY})
target_compile_definitions(eressea PRIVATE DUSE_READLINE)
target_compile_definitions(eressea PRIVATE HAVE_READLINE)
endif (READLINE_FOUND)

if (CURSES_FOUND)
target_include_directories (eressea PRIVATE ${CURSES_INCLUDE_DIRS})
target_link_libraries(eressea ${CURSES_LIBRARY})
target_compile_definitions(eressea PRIVATE USE_CURSES)
target_compile_definitions(eressea PRIVATE HAVE_CURSES)
endif(CURSES_FOUND)

if (EXPAT_FOUND)
Expand Down
16 changes: 1 addition & 15 deletions src/bind_eressea.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <kernel/save.h>

#include <util/language.h>
#include <util/log.h>

#include <stream.h>
#include <stdio.h>
Expand Down Expand Up @@ -41,20 +40,7 @@ int eressea_write_game(const char * filename) {
}

int eressea_read_orders(const char * filename) {
if (filename) {
FILE *F = fopen(filename, "r");
int result;

if (!F) {
perror(filename);
return -1;
}
log_info("reading orders from %s", filename);
result = parseorders(F);
fclose(F);
return result;
}
return -1;
return readorders(filename);
}

int eressea_export_json(const char * filename, int flags) {
Expand Down
2 changes: 1 addition & 1 deletion src/bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ lua_State *lua_init(const dictionary *inifile) {
tolua_unit_open(L);
tolua_message_open(L);
tolua_order_open(L);
#ifdef USE_CURSES
#ifdef HAVE_CURSES
tolua_gmtool_open(L);
#endif
tolua_storage_open(L);
Expand Down
2 changes: 1 addition & 1 deletion src/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#define lua_strlen(L, idx) lua_rawlen(L, idx)
#endif

#ifdef LUA_USE_READLINE
#ifdef HAVE_READLINE
#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>
Expand Down
Loading
Loading