Where are my local variables displayed in the Variables window?

In my Lua script, I have a lot of local variables defined at the top. For example:

[lua]local foo = 0
local bar = 0

function something
end[/lua]
When I look in my Variable window, which does contain a few real global variables, my functions, and a lot of other stuff, I don’t see my local variables. Are they hiding somewhere?

Thanks!

  • Bret

[import]uid: 168791 topic_id: 31749 reply_id: 331749[/import]

Hello Bret,

Thanks for your interest!
We think the problem is because of the way Lua optimizes upvalues. For instance, say we are at a breakpoint below:

local foo = 0  
local bar = 0  
   
function something  
--Breakpoint here  
end  

Just visually looking you would expect foo and bar to be present in the stack but they are actually not unless you use them in that function. In this case neither foo nor bar will be seen in that stack frame. Now take for instance:

local foo = 0  
local bar = 0  
   
function something  
print(foo)  
--Breakpoint here  
end  

now in this case foo will show up in the stack but bar will not. This is because these locals are upvaues (aka static variables) and only show up if used inside functions.

Is this the case for you?

Regards,
M.Y. Developers [import]uid: 55057 topic_id: 31749 reply_id: 126818[/import]

Thanks for the reply,

Yup, that sounds like my situation. I’m sure that I can work around it at this point. Thanks so much for the information!

  • Bret [import]uid: 168791 topic_id: 31749 reply_id: 126829[/import]

Hello Bret,

Thanks for your interest!
We think the problem is because of the way Lua optimizes upvalues. For instance, say we are at a breakpoint below:

local foo = 0  
local bar = 0  
   
function something  
--Breakpoint here  
end  

Just visually looking you would expect foo and bar to be present in the stack but they are actually not unless you use them in that function. In this case neither foo nor bar will be seen in that stack frame. Now take for instance:

local foo = 0  
local bar = 0  
   
function something  
print(foo)  
--Breakpoint here  
end  

now in this case foo will show up in the stack but bar will not. This is because these locals are upvaues (aka static variables) and only show up if used inside functions.

Is this the case for you?

Regards,
M.Y. Developers [import]uid: 55057 topic_id: 31749 reply_id: 126818[/import]

Thanks for the reply,

Yup, that sounds like my situation. I’m sure that I can work around it at this point. Thanks so much for the information!

  • Bret [import]uid: 168791 topic_id: 31749 reply_id: 126829[/import]