TangentFoxy / Pop.Box

(ON HOLD) Pop.Box is an easy to use GUI library for the LÖVE engine, intended for rapid prototyping.
http://guard13007.github.io/Pop.Box/docs
MIT License
8 stars 4 forks source link

Figure out how to create elements without using MoonScript's class system #28

Open TangentFoxy opened 8 years ago

TangentFoxy commented 8 years ago

Essentially, I just need to understand how MoonScript's classes work, and then create something that someone can easily use to create their own classes that inherit properly.

TangentFoxy commented 7 years ago

Raw notes from examining it:

base obj with an __index to itself, contains functions accepting a self argument,
 and __class pointing to class obj

class is obj w __init function, __base linking to base obj, and __name specifying name of class
 it has metatable, __index is the base table (makes perfect sense),
  __call is a function that creates a self obj w the base obj as a metatable, then calls __init
     on it, and returns the self (__init is never meant to get directly called)

inheritance addtionally does:

new base obj will have a metatable set to parent.__base (where parent is parent class obj)
new class obj will have __parent value linking to parent class obj, and __index metamethod
  that returns rawget(new base, name) or return parent class[name] if that was nil
if parent class had __inherited, then is called w parent class and new class
TangentFoxy commented 7 years ago

While untested, I'm going to mark this fixed on dev branch because it should work as far as I know, and it will only be tested when I (or someone) gets around to trying to use it.