mirror of
https://github.com/gnustep/libs-steptalk.git
synced 2025-02-23 11:31:01 +00:00
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/steptalk/trunk@21701 72102866-910b-0410-8b05-ffd578937521
48 lines
No EOL
1.4 KiB
Smalltalk
48 lines
No EOL
1.4 KiB
Smalltalk
| actor engine source method |
|
|
|
|
actor := STActor actorInEnvironment:Environment.
|
|
"Set ivars"
|
|
|
|
ivars := NSMutableDictionary dictionary.
|
|
ivars setObject:1 forKey:'number'.
|
|
actor setInstanceVariables:ivars.
|
|
|
|
" Get the proper engine "
|
|
engine := STEngine engineForLanguage:'Smalltalk'.
|
|
|
|
" This is the source of new method "
|
|
source := 'increment
|
|
number := number + 1. ^self'.
|
|
|
|
" Create method "
|
|
method := engine methodFromSource:source
|
|
forReceiver:actor
|
|
inContext:Environment.
|
|
|
|
" Add the method to the actor "
|
|
actor addMethod:method.
|
|
|
|
" Add another method with an argument "
|
|
source := 'setNumber:i number := i. ^self'.
|
|
method := engine methodFromSource:source
|
|
forReceiver:actor
|
|
inContext:Environment.
|
|
actor addMethod:method.
|
|
|
|
source := 'print
|
|
Transcript showLine: (\'The number is \',
|
|
(number description)). ^self'.
|
|
method := engine methodFromSource:source
|
|
forReceiver:actor
|
|
inContext:Environment.
|
|
actor addMethod:method.
|
|
|
|
" Send it! "
|
|
actor print.
|
|
actor increment.
|
|
actor print.
|
|
actor increment.
|
|
actor print.
|
|
actor setNumber:10.
|
|
actor print.
|
|
|