Jump to content




How does OOP works?


  • You cannot reply to this topic
2 replies to this topic

#1 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 14 May 2013 - 08:39 AM

I heared that OOP works in lua, but how does it work?

I heared something about metatables but my brain isn't available to understand it alone :D

#2 makerimages

  • Members
  • 236 posts

Posted 14 May 2013 - 08:43 AM

have a look at http://computercraft.../wiki/Metatable I haven`t used it myself so I can`t give any advie on that, I usually work with regular tables for my OOP-style needs

#3 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 14 May 2013 - 08:52 AM

OOP stands for Object Oriented Programming, and metatables are used to give special properties to tables. Metatables and OOP are two completely different subjects. Metatables are used in OOP, however.

The basic concept of OOP is using objects that contain the functions for your program, instead of managing all of the separate variables on your own.

CC already has an example or two of OOP and non-OOP, specifically peripheral functions.

Non-OOP:
peripheral.call('right', 'write', 'Hello World!')

OOP:
monitor = peripheral.wrap('right')
monitor.write('Hello World!')

As you can see here, we use a monitor object as a "middle-man" for calling a function rather than calling the function ourself. In this example, it does take longer, but using OOP does shorten operations in the longrun. Imagine the above examples, but with a couple hundred more writing operations. Using the monitor object would be less typing, no?





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users