Advertisement
LuaWeaver

[v1.2] wOOP (Docs)

Mar 26th, 2013
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.82 KB | None | 0 0
  1. --[[
  2. Put briefly, wOOP is an OO library that uses userdata and some metatable magic to allow support for a few important things-
  3.  
  4. "implied" self
  5. "pseudomethods"
  6. private values
  7. readonly values
  8. constructors
  9. finalizers
  10. single-level inheritance
  11. and lastly, a short, clean syntax.
  12.  
  13. It also follows the ClassCommons specifications - if you set common_class to true BEFORE requiring it. All tests have run been run on (and in fact passed) this library. This library is bug-free (as far as been tested (enough)) and is easy to use.
  14.  
  15. SYNTAX-
  16. class function
  17.  
  18. class <classname> <extends>?
  19. <data>
  20.  
  21. classname is a string for the class name.
  22. extends is a string for which the class inherits from. (default base)
  23. data is a table containing all the necessary data. (see class structure)
  24.  
  25. creating objects
  26. All classes are global. Use <classname>(args) to create an object.
  27.  
  28. destroying objects
  29. Remove an object from memory (goes through and deletes all local values equal to the object)
  30.  
  31. CLASS STRUCTURE-
  32. There are some values in a class that are important. Use __settings (or what you've set it to) and you may include the following values-
  33.  
  34. new(...)
  35. Function that gets called when creating an object. Returns a table that has values in it that is used for the base of the object.
  36.  
  37. mt
  38. Table used as metatable for the object. __gc is supported if using userdata.
  39.  
  40. CONFIG TABLE USAGE-
  41. imply_self (bool) [true] Change functions to pseudomethods (see pseudomethods).
  42. self_name (string) ["self"] If using imply_self, what the name of the value is.
  43. using_userdata (bool) [true] Use userdata as a proxy to the object. (__len and __gc)
  44. strict_error (bool) [true] Objects cannot be modified to have new values or change private values, attempting either will error.
  45. private_value (bool) [true] Use private values.
  46. private_value_index (string) ["__"] What separates private values from normal values. Include at start of table index.
  47. readonly_value(_index) See private_value(_index). Defaults are [true] and ["_"], respectively.
  48. class_config_location (string) ["__setings"] Where the class config is located. Set to "class" for directly in the class itself. (see class structure)
  49. class_config_setup (table) [{new="new",mt="mt"}]  Defines the name of the "new" and "mt" functions inside the class config. (see class structure)
  50.  
  51. USAGE-
  52.     PSEUDOMETHODS-
  53.         A pseudomethod is a function that has it's environment changed to include a "self" value - so you don't have to. Changes functions to use a "." instead of a ":".
  54.  
  55. Send any suggestions/comments to LuaWeaver on the love2d forums.
  56.  
  57. EXAMPLE-]]
  58.  
  59. class "example"
  60. {
  61.     asdf=0;
  62.     qwer=10;
  63.     add=
  64.     function()
  65.         return self.asdf+self.qwer
  66.     end
  67. }
  68.  
  69. class "example2" "example"
  70. {
  71.     sub=
  72.     function()
  73.         return self.asdf-self.qwer
  74.     end
  75. }
  76.  
  77. local e2=example2()
  78. e2.asdf=15
  79. print(e2.add())
  80. print(e2.sub())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement