Skip to content

Compile script #311

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

Merged
merged 1 commit into from
Feb 14, 2020
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
21 changes: 16 additions & 5 deletions bin/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,31 @@ if [ ${#MANIFEST[@]} -eq 0 ]; then
exit 1
fi

SCRIPTS_LUA=obj/SCRIPTS/BF/COMPILE/scripts.lua

echo 'local scripts = {' >> $SCRIPTS_LUA
for f in ${MANIFEST[@]};
do
echo ' ''"'${f/\obj/}'",' >> $SCRIPTS_LUA
done
echo '}' >> $SCRIPTS_LUA
echo 'return scripts[...]' >> $SCRIPTS_LUA

MANIFEST+=($SCRIPTS_LUA);

for f in ${MANIFEST[@]};
do
SRC_NAME=$f
OBJ_NAME=$(dirname ${f})/$(basename ${f} .lua).luac
echo -e "Compiling file \e[1m${SRC_NAME}\e[21m..."
luac -s -o ${OBJ_NAME} ${SRC_NAME}
echo -e "Testing file \e[1m${SRC_NAME}\e[21m..."
luac -p ${SRC_NAME}
_fail=$?
if [[ $_fail -ne 0 ]]; then
LAST_FAILURE=$_fail
echo -e "\e[1m\e[39m[\e[31mBUILD FAILED\e[39m]\e[21m Compilation error in file ${SRC_NAME}\e[1m"
echo -e "\e[1m\e[39m[\e[31mBUILD FAILED\e[39m]\e[21m Error in file ${SRC_NAME}\e[1m"
fi
done

if [[ $LAST_FAILURE -eq 0 ]]; then
echo -e "\e[1m\e[39m[\e[32mTEST SUCCESSFUL\e[39m]\e[21m All lua files built successfully!"
echo -e "\e[1m\e[39m[\e[32mTEST SUCCESSFUL\e[39m]\e[21m"
fi
exit $LAST_FAILURE
21 changes: 21 additions & 0 deletions src/SCRIPTS/BF/COMPILE/compile.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
local i = 1

local function compile()
local script = assert(loadScript("COMPILE/scripts.lua"))(i)
collectgarbage()
i = i + 1
if script then
lcd.clear()
lcd.drawText(2, 2, "Compiling...", SMLSIZE)
lcd.drawText(2, 22, script, SMLSIZE)
assert(loadScript(script, 'c'))
collectgarbage()
return 0
end
local file = io.open("COMPILE/scripts_compiled.lua", 'w')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had been looking for a way to persist state in lua - this seems to be a good way to do so.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 . The first iteration of this had compile.lua delete it's contents when finished. Quickly abandoned that idea lol.

io.write(file, "return true")
io.close(file)
return 1
end

return compile
1 change: 1 addition & 0 deletions src/SCRIPTS/BF/COMPILE/scripts_compiled.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
return false
19 changes: 12 additions & 7 deletions src/SCRIPTS/TOOLS/bf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ chdir("/SCRIPTS/BF")

apiVersion = 0

protocol = assert(loadScript("protocols.lua"))()
radio = assert(loadScript("radios.lua"))()
local run = nil
local scriptsCompiled = assert(loadScript("COMPILE/scripts_compiled.lua"))()

assert(loadScript(protocol.transport))()
assert(loadScript("MSP/common.lua"))()
if scriptsCompiled then
protocol = assert(loadScript("protocols.lua"))()
radio = assert(loadScript("radios.lua"))()
assert(loadScript(protocol.transport))()
assert(loadScript("MSP/common.lua"))()
run = assert(loadScript("ui.lua"))()
else
run = assert(loadScript("COMPILE/compile.lua"))()
end

local run_ui = assert(loadScript("ui.lua"))()

return { run=run_ui }
return { run=run }