Advertisement
LuaWeaver

Food class wOOP

May 7th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.86 KB | None | 0 0
  1. class "food"
  2. {
  3.         eaten=false,
  4.         eat=
  5.         function()
  6.                 if self.eaten then
  7.                         print("You bite into nothing, it hurts your teeth.")
  8.                 else
  9.                         print(("The %s has been eaten :("):format(self.name))
  10.                         self.eaten=true
  11.                 end
  12.         end,
  13.        
  14.         __settings=
  15.         {
  16.                 new=
  17.                 function(name)
  18.                         print(("Delicous %s has been created!"):format(name))
  19.                         return {name=name}
  20.                 end,
  21.                 mt=
  22.                 {
  23.                         __gc=
  24.                         function(self)
  25.                                 if not self.eaten then
  26.                                         print(("You throw the %s into the trash (what a waste)."):format(self.name))
  27.                                 else
  28.                                         print(("You throw the crumbs of %s into the trash."):format(self.name))
  29.                                 end
  30.                         end,
  31.                        
  32.                         __add=
  33.                         function(self,other)
  34.                                 if type(other)=="userdata" and other.isA("food") then
  35.                                         print("You smash the two foods together and create:")
  36.                                         return _G[self.className](("%s-y %s"):format(self.name,other.name))
  37.                                 end
  38.                         end
  39.                 }
  40.         }
  41. }
  42.  
  43. class "cake" "food"
  44. {
  45.         eat=
  46.         function()
  47.                 print("LIES!")
  48.                 self.eaten=true
  49.         end
  50. }
  51.  
  52. class "candy" "food"
  53. {
  54.         eat=
  55.         function()
  56.                 print("The dentist frowns upon you.")
  57.                 self.eaten=true
  58.         end
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement