Lua: "class"

VheliumVhelium Join Date: 2012-11-24 Member: 173049Members
Hi everyone,

as a budding developper I wanted to use the potential of this fantastic game to create mods for it.
I'm very fimilar with C# and Java and also used Lua for some simple projects.
When I looked through the code I saw in nearly every file the definition of a class like "class 'ARC' (ScriptActor)".
I have never seen this kind of class definition in Lua and I also didnt find anything like this on the internet.

Can someone explain me, how this exactly works?
Thanks.

Greetings,

Vhelium

Comments

  • DavilDavil Florida, USA Join Date: 2012-08-14 Member: 155602Members, Constellation
    It's possible he created his own function called class and ScriptActor is another class so this is creating an instance of the ScriptActor class called ARC.
  • HuzeHuze Insightful Join Date: 2003-11-12 Member: 22724Members, NS1 Playtester, NS2 Playtester, Squad Five Blue, Reinforced - Shadow
    This is inheritance. The equivalent in C# is
    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->public class ARC : ScriptActor<!--c2--></div><!--ec2-->

    You should watch Brian's talk on NS2's lua code here:
    <a href="http://www.twitch.tv/naturalselection2/b/341658557" target="_blank">http://www.twitch.tv/naturalselection2/b/341658557</a> Starts at 11:20
  • extolloextollo Ping Blip Join Date: 2010-07-16 Member: 72457Members
    it's an lua language extension from luabind. check the docs for that.
  • jeffcojeffco Join Date: 2011-02-14 Member: 81785Members
    edited November 2012
    'class' is a lua extension. I guess "class 'ARC' (ScriptActor)" translates to "ARC = {}; for k,v in pairs(ScriptActor) do ARC[k] = v end".
  • VheliumVhelium Join Date: 2012-11-24 Member: 173049Members
    Ok I see.
    Thank you guys for the help.
    I thought it must be like that, but I was confused because I have never seen it in Lua before.
    Also thanks for the link.

    Vhelium
Sign In or Register to comment.