2
0

MyScript.st 744 B

123456789101112131415161718192021222324252627
  1. Object subclass: #MyScript
  2. instanceVariableNames: ''
  3. category: 'MyScript'!
  4. !MyScript class methodsFor: 'main'!
  5. main
  6. "Just a trivial example showing some meta programming by
  7. creating a class, compiling some methods and then exporting
  8. this package in javascript format to stdout"
  9. | klass compiler method |
  10. Object subclass: #Dummy instanceVariableNames: '' package: 'Dummy'.
  11. klass := Smalltalk current at: #Dummy.
  12. compiler := Compiler new.
  13. method := compiler load: 'foo ^10' forClass: klass.
  14. method category: 'foo'.
  15. klass addCompiledMethod: method.
  16. method := compiler load: 'bar ^ self foo * 2' forClass: klass.
  17. method category: 'foo'.
  18. klass addCompiledMethod: method.
  19. console log: (Exporter new exportPackage: 'Dummy')
  20. ! !