|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Reaper79 Advanced Cheater Reputation: 2
Joined: 21 Nov 2013 Posts: 68 Location: Germany
|
Posted: Thu Aug 14, 2014 1:32 pm Post subject: using LUA variable in ASM script ? |
|
|
Hi, following situation:
Code: |
[ENABLE]
{$LUA}
errorOnLookupFailure(false)
local result = nil
local modules = { "module1.dll", "module2.dll", "module3.dll" }
for i = 0, table.getn(modules) do
result = getAddress(modules[i])
if (result ~= 0) then result = modules[i] break end
end
return [[ aobscanmodule(injectPoint1, ]] .. result .. [[,00 11 22 33 44)
aobscanmodule(injectPoint2,]] .. result .. [[,55 66 77 88)]]
{$ASM}
etc...
etc...
|
this works fine, but is there any other way to write the return more nicely ? this looks weired when i have more aobscans...
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 457
Joined: 09 May 2003 Posts: 25262 Location: The netherlands
|
Posted: Thu Aug 14, 2014 2:04 pm Post subject: |
|
|
The aa command define(modulename,bla.dll) will rewrite modulename with bla.dll before the script gets executed
You can also return a string variable you build in multiple iterations, lua does support string concatenation and /n
_________________
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 |
|
|
Redouane Master Cheater Reputation: 3
Joined: 05 Sep 2013 Posts: 363 Location: Algeria
|
Posted: Thu Aug 14, 2014 2:28 pm Post subject: Re: using LUA variable in ASM script ? |
|
|
Reaper79 wrote: | Hi, following situation:
Code: |
[ENABLE]
{$LUA}
errorOnLookupFailure(false)
local result = nil
local modules = { "module1.dll", "module2.dll", "module3.dll" }
for i = 0, table.getn(modules) do
result = getAddress(modules[i])
if (result ~= 0) then result = modules[i] break end
end
return [[ aobscanmodule(injectPoint1, ]] .. result .. [[,00 11 22 33 44)
aobscanmodule(injectPoint2,]] .. result .. [[,55 66 77 88)]]
{$ASM}
etc...
etc...
|
this works fine, but is there any other way to write the return more nicely ? this looks weired when i have more aobscans... |
There are many ways to do it:
You could make all the final string parts into a table,then use table.concat.
You could also use string.format,like this:
Code: | return ([[aobscanmodule(injectPoint1,%s,00 11 22 33 44)
aobscanmodule(injectPoint2,%s,55 66 77 88)]]):format(result,result)
--the __index of strings points to the string table,same as this:
string.format('aobscanmodule(injectPoint1,%s,00 11 22 33 44)\naobscanmodule(injectPoint2,%s,55 66 77 88)',result,result) |
Also,why are you using table.getn?you could use #modules directly.
|
|
Back to top |
|
|
Reaper79 Advanced Cheater Reputation: 2
Joined: 21 Nov 2013 Posts: 68 Location: Germany
|
Posted: Thu Aug 14, 2014 3:28 pm Post subject: |
|
|
Thank you guys,
string.format will do it for now. Also i changed the table.getn to #modules.
Is the # a shortcut for tables.getn ? Is it more performant or why not use tables.getn ? (performance / readability ?)
|
|
Back to top |
|
|
Redouane Master Cheater Reputation: 3
Joined: 05 Sep 2013 Posts: 363 Location: Algeria
|
Posted: Thu Aug 14, 2014 5:58 pm Post subject: |
|
|
Reaper79 wrote: | Thank you guys,
string.format will do it for now. Also i changed the table.getn to #modules.
Is the # a shortcut for tables.getn ? Is it more performant or why not use tables.getn ? (performance / readability ?) |
table.getn is deprecated in recent versions of Lua,it does not even exist in Lua 5.2,that means that your code may become non compatible with upcoming versions of CE,also,if you are looking for performance,I'd recommend you to read this book:
http://www.lua.org/gems/sample.pdf
Also this:
http://lua-users.org/wiki/OptimisationCodingTips
Quote:
Short inline expressions are better than function calls,for instance, t[#t+1]=v is better than table.insert(t,v),even if it does the same job.
Also,the length operator '#' can be used on both strings and tables (and sometimes other objects),when it's used with tables,it returns the number of elements in the table,when used on strings,it returns the length of the string,its behaviour can be modified with the __len metamethod,that's why I said that it can also be used on other objects (it just calls the metamethod if it's a proper function and returns whatever that function returns).
|
|
Back to top |
|
|
Reaper79 Advanced Cheater Reputation: 2
Joined: 21 Nov 2013 Posts: 68 Location: Germany
|
Posted: Fri Aug 15, 2014 1:37 am Post subject: |
|
|
Thank you very much for this detailed explanation.
|
|
Back to top |
|
|
|
|
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
|
|