Posted to tcl by hypnotoad at Tue Jan 08 15:26:54 GMT 2019view raw

  1. ###
  2. # Build on a class that has been created in C
  3. #
  4. # C defines the following:
  5. # Configure_Dump - Return a dict of the current state
  6. # Configure_Get - Return a single value from the current state
  7. # Configure_Set - Set a new value for the current state
  8. # Configure_Delta - Return a list of all of the values that have a script
  9. # binding and were modified since the last call to Configure_Delta
  10. ###
  11. oo::define oo::class {
  12. method configure args {
  13. if {[llength $args]==0} {
  14. tailcall my Configure_Dump
  15. }
  16. if {[llength $args]==1} {
  17. tailcall my Configure_Get [lindex $args 0]
  18. }
  19. foreach {key value} $args {
  20. my Configure_Set $key $value
  21. }
  22. foreach {key value script} [my Configure_Delta] {
  23. eval [string map [list %field% $field %value% $value %self% [self]] $script]
  24. }
  25. }
  26.  
  27. method cget field {
  28. tailcall my Configure_Get $field
  29. }
  30. }