On Tue, Feb 28, 2017 at 11:28 AM, Offray Vladimir Luna Cárdenas < offray.luna@mutabit.com> wrote:
Hi,
I would like to store the object resulting from executing a playground. This would imply two steps:
- Knowing that the playground content was executed (via the play button or its shortcuts Ctrl + Shift + g or Ctrl + g). - Getting the results of that execution. For example if the result at the end is a string or a dictionary, I would like to get that string or dictionary.
Any pointers on how to make that will be welcomed.
Cheers,
Offray
Ps: I still get lost when I search by myself trying to answer questions like the ones above. I imagine that in some way is related with evaluationAction and presentations, by looking for the source code of "do it and go", but still I can't get a functional code snippet to start prototyping.
In playground, if you evaluate "self halt. 42" at top of the debug stack you'll see method... Undefined>>DoIt self halt. ^ 42 where stepping OVER returns 42 into "value" variable in OpalCompiler>>evaluate OVER returns 42 into "result" variable in RubSmalltalkEditor>>evaluate:andDo: at the end of which stepping INTO "^aBlock value: result" takes you to RubSmalltalkEditor>>highlightEvaluateAndDo:, where INTO "[:result | aBlock value: result]" takes you to GLMPharoScriptPResentation(GLMRubricSmalltalkCodePresentation)>>executionSelectionActions where changing "aPresentation highlightEvaluateAndDo: [ :result | ] ]; to "aPresentation highlightEvaluateAndDo: [ :result | self inform: 'Result ' , result printString] ]; " and opening a new Playground, then evaluating "42" informs us that 42 is the result. Stepping further along, in GLMMorphicPharoScriptRenderer(GLMMorphicPharoCodePresentation)>>highlightEvaluateAndDo:: the value returned from... self evaluate: self highlightedTextAsStream andDo: [:result | aBlock value: result. ]. is not 42 but aGLMPharoScriptPresentation. it might help to change that to... andDo: [:result | aBlock value: result. result ]. but anyway that return value is thrown away in GLMMorphicPharoScriptRenderer(GLMMorphicPharoCodePresentation)>>actOnHighlightAndEvaluate: So subclassing GLMRubricSmalltalkCodePresentation and overriding #executionSelectionActions is perhaps your best bet. Or some GLM expert provides a nice way for a user to set this customAssignmentBlock... aPresentation highlightEvaluateAndDo: [ :result | customAssignmentBlock value: result ]. in #executionSelectionActions. cheers -ben