Improves modules sourcing

A module should always begin with a test to `execute_module` to see if
it should be executed. As modules are always sourced
(even when embedded), a simple `return` will stop the subscript.

Modules are executed in a subscript, so the global space will not be
polluted, and will also be reset after the execution of the module.

This commit also solves some bugs in Makefile and lua parser.
This commit is contained in:
Antonin Décimo
2015-06-14 18:17:43 +02:00
parent 06d5369877
commit 72ada933f1
7 changed files with 60 additions and 23 deletions

View File

@@ -11,7 +11,7 @@ SED_INSTALL_DIR=$(shell echo "$(INSTALL_DIR)" | sed -e 's/[\/&]/\\&/g')
love-release: clean
mkdir -p $(BUILD_DIR)
sed -e 's/INSTALL=false/INSTALL=true/' -e 's/SCRIPTS_DIR="scripts"/SCRIPTS_DIR="$(SED_INSTALL_DIR)\/scripts"/' love-release.sh > '$(BUILD_DIR)/love-release'
sed -e 's/INSTALLED=false/INSTALLED=true/' -e 's/SCRIPTS_DIR="scripts"/SCRIPTS_DIR="$(SED_INSTALL_DIR)\/scripts"/' love-release.sh > '$(BUILD_DIR)/love-release'
cp love-release.1 '$(BUILD_DIR)/love-release.1'
gzip '$(BUILD_DIR)/love-release.1'
@@ -26,9 +26,9 @@ install:
embedded: clean
mkdir -p '$(BUILD_DIR)'
sed 's/EMBEDDED=false/EMBEDDED=true/' love-release.sh > '$(BUILD_DIR)/love-release.sh'
for file in scripts/*; do \
for file in scripts/*.sh; do \
module="$$(basename -s '.sh' "$$file")"; \
content='if [[ $$(execute_module "'"$$module"'") == true ]]; then'$$'\n'"$$(cat $$file)"$$'\n''fi'$$'\n\n'; \
content='(source <(cat <<\EndOfModule'$$'\n'"$$(cat $$file)"$$'\n''EndOfModule'$$'\n''))'$$'\n\n'; \
echo "$$content" >> "$(BUILD_DIR)/tmp"; \
done
sed -i.bak -e '/include_scripts_here$$/r $(BUILD_DIR)/tmp' '$(BUILD_DIR)/love-release.sh';