View previous topic :: View next topic |
Author |
Message |
Chris12 Expert Cheater Reputation: 1
Joined: 27 Apr 2012 Posts: 103
|
Posted: Wed Feb 27, 2013 1:27 pm Post subject: How do I read all values a lua script or function returned?? |
|
|
Hi,
I'm executing this lua code:
Code: | local m = getMemoryViewForm()
if m ~= nil then
return disassemblerview_getSelectedAddress(memoryview_getDisassemblerView(m))
end
return 0 |
This is how I do it (on cheatengines main thread of course!):
Code: |
int originalStack = GetTop(); << returns zero
LoadString(luaCode);
int preCallStack = GetTop(); << returns 1 because the code is on the stack
ProtectedCall(0, -1, 0); <<< just a wrapper for the c-function: "pcall"
int postCallStack = GetTop(); << returns 2, why???
...
|
Now what I don't understand:
originalStack = 0
preCallStack = 1
so far so good, but after the protected call why is postCallStack = 2?
It should be 1 or not ??
Now when I look what values there are on the stack like this:
Code: |
string a = GetString();
Pop(1);
string b = GetString();
|
a and b are the same value (always the correct one, the currently selected line in the memory view).
So why does "return disassemblerview_getSelectedAddress..." push the the return value on the lua stack twice ??
Now another example (lua)
Code: |
return getOpenedProcessID()
|
when this is the code I am executing then the stack is like this:
originalStack = 0
preCallStack = 1 (the value on the stack is the lua-function)
postCallStack = 1 (the value on the stack here is the return value of the called function)
That single value on the stack is correct. (the process it of CEs target)
My understanding is that pcall pops the function off the stack and only leaves the return values.
But it seems that is only the case for my second example.
In my more complex code (the first example) there are suddenly two (same) return values.
Why is it like this?
In general, how do I get the number of values a lua script returned?
I always thought the difference between the stack-top before and after the "pcall" is the number of return values ??
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25288 Location: The netherlands
|
Posted: Wed Feb 27, 2013 2:51 pm Post subject: |
|
|
disassemblerview_getSelectedAddress() returns 2 results. The currently selected address and the secondary address (when multiselecting lines, the same as the first one otherwise).
That is why postCallStack is 2 because there are 2 values returned.
I assume that your second parameter is the nResults parameter. If you change that from -1 to 1 it will only return 1 result (the first one)
_________________
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 |
|
|
Chris12 Expert Cheater Reputation: 1
Joined: 27 Apr 2012 Posts: 103
|
Posted: Wed Feb 27, 2013 11:49 pm Post subject: |
|
|
Ahhh
That clears up everything. Thanks
|
|
Back to top |
|
|
|