Hi, Dr. Geo script are becoming first class citizen -- before it was just a method hooked to an existing DrGeoUserScripts class ; then, it was easy to export the script method as a string to include it in the XML sketch file. Now to save a Dr. Geo sketch using a script, the whole script class needs to be embedded in the sketch XML representation. Is it possible to export a whole class as a string, then import it back from a string representation to a class? Thanks Hilaire -- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
Le 12 nov. 2014 08:32, "Hilaire" <hilaire@drgeo.eu> a écrit :
Hi,
Dr. Geo script are becoming first class citizen -- before it was just a method hooked to an existing DrGeoUserScripts class ; then, it was easy to export the script method as a string to include it in the XML sketch file.
Now to save a Dr. Geo sketch using a script, the whole script class needs to be embedded in the sketch XML representation.
Is it possible to export a whole class as a string, then import it back from a string representation to a class?
Isn't that a fileOut/fileIn thing? Phil
Thanks
Hilaire -- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
Le 12/11/2014 09:08, phil@highoctane.be a écrit :
Is it possible to export a whole class as a string, then import it back from a string representation to a class?
Isn't that a fileOut/fileIn thing?
Yes, however I don't want it on a .st file (to avoid possible trouble on the end user DrGeo installation) but on a string within Smalltalk. Hilaire -- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
String streamContents: [ :out | Association fileOutOn: out ] I am not sure it covers everything, but for some script methods this will do.
On 12 Nov 2014, at 09:21, Hilaire <hilaire@drgeo.eu> wrote:
Le 12/11/2014 09:08, phil@highoctane.be a écrit :
Is it possible to export a whole class as a string, then import it back from a string representation to a class?
Isn't that a fileOut/fileIn thing?
Yes, however I don't want it on a .st file (to avoid possible trouble on the end user DrGeo installation) but on a string within Smalltalk.
Hilaire
-- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
Thanks, interesting hack I need to learn from. Filout works well as long as only ascii appear in the body of the method. When a method contains non ascii (for example for a string) fileout get irrational with a ZNInvalidUTF8, but not always! For example, a script method as: scriptName ^ 'téte' does not lead to the error, but as following: scriptName ^ 'tété' leads to the error. Note the scriptName method works from Pharo To build the script I use the following code. createScriptFrom: dialog "Build a new script from the dialog, return the newly created script object" |scriptClass stream| scriptClass := DrGeoUserScript subclass: ('DrGeoScript', dialog scriptName hash printString) asSymbol instanceVariableNames: '' classVariableNames: '' category: 'DrGeoII-User'. "name" stream := WriteStream on: String new. stream << 'scriptName'; << Character cr; << Character tab; << $^; <<$'; << dialog scriptName; << $'. scriptClass compile: stream contents classified: 'public'. Later I test directly from the browser with a dummy class with one method with non ascii character. Fileout sometimes work (for example, I add a space in the method body, save, remove the space, save again,...), some time not. tested on Pharo 3.0 Hilaire Le 12/11/2014 09:33, Sven Van Caekenberghe a écrit :
String streamContents: [ :out | Association fileOutOn: out ]
I am not sure it covers everything, but for some script methods this will do.
-- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
Le 12/11/2014 10:22, Hilaire a écrit :
Later I test directly from the browser with a dummy class with one method with non ascii character. Fileout sometimes work (for example, I add a space in the method body, save, remove the space, save again,...), some time not.
tested on Pharo 3.0
Reported here https://pharo.fogbugz.com/f/cases/14462/ZNInvalidUTF8-when-fileout-method-bo... -- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
On Wed, Nov 12, 2014 at 9:21 AM, Hilaire <hilaire@drgeo.eu> wrote:
Le 12/11/2014 09:08, phil@highoctane.be a écrit :
Is it possible to export a whole class as a string, then import it back from a string representation to a class?
Isn't that a fileOut/fileIn thing?
Yes, however I don't want it on a .st file (to avoid possible trouble on the end user DrGeo installation) but on a string within Smalltalk.
Why not use FileSystem memory for those things? This would keep the files inside the image. Phil
Hilaire
-- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
and if you want a json like implementation there is filetree. I think json is a much better format than XML but I am nowhere near to an experienced web developer. On Wed, Nov 12, 2014 at 11:15 AM, phil@highoctane.be <phil@highoctane.be> wrote:
On Wed, Nov 12, 2014 at 9:21 AM, Hilaire <hilaire@drgeo.eu> wrote:
Le 12/11/2014 09:08, phil@highoctane.be a écrit :
Is it possible to export a whole class as a string, then import it back from a string representation to a class?
Isn't that a fileOut/fileIn thing?
Yes, however I don't want it on a .st file (to avoid possible trouble on the end user DrGeo installation) but on a string within Smalltalk.
Why not use FileSystem memory for those things? This would keep the files inside the image.
Phil
Hilaire
-- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
Le 12/11/2014 10:15, phil@highoctane.be a écrit :
Why not use FileSystem memory for those things? This would keep the files inside the image.
because I didn't know about it :) But fileout(UTF8 conversion, again...) seems to be broken, see my other post. Hilaire -- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu
participants (4)
-
Hilaire -
kilon alios -
phil@highoctane.be -
Sven Van Caekenberghe