Adds a generational garbage collector - even the default settings may work better than the current incremental GC, especially for timers. Some objects might never be collected if a major collection never needs to happen, but at least users shouldn't need to worry about garbage collection themselves or experience seemingly unbounded logarithmic growth in memory usage when using many timers (topic 1 / topic 2)
const variables - can't believe it took this long
to-be-closed variables - allows you to "close" variables when they go out of scope, even on errors (equate w/ RAII); likely a better alternative to the current system of autodestroy userdata objects on garbage collection
Other stuff
Breaking changes (haven't looked into these):
Precompiled chunks might not be compatible - some people's attempts at obfuscating Lua scripts might break
bitwise operations on strings no longer automatically coerce strings to integers
print() no longer calls tostring() to format its arguments; instead, "it has this functionality hardwired. You should use __tostring to modify how values are printed."
collectgarbage() interface has changed
Some C API and other stuff
_________________
I don't know where I'm going, but I'll figure it out when I get there.
Joined: 09 May 2003 Posts: 25792 Location: The netherlands
Posted: Sun Aug 16, 2020 3:59 am Post subject:
It's nice. But not sure if it will get added to CE yet.
collect garbage: CE already does that since 7.0 or so. It has an active collectGarbage and passive garbage collection going on in the background when the GUI is active
const variables: I guess, but not the end of the world to miss it
to-be-closed variables: It's handy but can't be implemented into CE by default as some scripts expect local var declared objects keep existing even after the script has finished. (e.g forms and timers)
Here's an example script showing how automatic garbage collection can be used
Code:
if counter==nil then
counter=1
else
counter=counter+1
end
local f=createForm(true)
to-be-closed variables: my bad, I was under the impression they were tied to the value itself and not the variable.
It seems too easy to copy the value and have the __close metamethod called multiple times. I can't think of a good way of reference counting it either (no __copy metamethod)
Some code I was playing around with:
Code:
mt = {
__close = function(v, err)
print(err or v.message)
end
}
local function foo()
local table0<close> = setmetatable({ message = " 0 closed" }, mt)
local table1<close> = setmetatable({ message = " 1 closed" }, mt)
local table2<close> = table1
return function()
return table1
end
end
print'foo()'
local closure = foo()
print'closure()'
local table1<close> = closure()
print'return'
return
CE users are barely using metatables right now - I can't see many people using to-be-closed variables (or const for that matter). If someone thinks otherwise, feel free to speak up.
If garbage collection is in a good state now too, I don't see any reason to update to Lua 5.4, especially if it breaks existing tables. Maybe this can be revisited when Lua 5.5 comes out in another 3-5 years. _________________
I don't know where I'm going, but I'll figure it out when I get there.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum