Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Lua 5.4 Released

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4702

PostPosted: Sat Aug 15, 2020 2:00 pm    Post subject: Lua 5.4 Released Reply with quote

https://www.lua.org/manual/5.4/readme.html#changes
Features:
  • 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.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25792
Location: The netherlands

PostPosted: Sun Aug 16, 2020 3:59 am    Post subject: Reply with quote

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)

f.BorderStyle=bsSizeable
f.Position=poScreenCenter
f.Name="form"..counter

f.OnClose=function(s,ca)
  s.Caption='Nope' --replace with f.Caption and the form will never autodestroy
  return caNone
end


local formname=f.name

local mt=getmetatable(f)


local olddestroy=mt.destroy
mt.destroy=function(x)
  print("form "..formname.." gets destroyed now")

  if olddestroy then
    olddestroy(x)
  else
    print("old destroy was nil")
  end
  print("bye "..formname)
end
mt.__autodestroy=true

print("created "..f.name)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4702

PostPosted: Sun Aug 16, 2020 11:38 am    Post subject: Reply with quote

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

--[[ Output:

foo()
  1 closed
  1 closed
  0 closed
closure()
return
  1 closed

]]

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites