[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: debug.setlocal does not correctly restore values for variables localized inside subblocks (or so it seems)
- From: Paul K <paulclinger@...>
- Date: Thu, 19 Jul 2012 23:14:26 -0700
> To solve this, simply store by numeric local ID, rather than name.
I suspected the answer should be a simple one, but was missing it. So,
the reason for the bug is that there may be several variables with the
same name (as they localize each other), but they will still have
different ids. As far as I understand, ids go in the order in which
the variables appear in the block. Thanks Declan!
Paul.
On Thu, Jul 19, 2012 at 10:45 PM, Declan White <deco.da.man@gmail.com> wrote:
> Paul K <paulclinger <at> yahoo.com> writes:
>
>>
>> I came across this issue while investigating a bug in my debugger (MobDebug).
>>
>> It looks like debug.setlocal does not correctly restore variables that
>> are localized inside subblocks in a function.
>>
>
> Paul,
>
> You are storing the local variables by name, but their identifying key is
> numeric.
>
> Here's how your code plays out:
>
> function f()
> local a = 1
> do
> local a = 2
> end
> end
>
> t = {}
> t['a'] = 1 -- finds local #1
> t['a'] = 2 -- finds local #2, this overrides the value in the table, as I'm sure
> you understand
>
> local #1 = t['a'] -- sets the top a to 2
> local #2 = t['a'] -- sets the bottom a to 2
>
> To solve this, simply store by numeric local ID, rather than name.
>
> e.g:
> local vars, i = {}, 1
> while true do
> local name, value = debug.getlocal(func, i)
> vars[i] = value
> i = i+1
> end
> -- same idea for restore code
>
> Hope this helps,
> Declan.
>
>
>