WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   LUA Scoping Semantics (https://www.wowinterface.com/forums/showthread.php?t=55857)

mtp1032 11-16-17 11:49 AM

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:
Quote:

attempt to call global 'parseStackTrace' (a nil value)
(ASIDE: I'm using !Swatter)

my .toc file contains these lines
Quote:

<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,

Kakjens 11-16-17 12:42 PM

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.

Fizzlemizz 11-16-17 01:41 PM

See the reply on the WoW Forum

jeffy162 11-16-17 03:12 PM

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). :o Sorry, I couldn't help myself.

Kakjens 11-17-17 04:54 AM

It seems like Fizzlemizz forgot to provide a link for people who might have similar problem.


All times are GMT -6. The time now is 10:58 AM.

vBulletin © 2021, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI