A really, really great write up!! Thank you so much for this. Ive finished my second read of it.
I have a question on volatile modules and specifically the volatile function. You posted up some code:
local module ... -- this is a situation where using an upvalue is essential!
return function (csocket)
package.loaded[module]=nil
module = nil
-- . . .
end
and I mostly understand all of this except for the very first line "local module ... --comment"
When i compile this in the esp i get a lua error: stdin:1: spl.lua:1: unexpected symbol near '...'
I cannot seem to determine why this would be. Any help please??
Here is the full volatile module/function:
local spl ...
return function split(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={}
local i=1
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
t[i] = str
i = i + 1
end
package.loaded['spl']=nil
spl=nil
return t
end
local module = ...
will set the local variable module to "spl". The require() will set package.loaded.spl to reference the returned function, preventing its garbage collection, hence
package.loaded[module]=nil
will remove this reference so once all other references go out of scope, the memory used by the module can be garbage collected.
I hope this explanation helps.