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

Compile script #311

Merged
merged 1 commit into from
Feb 14, 2020
Merged

Compile script #311

merged 1 commit into from
Feb 14, 2020

Conversation

klutvott123
Copy link
Member

Adds a script that compiles all Betaflight lua files the first time bf.lua is executed.
build.sh has been repurposed to create a file containing a table with the files to be compiled. The .lua files are tested for errors using luac -p. No .luac files are created.

As discussed in #281 the main memory issue we have now is running out of memory when compiling the betaflight lua scripts on the TX. OpenTX uses a modified version of LUA 5.2.2 with lua tiny RAM applied. This means that precompiled scripts will not work unless they are created with a version of lua that has had the same mod applied.

I believe the problem with on device compilation is that we're trying to load too many files in one lua cycle(bf.lua). The solution is to use a compile script that loads and compiles one file each lua cycle.

compile.lua will only run the first time bf.luais executed. It loads and compiles all files listed in scripts.lua one by one and exits when done. The next time bf.lua is executed everything will be as normal. compile.lua will not run again unless scripts_compiled.lua is modified or overwritten(new bf lua version).

"Free mem" in OpenTX shows over 40KB after running this(used to be close to 0 or out of memory).

Adds a script that compiles all Betaflight lua files the first time bf.lua is executed.
build.sh has been repurposed to create a file containing a table with the files to be compiled. The .lua files are tested for errors using luac -p. No .luac files are created.
@mikeller mikeller added this to the 1.5 milestone Feb 12, 2020
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.

@mikeller mikeller merged commit 968d5be into betaflight:master Feb 14, 2020
@klutvott123 klutvott123 deleted the compile-script branch March 19, 2020 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants