UsefulCodes - Wwarrior1/NodeMCU GitHub Wiki
Useful Commands
file.remove("init.lua")
node.compile("info.lua")
require("basic") == dofile("basic.lc")
package.loaded['filename']=nil | only with require()
collectgarbage()
Useful codes
Volatile Module templates
local M, module = {}, ...
...
function M.init(csocket)
package.loaded[module]=nil
...
end
...
return M
Using: require("connector").init(c)
local module = _ -- this is a situation where using an upvalue is essential!
return function (csocket)
package.loaded[module]=nil
module = nil
...
end
Using: require("connector")(c)
Memory cleanup
Load some functions and at the end call init()
!!! Otherwise our volatile modules won't work.
Additionally there is a little improvement while assigning tmp
to some function and then reassign it to nil
.
tmp = require("basic_compile").compileAllFiles()
tmp = nil
require("basic_compile").init()
collectgarbage()
Command to LuaSrcDiet:
./LuaSrcDiet.lua --maximum --details --opt-srcequiv ../../Modules/api/init.lua -o ../../Modules/api/init_.lua