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 


Enumerating list of Lua objects created?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
predprey
Master Cheater
Reputation: 24

Joined: 08 Oct 2015
Posts: 486

PostPosted: Fri May 20, 2016 11:23 pm    Post subject: Enumerating list of Lua objects created? Reply with quote

Suppose I created a form previously in Lua engine named "Form". If I run the script to create the form again, the previous form is not overwritten but a new form named "Form_1" is created.

These forms do not seemed to be assigned to CE as they do not show up when enumerating through all the getForm().Name.

Is there a way to find out all the list of global variables and objects created previously?

Another question I have is what is the flag "DoNotSaveInTable" for? I thought if set to false, it meant the form would appear inside "Table" submenu of CE's main window.

------------------------------------------------------------

EDIT: Ok, I read up on Lua environment. We can get the list of global variables through:
Code:
for n in pairs(_G) do print (n) end

Though it would be easier if we can distill it down to those created by the user, but I guess that would be more complex.

Regarding "DoNotSaveInTable", it seems to dictate whether a form is saved together with the .CT file and doesn't affect if it is displayed as a menu item.
Back to top
View user's profile Send private message
Redouane
Master Cheater
Reputation: 3

Joined: 05 Sep 2013
Posts: 363
Location: Algeria

PostPosted: Sat May 21, 2016 4:57 am    Post subject: Re: Enumerating list of Lua objects created? This post has 1 review(s) Reply with quote

To loop through all the user-created forms, you could write something like this:
Code:
for i,v in pairs(_G) do -- use _G or _ENV
     if type(v) == 'userdata' and v['getClassName'] and v.getClassName() == 'TCEForm' then print(i);
     end
end

Also, you could create the form only once in your script, and show it when the script runs (Check if the form exists, if it does, show it, otherwise, create the form and save it in a global variable, then show it).
No idea about the doNotSaveInTable flag (never found it necessary to use it)
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Sat May 21, 2016 9:58 am    Post subject: This post has 1 review(s) Reply with quote

That won't give you all the created Lua forms if you assign two forms to the same global variable (or if you don't store the form in a global variable). Take this code as an example:
Code:
-- creates a copy of the current _ENV
local bak = {}
for k,v in pairs(_ENV) do
  bak[k] = v
end

-- makes a form
createForm()

-- compares the current _ENV with the copy and prints any differences
for k,v in pairs(_ENV) do
  if not (bak[k] and bak[k] == v) then
    print("k:",k,"\tv:",type(v))
  end
end

This prints out nothing because no new global variables were added; however, it still created the form, and the memory that form takes up still exists. Just be careful with what you do and always destroy the stuff you don't need any more.

_________________
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
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sat May 21, 2016 2:28 pm    Post subject: Reply with quote

to keep all the forms in some variable you can override original function:
Code:
collectedLuaCreatedForms = {}

if createFormOrig==nil then createFormOrig=createForm end

function createForm(...)
  local newForm=createFormOrig(...)
  collectedLuaCreatedForms[#collectedLuaCreatedForms+1] = newForm
  return newForm
end

function destroyAllLuaCreatedForms()
  for _,v in ipairs(collectedLuaCreatedForms) do
    v.destroy()
  end
  collectedLuaCreatedForms = {}
end

Then calling destroyAllLuaCreatedForms() will destroy all of them.






Or without overriding. You can use myCreateForm() to create forms. And destroyAllMyForms() to destroy all of them:
Code:
collectedMyForms = {}

function myCreateForm(...)
  local newForm=createForm(...)
  collectedMyForms[#collectedMyForms+1] = newForm
  return newForm
end

function destroyAllMyForms()
  for _,v in ipairs(collectedMyForms) do
    v.destroy()
  end
  collectedMyForms = {}
end

_________________
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine 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