importing and compiling squeak code
Alan Lovejoy
squeak-dev.sourcery at forum-mail.net
Mon Feb 7 07:01:00 UTC 2005
Also, here is the template for defining a class:
Superclass subclass: #YourClassName
instanceVariableNames: 'instVarAlpha instVarBeta'
classVariableNames: ''
poolDictionaries: ''
category: 'Dynamic Coding Examples'
And you can execute any arbitrary code stored in a string using the
following:
Compiler evaluate: aString
For example:
| string1 string2 string3 sum class |
string1 := '3 + 4'.
string2 :=
'Object subclass: #DynamicCodeExample
instanceVariableNames: ''value''
classVariableNames: ''''
poolDictionaries: ''''
category: ''Dynamic Coding Examples'''.
string3 := 'value
^value'.
sum := Compiler evaluate: string1.
class := Compiler evaluate: string2.
class compile: string3 classified: #accessing.
--Alan
-----Original Message-----
From: squeak-dev-bounces at lists.squeakfoundation.org
[mailto:squeak-dev-bounces at lists.squeakfoundation.org] On Behalf Of Alan
Lovejoy
Sent: Sunday, February 06, 2005 10:41 PM
To: 'The general-purpose Squeak developers list'
Subject: RE: importing and compiling squeak code
Brett:
To compile a method in a class, execute the following code:
YourClass compile: methodBodyString classified: #methodCategory
So, to add the method #foo to the class Object, under the method category
#bar, where the body of the #foo method prints 'Foo, world!' to the
Transcript, you would code the following:
Object
compile: 'foo
Transcript cr; show: ''Foo, world!'''
classified: #temporary
--Alan
-----Original Message-----
From: squeak-dev-bounces at lists.squeakfoundation.org
[mailto:squeak-dev-bounces at lists.squeakfoundation.org] On Behalf Of Hart's
Antler
Sent: Sunday, February 06, 2005 10:09 PM
To: squeak-dev at lists.squeakfoundation.org
Subject: importing and compiling squeak code
Hi, i am new to Squeak and smalltalk, i'm hoping somebody can help me get
started on this problem.
I want to store some squeak code in a file and execute the code after the
program is running,
binding all of the methods found in that file to a new object. I am
starting with something like
below:
bindMethods bindToObject compile: text
...something here to compile the text and return the methods?
...something here to bind those methods to bindToObject?
Thanks,
-brett
__________________________________
Do you Yahoo!?
Meet the all-new My Yahoo! - Try it today!
http://my.yahoo.com
More information about the Squeak-dev
mailing list
|