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