Defining classes in Lua?

FocusedWolfFocusedWolf Join Date: 2005-01-09 Member: 34258Members
edited June 2011 in Modding
How does one create a custom class, <u>with overloaded operators</u>, in ns2 lua?

I'm guessing, since i can't get it to work, that it's not like luabind anymore? <a href="http://www.rasterbar.com/products/luabind/docs.html#overloading-operators" target="_blank">http://www.rasterbar.com/products/luabind/...ading-operators</a>

Comments

  • fsfodfsfod uk Join Date: 2004-04-09 Member: 27810Members, NS2 Developer, Constellation, NS2 Playtester, Squad Five Blue, Squad Five Silver, Squad Five Gold, Subnautica Playtester, NS2 Community Developer, Pistachionauts
    With metatables <a href="http://lua-users.org/wiki/MetamethodsTutorial" target="_blank">http://lua-users.org/wiki/MetamethodsTutorial</a>
    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local mt = {
      __add = function(self, right)
        return self.somefield+right.somefield
      end
      __sub = function(self, right)
        return self.somefield-right.somefield
      end
    }

    //Normally you would just do setmetatable(OurObject, mt) for non class() stuff.
    //For stuff declared with class() the object created with mytype() call is a userdata object so we need modify its existing
    //metatable we need todo this just once on our created object
    local objectmt = debug.getmetatable(OurObject)

    for name,value in pairs(mt) do
      objectmt[name] = value  
    end<!--c2--></div><!--ec2-->
  • SewlekSewlek The programmer previously known as Schimmel Join Date: 2003-05-13 Member: 16247Members, NS2 Developer, NS2 Playtester, Squad Five Gold, Subnautica Developer
    edited June 2011
    hey, someone knows a nice editor for lua ns2?
    i really loved the code navigation in eclipse for the most languages, but unfortunately its not working
    in lua-eclipse.

    has someone a suggestion?
  • Josh86Josh86 Join Date: 2010-12-06 Member: 75513Members
    I've used Eclipse, too, but with Java.

    You can try Decoda, which was developed by UWE. I haven't really tried it but I'm pretty sure I've seen it included in the tools that come with NS2. I'm not much of a programmer, but I hope that's what you might be looking for. You mentioned ease of code navigation -- I'm not sure of all the perks Decoda has. It says it's an IDE and not just a debugger, so I assume you can use it like any editor.

    Otherwise I've downloaded Notepad++ and use that to make up any quick code or just to mess around. I like light and simple stuff.
  • FocusedWolfFocusedWolf Join Date: 2005-01-09 Member: 34258Members
    edited June 2011
    I'm using UltraEdit. Notepad++ was good for a while, but when your code gets into the 1000 lines territory, the need for a way to actually collapse functions (which Notepad++ fails at for some reason... the C style comments confuse it) and a window for actually seeing what functions you have for quick browsing is very useful.

    <a href="http://i.imgur.com/HmkWb.png" target="_blank">http://i.imgur.com/HmkWb.png</a>

    Also a warning. You can't just install UltraEdit and achieve an awesome state. You need to remove many toolbars + configure a bunch of options + install a .uew lua language word file so it can understand lua (i'm using a custom one that i had to make just to get functions to fold correctly). Also UltraEdit sucks! at syntax coloring so i had to get a third party tool "UltraEdit Color Scheme Manager" Just to get some half decent syntax coloring. Yes it was worth it. It works very good now :P
  • SewlekSewlek The programmer previously known as Schimmel Join Date: 2003-05-13 Member: 16247Members, NS2 Developer, NS2 Playtester, Squad Five Gold, Subnautica Developer
    i tried decoda, eclipse and notepad++ (im not convinced ^^). im searching for something that actually can undestand the meaning of a "class" and "methods" (+properties) of them. so rather
    browsing through files, browse through collapseable object lists, which shows you all those informations and enables you to jump to their definitions. maybe i just want to much :D
    or i have to write my own plugin for eclipse, but then... i prefer simply using what I already have.

    nevertheless, functionality like call hirarchy or simple code navigation (Ctrl+left mbutton -> jump to definition) would be really nice. i really like the comfort
    to see in a fast and simple way (without searching for it) who calls "me", what happens before and afterwards.
  • RokiyoRokiyo A.K.A. .::FeX::. Revenge Join Date: 2002-10-10 Member: 1471Members, Constellation
    The closest I've found to an IDE is sylvanaar's Lua plugin he's developing for IntelliJ.
    IntelliJ-IDEA IDE: <a href="http://www.jetbrains.com/idea/download/" target="_blank">http://www.jetbrains.com/idea/download/</a>
    Lua-for-IDEA plugin: <a href="https://bitbucket.org/sylvanaar2/lua-for-idea/wiki/Home" target="_blank">https://bitbucket.org/sylvanaar2/lua-for-idea/wiki/Home</a>

    I haven't looked in on the project in about 6 months, but AFAIK he's still actively working on it. If you wish to speak to sylvanaar directly, he can usually be found on the #wowace channel on freenode.net irc.
  • SewlekSewlek The programmer previously known as Schimmel Join Date: 2003-05-13 Member: 16247Members, NS2 Developer, NS2 Playtester, Squad Five Gold, Subnautica Developer
    that looks good so far:

    <img src="https://bitbucket.org/sylvanaar2/lua-for-idea/wiki/9-13-2010-9-22-40.png" border="0" class="linked-image" />

    i will try it, thanks :)
  • CrispyCrispy Jaded GD Join Date: 2004-08-22 Member: 30793Members, Constellation
    Has anyone used this who can recommend it?

    It looks like it would be helpful for someone who is mainly muddling through Lua by dipping into someone else's code.
  • SewlekSewlek The programmer previously known as Schimmel Join Date: 2003-05-13 Member: 16247Members, NS2 Developer, NS2 Playtester, Squad Five Gold, Subnautica Developer
    im not satisfied with any options currently out there, and I might realyl will write (or alter an existing) addon for eclipse. Its still the editor of my choice :)
    Decode I tried just once, its not bad (better than most other editors out there) but its not starting anymore in win7 64-bit, so its currently anyway no option (at least for me) I have also seen that there are multiple eclipse plugins already out there for lua, so I will try them aswell before, and if they are any good I'll let you know
Sign In or Register to comment.