Jump to content

Welcome to Gaming On Steroids Forums
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account
Photo

Classes in LUA


  • Please log in to reply
4 replies to this topic

#1
Kyung

Kyung

    Member

  • Members
  • 18 posts

In this version of LUA used by GOS, is there a specific API for creating and instantiating classes? By looking at some of the open source code, I see some people using the 'class' keyword, but looking at LUA wikis I generally see using tables as classes.

Any specific way to do this in the GOS api?


  • 0

#2
Ryzuki

Ryzuki

    Advanced Member

  • Contributor
  • 297 posts
  • LocationOsu!z

you can read: lua metatable


  • 0

#3
Deftsu

Deftsu

    donthackourgames

  • Ex-Core Dev
  • PipPipPip
  • 4,812 posts
class "template"
function template:__init(args) 
  -- put anything that you want to load when initaiting the class here
  -- use this for accessing the class (can be used only when inside class functions, thinks of it as 'this' in C#, would be something like : self.somevar = 5 instead of this.somevar = 5 
end
template(args) -- load the class
btw you don't have to put any args, it's not neccessary.
  • 1

#4
Kyung

Kyung

    Member

  • Members
  • 18 posts
class "template"
function template:__init(args) 
  -- put anything that you want to load when initaiting the class here
  -- use this for accessing the class (can be used only when inside class functions, thinks of it as 'this' in C#, would be something like : self.somevar = 5 instead of this.somevar = 5 
end
template(args) -- load the class
btw you don't have to put any args, it's not neccessary.

 

Specifically to this, is there a way to define properties in lua (with getters and setters)?


  • 0

#5
jouzuna

jouzuna

    Advanced Member

  • Contributor
  • 73 posts

Specifically to this, is there a way to define properties in lua (with getters and setters)?

would need to make use of __index and __newindex metamethods


  • 0




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users