This is a WoW (World of Warcraft) lua script question. Not many of these get asked here but I have no where to turn and Stackoverflow is the programmer oasis for answers.
Question:
Wowwiki states that the 2nd, 3rd, 4th arguments are your calling functions 1st, 2nd, 3rd arguments. I don't find this to be true. I find that the 3rd, 4th, 5th arguments end up being the 1st, 2nd, 3rd arguments.
Link: http://www.wowwiki.com/API_pcall
Function:
function myTest(arg1) return arg1 .. 10; end
Problem:
local retOK, ret1 = pcall(myTest,"string value");
when I try the sample I get an error of "trying to perform concatenate on local 'arg1' (a nil value)". If I change the code to
local retOK, ret1 = pcall(myTest,"string value", "bob");
then I get the output of "bob10". Where does the 2nd argument go and what is it for?
More Testing:
function BobsToolbox:RunTest() local test1, value1 = pcall(BobsToolbox.Test1, "string value"); SharpDeck:Print("Test1: " .. tostring(test1) .. " Value: " .. tostring(value1)); end
function BobsToolbox:Test1(arg1) return arg1 .. "10"; end
Results: attempt to concatenate local 'arg1' (a nil value)
function BobsToolbox:RunTest() local test1, value1 = pcall(Test1, "string value"); SharpDeck:Print("Test1: " .. tostring(test1) .. " Value: " .. tostring(value1)); end
function Test1(arg1) return arg1 .. "10"; end
Results: string value10
I am new to lua and I can't understand why these are different.
New Question:
The following code works but why?
function BobsToolbox:RunTest() local test1, value1 = pcall(BobsToolbox.Test1, "string value"); SharpDeck:Print("Test1: " .. tostring(test1) .. " Value: " .. tostring(value1)); end
function BobsToolbox.Test1(arg1) return arg1 .. "10"; end
What's the difference between the following: ("." vs ":")
- function BobsToolbox.Test1(arg1)
- function BobsToolbox:Test1(arg1)