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

Object Orientation in lua


  • Please log in to reply
6 replies to this topic

#1
StopMotionCuber

StopMotionCuber

    Newbie

  • Members
  • 6 posts

Hey Guys,

 

I'm thinking about writing Scripts for GoS in March.

Before doing that I'd like to know if it is possible to define Objects on lua.

I'm coming from C#/Python and both of them fully support object orientation.

I know that you can do many things without Objects, but when things are getting complex your code is going to be complex too and will become hard readable and hard to maintain and you will do more mistakes.

This is why I'd rather prefer to keep my code clean


  • 0

#2
pleb

pleb

    still not banned :K

  • Donator
  • 426 posts
  • Locationlithuania

yes


  • 0

#3
Kyung

Kyung

    Member

  • Members
  • 18 posts

yes

This is technically correct but not the best approach.

 

LUA, on its own, has tables which are a very powerful tool (they almost work like Javascript objects). The link that pleb gave you will tell you how to implement OOP using tables.

 

However, GoS uses LuaBind, which on its own provides a much more cpp-like OOP approach.

 

Take a look at the following documentation for more info: http://www.rasterbar...-classes-in-lua


  • 1

#4
StopMotionCuber

StopMotionCuber

    Newbie

  • Members
  • 6 posts

This is technically correct but not the best approach.

 

LUA, on its own, has tables which are a very powerful tool (they almost work like Javascript objects). The link that pleb gave you will tell you how to implement OOP using tables.

 

However, GoS uses LuaBind, which on its own provides a much more cpp-like OOP approach.

 

Take a look at the following documentation for more info: http://www.rasterbar...-classes-in-lua

 

Thanks, this is what I was looking for.

Is there somewhere some documentation for the standard object? Like what methods I can overwrite other than the initializer __init()


  • 0

#5
Kyung

Kyung

    Member

  • Members
  • 18 posts

Thanks, this is what I was looking for.

Is there somewhere some documentation for the standard object? Like what methods I can overwrite other than the initializer __init()

http://www.rasterbar...ading-operators


  • 0

#6
jouzuna

jouzuna

    Advanced Member

  • Contributor
  • 73 posts

Lua doesn't natively support classes but you can simulate the same behaviour

tables in Lua are objects which do support overloading through the use of metatables

using the __call metamethod you can create a new instance of the object with default values etc

 

in the GoS core, "classes" have been added through the use of class(className) which would store on the global/current environment (not sure which but I think its global)

along with a "custom metamethod" __init (as the class contructor)

 

I'm assuming you understand classes well enough to know when they are useful and when they are not as you've had experience in oop languages

but for others reading: please don't use classes if you don't fully understand them, I think I've seen 1 script on here where they have been correctly used


  • 0

#7
StopMotionCuber

StopMotionCuber

    Newbie

  • Members
  • 6 posts

Lua doesn't natively support classes but you can simulate the same behaviour

tables in Lua are objects which do support overloading through the use of metatables

using the __call metamethod you can create a new instance of the object with default values etc

 

in the GoS core, "classes" have been added through the use of class(className) which would store on the global/current environment (not sure which but I think its global)

along with a "custom metamethod" __init (as the class contructor)

 

I'm assuming you understand classes well enough to know when they are useful and when they are not as you've had experience in oop languages

but for others reading: please don't use classes if you don't fully understand them, I think I've seen 1 script on here where they have been correctly used

 

Thanks for the answer, will definitely have a look at it again when I will start coding

I think you have to use both though (OOP and Scripting) to get some knowledge of when Objects are useful and when not


  • 0




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users