2
0

MyScript.st 840 B

1234567891011121314151617181920212223242526272829
  1. Object subclass: #MyScript
  2. instanceVariableNames: ''
  3. package: '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 method |
  10. console log: 'Creating new class #Dummy'.
  11. Object subclass: #Dummy instanceVariableNames: '' package: 'Dummy'.
  12. klass := Smalltalk current at: #Dummy.
  13. console log: 'Add method #foo to class #Dummy'.
  14. klass compile: 'foo ^10' category: 'foo'.
  15. console log: 'Add method #bar to class #Dummy'.
  16. klass compile: 'bar ^ self foo * 2' category: 'foo'.
  17. console log: '--- Exported JavaScript for class #Dummy ---'.
  18. console log: (Exporter new exportPackage: 'Dummy').
  19. console log: '--- Exported JavaScript for class #Dummy End---'.
  20. ! !