Newbie lua question menu

Shout-Out

User Tag List

Results 1 to 3 of 3
  1. #1
    Thomja's Avatar Almost Legendary User
    Reputation
    538
    Join Date
    Nov 2008
    Posts
    639
    Thanks G/R
    14/38
    Trade Feedback
    3 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Newbie lua question

    Ok so tried the bawx but nobody seemed to know lua in there so heres my thread instead.

    Code:
    counter = {
    count = 0
    }
    function counter:get()
    return self.count
    end
    function counter:inc()
    self.count = self.count + 1
    end
    
    This code is roughly equivalent to the following definition:
    
    counter = {
    count = 0
    }
    function counter.get(self)
    return self.count
    end
    function counter.inc(self)
    self.count = self.count + 1
    end
    
    Test this new version with the following code:
    > print(counter:get())
    0
    > counter:inc()
    > counter:inc()
    > print(counter:get())
    2
    Ok so I know that the counter:get() auto adds the self argument. But how does it know what the self argument is when you call it without giving the self argument a name?

    When I call counter.get(counter) it makes sense. However when I call counter:get() without giving it the argument counter it somehow has to know that the invisible self argument is called counter :S
    I really don't have anything interesting to put here anymore.

    Newbie lua question
  2. #2
    nhjelle's Avatar Active Member
    Reputation
    17
    Join Date
    Jan 2009
    Posts
    94
    Thanks G/R
    0/0
    Trade Feedback
    2 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's a hidden aspect of using the colon operator in lua. It effectively adds a parameter to the function definition and adds an argument to the function call - both of which are self.
    counter is being used as a pointer in both the inc and get functions so self refers to counter.

  3. #3
    Haroon525's Avatar Banned
    Reputation
    1
    Join Date
    Jun 2014
    Posts
    9
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have also try it but there is no any solid result found by me.

Similar Threads

  1. [Lua] Newbie Lua scripting question (SOLVED)
    By Maybepie in forum WoW EMU Questions & Requests
    Replies: 10
    Last Post: 04-16-2010, 07:21 AM
  2. [LUA] Question
    By Algorithm in forum World of Warcraft Emulator Servers
    Replies: 9
    Last Post: 04-14-2008, 02:50 PM
  3. LUA Question (advanced?)
    By CairiFEA in forum World of Warcraft Emulator Servers
    Replies: 5
    Last Post: 04-13-2008, 01:57 AM
  4. LUA Question
    By CairiFEA in forum World of Warcraft Emulator Servers
    Replies: 8
    Last Post: 04-10-2008, 08:10 PM
  5. script lua question
    By onilank in forum World of Warcraft Emulator Servers
    Replies: 2
    Last Post: 12-21-2007, 06:58 PM
All times are GMT -5. The time now is 10:25 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search