Lua string concatenation

Want Cheat Engine to do something specific and no idea how to do that, ask here. (From simple scripts to full trainers and extensions)
Post Reply
S1N74X
Cheater
Cheater
Posts: 40
Joined: Wed Sep 15, 2021 4:25 pm
Reputation: 4

Lua string concatenation

Post by S1N74X »

Hello,

need your opinion.
Currently iam fiddeling around with Pointeroffsets.
I have an repeating pattern. But in between the offsets are changing.
Spoiler

Code: Select all

local startp = '[[[[pb]+120]+' -- start of Pointerpath
local endp = ']+11A0]' -- end of Pointerpath
local offsetResult = nil 

local offsets = {0,8,10,18,20,28,30,38,40,48,50} -- offset Table

for i=1,#offsets  do
offsetResult =  startp .. offsets[i] .. endp
print(offsetResult) -- or readFloat or whatever
end
The Output :
[[[[pb]+120]+0]+11A0]
[[[[pb]+120]+8]+11A0]
....
Works as expected.
My question is :
String concatenation is claimed to be slow.
What is your experience ?
How would you solve such a Problem?

Usefull hints or suggestions are welcome.

TheByteSize
Expert Cheater
Expert Cheater
Posts: 293
Joined: Sat Mar 04, 2017 7:28 am
Reputation: 236

Re: Lua string concatenation

Post by TheByteSize »

How about use Assembly instead? ;)

panraven
Table Makers
Table Makers
Posts: 129
Joined: Fri Mar 03, 2017 12:03 am
Reputation: 118

Re: Lua string concatenation

Post by panraven »

Most pure lua running time should be neglectable compare to inter-process memory read/write.
lua string concatenation is said to be inefficient mostly only when creating too many intermediate string within a heavy loop.
It seems your case is fine if just a few strings created once and done, ie the address strings are fixed, only the interpreted address content of the fixed symbols eg. pb or [pb] changed with time, which should be handled by CE internally.

S1N74X
Cheater
Cheater
Posts: 40
Joined: Wed Sep 15, 2021 4:25 pm
Reputation: 4

Re: Lua string concatenation

Post by S1N74X »

TheByteSize wrote:
Thu Dec 02, 2021 1:44 am
How about use Assembly instead? ;)
Thx for your reply.
I am not experienced enough yet to do this in pure ASM
Still learning :)

S1N74X
Cheater
Cheater
Posts: 40
Joined: Wed Sep 15, 2021 4:25 pm
Reputation: 4

Re: Lua string concatenation

Post by S1N74X »

panraven wrote:
Thu Dec 02, 2021 9:30 am
Most pure lua running time should be neglectable compare to inter-process memory read/write.
lua string concatenation is said to be inefficient mostly only when creating too many intermediate string within a heavy loop.
It seems your case is fine if just a few strings created once and done, ie the address strings are fixed, only the interpreted address content of the fixed symbols eg. pb or [pb] changed with time, which should be handled by CE internally.
Thank you for your Answer.
After taking a nap, i came up with this solution.
Spoiler

Code: Select all

--on script activation
local startp = '[[[[pb]+120]+' -- ppstart
local endp = ']+11A0]' -- ppend
local offsetResult = nil 
local offsets = {0,8,10,18,20,28,30,38,40,48,50} -- offsets
local results = {} -- result of concatination

for i=1,#offsets  do
offsetResult =  startp .. offsets[i] .. endp -- build pp string
table.insert(results,offsetResult) -- store pp string
end
 
-- in timed condition
for j=1,#results do
print(results[j]) -- or readFloat or whatever
end

No one said i have to do the concationation at "runtime" :)

Post Reply

Who is online

Users browsing this forum: No registered users