View Single Post
07-29-12, 01:22 AM   #1
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 124
Question Looking for a dumbed down explanation of a couple of things!

Hey all. Cheers to anyone who is able to spare a moment or two to help me with this.

I've been self learning Lua and there's a couple of niggling things that I can't seem to get my head around without some sort of help.

I've been using the official manual, the Tutorial Directory at Lua-users wiki, and Phanx's Ace3 Getting Started guide on wowace.

Anyway, to the point.



1. I understand the below function, how it works and how to call it.

Lua Code:
  1. function MyFunction(arg1, arg2 arg3)
  2.   -- block
  3.   return arg1, arg2, arg3 -- (optional)
  4. end

But I don't understand this at all...

Lua Code:
  1. function MyFunction(...)
  2.   -- block
  3. end

What is the "..." for when creating/calling a function? I've read in the past that it's a string delimiter, but I'm unsure what it does/means. Any chance of a small example and an explanation of what it's doing.?



2. If I put the above function in a global functions table like...

Lua Code:
  1. EarthernFunctionTable = {
  2.                                     [1] = MyFunction,
  3.                                     [2] = MyOtherFunction
  4.                                   }

... am I correct in saying that these functions are then available to all frames (and/or even all loaded addons?)



3. I'd like to call a function with several arguments. But say I'd rather not pass the first arg... how do I skip the first argument and move on to the second?

Is it something like...

Lua Code:
  1. MyFunction(_, arg2, arg3)

... Then again, I've tried that and it's returned an error in the past.

4. Last one, I promise! I'm looking to create a function that can be called as follows...

Lua Code:
  1. MyFrame:MyFunction(arg1, arg2, arg3)

... I understand that this is done in the following way...

Lua Code:
  1. function obj:FunctionName(arg1, arg2, arg3)

... I'm not sure I understand the above instruction though. What should 'obj' be (keeping in mind that the aim is for any frame to be able to use it). Is it simply 'self'?

Regarding the examples: I think I've created all the above functions with 3 arguments. I know that a function can have several (or zero) arguments depending on what's required.


If you've got this far, thanks alot for taking the time to read . Phanx, if ever you read this, thanks very much for the Ace3 tutorial on wowace. It's been a great help so far.
__________________
__________________
  Reply With Quote