SHARE
TWEET

Untitled

a guest Jan 28th, 2020 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[=[
  2.  
  3. TODO: Optimize operation of the registry.
  4.  
  5. idVars:
  6.     - Attached to id, read-only.
  7.     - Classes/Interfaces requiring idVars must define their defaults in:
  8.          istats/defaults/idv.
  9.    
  10. classVars:      ??? Needed ???
  11.     - Attached to class, aka static, read-write.   
  12.  
  13. instanceVars:
  14.     - Applied onto the instance, read-write, each instant holds its own version.
  15.     - Classes/Interfaces requiring idVars must define their defaults in:
  16.          istats/defaults/instv.
  17.    
  18.    
  19.    
  20. Registry init:
  21.     Iterate over the following folders, indexing into the following:
  22.     defaults/idv/   -> Reg.defaults.idv
  23.     defaults/instv/ -> Reg.defaults.instv
  24.     data/           -> Reg.data
  25.         Note: data is split into idv/instv based on the provided defaults.
  26.             A datum with no underlying default is ignored!
  27.             TODO: Change it so that extra datums are considered instvs?
  28.            
  29.     Extra:
  30.         defaults can be a function
  31.  
  32. Registry usage:
  33.     1- Thing (or child) calls Registry:apply(self, id).                 --initial call.
  34.     2- The hierarchy of self is explored to gather all classes/interfaces,
  35.         def a table of their __name__ fields as h.                      --fetch hierarchy.
  36.          
  37.     3- All entries defined by the given class's defaults get            ---idv
  38.         getters created for them in the instance:                       --create getters, with defaults-fallback.
  39.         --(iterating over h)                                            --
  40.         className = h[i]                                                --iterate all defaults of the given hierarchy.
  41.         def = Reg.defaults.idv[className]                               --fetch all default idvs of className (current iteration).
  42.         dat = Reg.data                                                  --access ALL registry data. (not sectioned into idv/instv)
  43.         for k, v in ipairs(def)                                         --iterating the defaults of a given class.
  44.             fstr = "get" .. capitalize(k)                               --Format getter name.
  45.             instance[fstr] = function() return dat[id][k] or v end --set instance.getVar to return the data[id][var] or defaults.idv[className][var].
  46.             --def[k] CAN be a func which computes the value based on instance and id.
  47.     4- Similar to the above, except the vars are:
  48.         - Applied directly to instance, instead of being wrapped in getters:
  49.             (iterating over h ; className)                             
  50.             className = h[i]                                            --iterate all defaults of the given hierarchy.
  51.             def = Reg.defaults.instv[className]                         --fetch all default instvs of className (current iteration).
  52.             dat = Reg.data                                              --access ALL registry data. (not sectioned into idv/instv)
  53.             for k, v in ipairs(def)                                     --iterating the defaults of a given class.                 
  54.                 instance[k] = dat[id][k] or v                               --set instance[var] to data[id][var] or defaults.intsv[className][var]
  55.    
  56.    
  57.    
  58. In-place functions:
  59.     t.__f is used for default-fallbacks: is called with f(instance, id, t, k, v)
  60.         - If present for t.__f[k], is indented into getVar() as the default-fallback.
  61.         - Else, the native-default is indented directly.
  62.          
  63.     t.__d is used for data-computation: is called with f(instance, id, t, k, v, datum)
  64.         - If present for t.__d[k], is called with the native-default and datum,
  65.                 It's return value is applied into the instance.
  66.         - Else, the datum is applied directly, else, the native-default is applied.
  67.    
  68.     General:
  69.         1- Take priority over a native-default.                
  70.         2- Are passed the var (k) and native-default (v), if any.
  71.         3- [__d only] Are passed the value from the datapack (datum), if any.
  72.    
  73.         Terminology:
  74.             r.t = Registry.defaults.i__v.className
  75.            
  76.             instance = the instance being instantiated
  77.             t = r.t                                 --aka the class's defaults.i__x
  78.             k = var                                 --aka what is indexed with in r.t[k]
  79.             v = r.t[k]                              --aka the value of var.
  80.             native-default   = r.t[k]               --aka v
  81.             default-fallback = r.t.__f[k]          
  82.             default-compute  = r.t.__f[k]
  83.             datum            = r.data.t[k]          --aka the datapack value of var.
  84.    
  85. Templates:
  86.     Used for:
  87.         1- Data-driven object creation / during runtime.
  88.             template = class
  89.         2- Data-driven template creation (combining) during runtime.
  90.             template = {class, interface0, interface1, ...}
  91.  
  92.     Registry:create(id, args)
  93.         1- Uses the id to fetch a template.
  94.         2- Fetches the [base] class from template.
  95.             If any mixins are present, includes them into the class, in order.
  96.         3- return combinedClass(args)       --calling the constructor of the [base] class.
  97.         4-
  98.             TODO: Figure out how to pass args/initial-values to the given mixins, if any.  
  99.  
  100. --]=]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top