LoginLogin
Might make SBS readonly: thread

[_] Lowerdash "Resources" Command

Root / Talk About Programs / [.]

kldck_hulCreated:
Hey yall! I'm thinking about adding a concept for library builders into Lowerdash - "Resources" I wanted to see if users/the community found this understandable: Resources would let you declare a Module a provider for a type of Resource with certain properties. You could then declare a different Module a consumer of that Resource - Adding references to a new Resource instance's properties on each new instance of the consumer. Example:
Module PhysManager
RES Body: { 
    X: 0, Y: 0, W: 16, H: 16, VX: 0, VY: 0, M: 100, P: 1, V: 100
  }, Ray: {
    NOT$:"USED"
  }

...

Module PhysBody
REF PhysManager Body

...

VAR E$ = new("PhysBody")
PhysManager_update
?_(E$,"X");",";_(E$,"Y")
After compiling this code: PhysManager has generated methods addBody and delBody These methods operate on a generated ID, in this case BodyID. PhysManager has generated VARs X[], Y[]... for direct access to every Resource instance it manages without any lookup cost Every instance of the PhysBody module has generated getters and setters for every property on the Body Resource A MEM BodyId is set using addBody on the PhysBody instance in its constructor. Whew Lad! Now, is this feature understandable? What keywords are best for this functionality? REF and RES are pretty common... and similar... How do I avoid making this look like JSON and objects? EDIT: Fixed the example. I just realized, I might want to do the linking backwards so that the property declaration is on the REF. Does the provider even have to know its being monkey patched? Well except that it needs to know about all the variables... EDIT2: USE CASE: I'm using this right now for Physics entities - to do the whole update in one DEF block - and want to use it for Events on Actors - again to do event bubbling in one block.

So for anyone who might've been interested in this: I've overhauled the way this is done. You declare a RES on the parent module, and it will generate the matching module that would have REF'd that RESOURCE. You can use this module as a prototype to both do things on construction and add side-effects to accessors. This works amazingly well for creating Entity Component Systems Example:
MODULE TestManager
  RES test { value1, value2 }

  STATIC DEF doAThing(managementID%)
    ?me("value1")[managementID%]
  END
END

MODULE MyThing PROTO testResource
  EXPORT DEF new()
    me("value1") = 2*me("value2")
  END

  EXPORT DEF _getValue2()
    RETURN 42
  END
END