1. #1

    Good way to learn Lua for addon creation purposes?

    I've decided that I want to look at learning Lua programming, specifically for developing addons or at the least modifying addons. I'm aware of the tutorial on the Lua website for the basics of the language, but I haven't found much dealing specifically with addon development. I know there was a book on WoW programming, but it was several years old so not sure if it's out of date.

    My previous job was as a software developer so I am familiar with programming concepts (I have used Visual Basic.NET, C#, Javascript and some Python and Ruby, although my experience is mostly small scripts and web app development) although some of Lua's things are a little foreign to me (e.g. it seems there isn't the concept of classes, at least not within addon development, and you use Lua tables to create a hash that doubles as a class).

    Can anyone point me to some resources to get started with this? I can look up the API related things but I haven't found many resources or tutorials on creating addons, creating the UI for an addon (I'm aware of the XML involved in it, just not any resources on using it, if there are any). Should I just dive in with an addon (and if so any recommendations for a well-written addon that's not too complex)?

  2. #2
    The Forgettable Forgettable's Avatar
    10+ Year Old Account
    Join Date
    May 2010
    Location
    Calgary, Canada
    Posts
    5,180
    I also am interested in this topic. Sadly, I cannot offer any substantial advice for you.

  3. #3
    The Patient
    15+ Year Old Account
    Join Date
    Apr 2008
    Location
    United Kingdom
    Posts
    319
    You don't necessarily need to use XML for frames, I prefer to just use LUA but it can be done either way. As for learning LUA I would say start with developing something small, create your own addon and take it from there to expand it gradually, that's what I did at least and it worked out better than reading through tutorials.

  4. #4
    Quote Originally Posted by suprep View Post
    You don't necessarily need to use XML for frames, I prefer to just use LUA but it can be done either way. As for learning LUA I would say start with developing something small, create your own addon and take it from there to expand it gradually, that's what I did at least and it worked out better than reading through tutorials.
    The issue is learning the syntax which if we are honest is the main issue that we all face once we try to learn a language. I mean once you learn say java programming itself isn't hard to do across the board but rather learning the nuances between c++ and java.
    He slipped out of his royal garments, left eternity to enter time, divinity to wrap himself in humanity.
    The sea of glass, for the ocean of separation. He left peace, and for the first time felt pain.
    Because the very hands that held the stars were now sentenced to wear my scars.

  5. #5
    Deleted
    I'll give you my usual post for this kind of situation, then.

    Quote Originally Posted by Treeston View Post
    1. Don't use WYSIWYG. Use Notepad++ or a comparable plain text editor.
    2. TOC format information
    3. Lua 5.1 manual
    4. API doc, event doc, widget doc. There's also the FrameXML, but you probably won't have to look into it until you get into hooking.
    5. Feel free to ask for any advice regarding issues you're having on this forum - we'll be more than happy to assist.
    6. You can also find me on IRC if you have questions. The channel is #mmo-champion @quakenet - if you're not familiar with it, there's a simple webchat you can use.
    7. It's also helpful to look at other peoples' code. Most authors will be happy to help you out with any questions you have regarding their code if they're not busy. You can find most of them in the #wowace/#curseforge/#wowuidev channels on freenode.

  6. #6
    Deleted
    This is the base for nearly any addon. I'm still learning myself and a great tutor is Tuller. His mods are very well written.

    https://github.com/tullamods

    Code:
    --addon name and addon namespace
    local addonName, ns = ...
    
    --create the application object
    local APP = CreateFrame("Frame")
    
    --add a reference to your app to the addon namespace (so you can use it any of your lua files)
    ns.app = APP 
    
    --local functions are private and only known for the lua file they live in
    local function PrintHelloWorldLocal()
      print("Hello World Local")
    end
    
    --the next function not global and not local, it is part of your application and can be used in any lua file of your addon
    function APP:PrintHelloWorldApp()
      print("Hello World App")
    end
    
    --the last one should be used very rarely since it polutes the global namespace
    --this function can be called from any other addon since it is part of the global namespace
    function PrintHelloWorldGlobal()
      print("Hello World Global")
    end
    
    
    --------------------------------
    -- FUNCTIONS
    --------------------------------
    
    --addon load func
    function APP:Load()
      self:SetScript("OnEvent", self.OnEvent)
      self:RegisterEvent("PLAYER_REGEN_ENABLED")
      self:RegisterEvent("PLAYER_REGEN_DISABLED")
    end
    
    --event handler function
    --this may look wierd in first place but is very useful since it directs events automatically to the event functions that are registered to the app
    function APP:OnEvent(event, ...)
      local action = self[event]
      if action then
        action(self, event, ...)
      end
    end
    
    function APP:PLAYER_REGEN_ENABLED()
      print("PLAYER LEAVES COMBAT")
    end
    
    
    function APP:PLAYER_REGEN_DISABLED()
      print("PLAYER ENTERS COMBAT")
    end
    
    --------------------------------
    -- INIT
    --------------------------------
    
    --load the app
    APP:Load()

    Here is that code as a first addon:
    http://code.google.com/p/rothui/down...MyFirstApp.zip

    Code:
    http://code.google.com/p/rothui/sour...ve/MyFirstApp/
    http://code.google.com/p/rothui/sour...MyFirstApp.toc
    http://code.google.com/p/rothui/sour...stApp/core.lua
    Last edited by mmoc48efa32b91; 2013-08-23 at 08:18 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •