I have been doing a fair amount of lua recently for the RCP. I am an experience programmer but have never had to program lua until a few weeks ago. I got very frustrated when my scripts would exceed the max size allowed by the RCP. I understand why the constraints are there but I still wasn't happy about it.
What I discovered is that the compiled lua code includes variable names and other debug information that can bloat the size of the resulting compiled lua bytecode. I like to use friendly global variable names when declaring things like constants and things of that nature. This practice really bloated the size of the resulting compiled LUA code.
Then I discovered luasrcdiet. This project will automatically shorten variable names and functions if they are declared local. The resulting code is unreadable but as far as getting code to fit on the RCP it has proven very effective.
Basically you run your code through luasrcdiet (making sure your code declares local variables as local) and it will allow you to fit much more code on the RCP than it normally would support.
You can find the code on github here:
https://github.com/LuaDist/luasrcdiet
I noticed as much as a 70% reduction in the size of the compiled bytecode. I hope this helps others.
ProTip - luasrcdiet to reduce compiled bytecode size
Fair warning you will need to be comfortable using the command line to use this tool.
I will be using my mutlicam GoPro script as an example. You can find it here:
https://github.com/eacmen/hpde/blob/mas ... lticam.lua
Notice which variables I marked as local and which ones I didn't. Anything that is contained within your file can be marked local. However functions like onTick cannot since that is the function that the RCP calls and its function name cannot be changed.
Make sure you have lua installed on your machine (apt-get install lua51 on linux, or various download packages available for Windows or OSX).
Download and extract luasrcdiet from git: https://github.com/LuaDist/luasrcdiet/a ... master.zip
Copy your lua script into the luasrcdiet-master directory that was created when you extracted the above file.
Create the "diet" lua file:
You should now be able to take this file and copy and paste it into the RCP interface.
However lets compare the compiled size between the two:
First compile the lua scripts.
Now lets compare their size:
I will be using my mutlicam GoPro script as an example. You can find it here:
https://github.com/eacmen/hpde/blob/mas ... lticam.lua
Notice which variables I marked as local and which ones I didn't. Anything that is contained within your file can be marked local. However functions like onTick cannot since that is the function that the RCP calls and its function name cannot be changed.
Make sure you have lua installed on your machine (apt-get install lua51 on linux, or various download packages available for Windows or OSX).
Download and extract luasrcdiet from git: https://github.com/LuaDist/luasrcdiet/a ... master.zip
Copy your lua script into the luasrcdiet-master directory that was created when you extracted the above file.
Create the "diet" lua file:
Code: Select all
lua LuaSrcDiet.lua gopro_session_multicam.lua -o gopro_session_multicam.diet.lua
However lets compare the compiled size between the two:
First compile the lua scripts.
Code: Select all
luac -o gopro_session_multicam.lua.out gopro_session_multicam.lua
luac -o gopro_session_multicam.diet.lua.out gopro_session_multicam.diet.lua
Code: Select all
-rw-r--r-- 1 peter peter 8995 Oct 11 11:35 gopro_session_multicam.diet.lua.out
-rw-r--r-- 1 peter peter 9867 Oct 11 11:21 gopro_session_multicam.lua.out
Sorry, but what are the advantages or disadvantages when comparing it to Lua minifier?
https://mothereff.in/lua-minifier
https://mothereff.in/lua-minifier
--Paulo