Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Put briefly, wOOP is an OO library that uses userdata and some metatable magic to allow support for a few important things-
- "implied" self
- "pseudomethods"
- private values
- readonly values
- constructors
- finalizers
- single-level inheritance
- and lastly, a short, clean syntax.
- 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.
- SYNTAX-
- class function
- class <classname> <extends>?
- <data>
- classname is a string for the class name.
- extends is a string for which the class inherits from. (default base)
- data is a table containing all the necessary data. (see class structure)
- creating objects
- All classes are global. Use <classname>(args) to create an object.
- destroying objects
- Remove an object from memory (goes through and deletes all local values equal to the object)
- CLASS STRUCTURE-
- 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-
- new(...)
- 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.
- mt
- Table used as metatable for the object. __gc is supported if using userdata.
- CONFIG TABLE USAGE-
- imply_self (bool) [true] Change functions to pseudomethods (see pseudomethods).
- self_name (string) ["self"] If using imply_self, what the name of the value is.
- using_userdata (bool) [true] Use userdata as a proxy to the object. (__len and __gc)
- strict_error (bool) [true] Objects cannot be modified to have new values or change private values, attempting either will error.
- private_value (bool) [true] Use private values.
- private_value_index (string) ["__"] What separates private values from normal values. Include at start of table index.
- readonly_value(_index) See private_value(_index). Defaults are [true] and ["_"], respectively.
- class_config_location (string) ["__setings"] Where the class config is located. Set to "class" for directly in the class itself. (see class structure)
- class_config_setup (table) [{new="new",mt="mt"}] Defines the name of the "new" and "mt" functions inside the class config. (see class structure)
- USAGE-
- PSEUDOMETHODS-
- 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 ":".
- Send any suggestions/comments to LuaWeaver on the love2d forums.
- EXAMPLE-]]
- class "example"
- {
- asdf=0;
- qwer=10;
- add=
- function()
- return self.asdf+self.qwer
- end
- }
- class "example2" "example"
- {
- sub=
- function()
- return self.asdf-self.qwer
- end
- }
- local e2=example2()
- e2.asdf=15
- print(e2.add())
- print(e2.sub())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement