Quantcast
LUA Scoping Semantics - WoWInterface
Thread Tools Display Modes
11-16-17, 11:49 AM   #1
mtp1032
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 22
LUA Scoping Semantics

Hello,

I'm a very new to LUA programming (2 full days), tho' I do have an extensive background in C/C++ and Java. Alas, I have run into what appears to be a scoping problem and I'm confused. Here's the problem:

in mylib.lua I have the function definition

Code:
function parseStackTrace()
<lines of code>
end
And in my testing framework, myLibTests.lua, I have


Code:
function runTests()
    local result1, result2, result3 = parseStackTrace( debugstack())
end
When executed, the test fails with the following error message:
attempt to call global 'parseStackTrace' (a nil value)
(ASIDE: I'm using !Swatter)

my .toc file contains these lines
<boiler plate>
myLib.lua
myLibTests.lua
It's clear I'm missing something important and probably familiar to most LUA programmers. So, can someone either explain what's going on or point me to the appropriate documentation?

Cheers,
  Reply With Quote
11-16-17, 12:42 PM   #2
Kakjens
A Cliff Giant
Join Date: Apr 2017
Posts: 75
I suggest to paste whole code, instead of snippets. For example, I don't see what calls runTests().
Additional issue is use of global functions. While in debugging phase it's OK but "good" add-ons try to avoid polluting global environment.
If you plan to use something as an argument in a function, both the call, and function definition has to have variable (at worst case, ellipsis).
Also, for WoW to know the new content of toc file, you need to restart it but you probably already knew it.
  Reply With Quote
11-16-17, 01:41 PM   #3
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,389
See the reply on the WoW Forum
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
11-16-17, 03:12 PM   #4
jeffy162
A Pyroguard Emberseer
 
jeffy162's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 2,364
I can't help with your problem, but, I can clear up one other thing: it is "Lua" (a Portuguese word meaning "moon") not"LUA" (it is a word, not an acronym). Sorry, I couldn't help myself.
__________________
Ahhhh, the vagueries of the aging mind. Wait.... What was I saying?


Carbonite <----- GitHub main module (Maps ONLY) download link. The other modules are also available on GitHub.
Carbonite-CLASSIC<----- GitHub link to Carbonite Classic. Thanks to ircdirk for this!
  Reply With Quote
11-17-17, 04:54 AM   #5
Kakjens
A Cliff Giant
Join Date: Apr 2017
Posts: 75
It seems like Fizzlemizz forgot to provide a link for people who might have similar problem.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » LUA Scoping Semantics

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off