nXIII wrote:
Okay, I think what I did is basically a whole bunch of compiling: (ugh, this took me FOREVER to make for Panther 1.0)
customBlockCode
| oCode temps assignments code i isComment isQuote |
oCode _ customBlockOrigin blockContents: customBlockName.
code _ ''.
isComment _ false.
isQuote _ false.
oCode do: [:let |
let = $' ifTrue: [
isComment ifFalse: [ isQuote _ isQuote not.
code _ code, let asString]]
ifFalse: [
isQuote ifTrue: [
code _ code, let asString]
ifFalse: [
let = $" ifTrue: [
isComment _ isComment not]
ifFalse: [
isComment ifFalse: [code _ code, let asString]]]]].
temps _ ''.
i _ 1.
[i <= self argumentCount] whileTrue: [
temps _ temps, (' t', i asString).
i _ i + 1.].
code lines size = 0 ifTrue: [^ ''].
[code lines first isEmpty] whileTrue: [code _ code copyFrom: 2 to: (code size)].
((code lines first asString findString: '|') > 0) ifTrue: [
code _ (code copyFrom: 1 to: (code lines first asString findString: '|')), temps, (code copyFrom: ((code lines first asString findString: '|') + 1) to: (code size))] ifFalse: [
code _ '|', temps, ' |
', code].
assignments _ ''.
i _ 1.
[i <= self argumentCount] whileTrue: [
([((self args at: i) size = 0)] ifError: [false]) ifTrue: [assignments _ assignments, (('t', i asString), ' _ '), '''''.
']
ifFalse: [
((self args at: i) isKindOf: String) ifTrue: [
assignments _ assignments, ((('t', i asString), ' _ '''), (self args at: i) asString), '''.
']
ifFalse: [
assignments _ assignments, ((('t', i asString), ' _ '), (self args at: i) asString), '.
']].
i _ i + 1.].
((code lines first asString findString: '|') > 0) ifTrue: [
code _ (code copyFrom: 1 to: (code findString: '|' startingAt: ((code findString: '|') + 1))), '
', assignments, (code copyFrom: ((code findString: '|' startingAt: ((code findString: '|') + 1)) + 1) to: (code size))].
[(code findString: '
') > 0] whileTrue: [code _ code copyReplaceAll: '
' with: '
'].
^ code.And then ran it:
isCustom ifTrue: [Compiler evaluate: self customBlockCode for: receiver logged: false].
Oh, and I found it very helpful to add the "view code" item to the debug menu of the command block.
um, nxlll, I hat to break this to you, but all that compiling wasn't nescesary. all you really had to do was add the code to set the t1, t2, etc. to the arguments and make sure that it reports the code asUTF8. And this way, the code you use in the block editor isn't at all diferent from real Squeak.
Offline
LS97 wrote:
great it works!
now all the block making/deleting is perfect.
i just have a tiny problem![]()
well, a bit bigger.
so, where's the code that actually runs all of those blocks? because i want it so that when i run a block it executes the code directly and not a method with that name.
i think it's somewhere in CommandBlockMorph evaluation, but how exactly can i do that?
Compiler evaluate: (code) for: receiver logged: false
Here ya go.
Offline
johnnydean1 wrote:
Havent you made a run squeak block. Just use that
Well, I have. Its here:
and its the block that says 'Code'. Its colapsable too.
Offline
rubiks_cube_guy238 wrote:
um, nxlll, I hat to break this to you, but all that compiling wasn't nescesary. all you really had to do was add the code to set the t1, t2, etc. to the arguments and make sure that it reports the code asUTF8. And this way, the code you use in the block editor isn't at all diferent from real Squeak.
No... this is the code to set the variables t1, t2, and declare them, and take out unnecessary code to speed up compiling.
And BTW, you apparently missed this:
I wrote:
And then ran it:
isCustom ifTrue: [Compiler evaluate: self customBlockCode for: receiver logged: false].
rubiks_cube_guy238 wrote:
LS97 wrote:
great it works!
now all the block making/deleting is perfect.
i just have a tiny problem :P
well, a bit bigger.
so, where's the code that actually runs all of those blocks? because i want it so that when i run a block it executes the code directly and not a method with that name.
i think it's somewhere in CommandBlockMorph evaluation, but how exactly can i do that?Code:
Compiler evaluate: (code) for: receiver logged: falseHere ya go. :)
That is not what he meant...
he meant "what actually evaluates the block" not "what is the Compiler message to run a piece of code"
And please don't triple-post. Thanks :)
Last edited by nXIII (2010-08-15 20:22:39)
Offline
nXIII wrote:
rubiks_cube_guy238 wrote:
um, nxlll, I hat to break this to you, but all that compiling wasn't nescesary. all you really had to do was add the code to set the t1, t2, etc. to the arguments and make sure that it reports the code asUTF8. And this way, the code you use in the block editor isn't at all diferent from real Squeak.
No... this is the code to set the variables t1, t2, and declare them, and take out unnecessary code to speed up compiling.
And BTW, you apparently missed this:I wrote:
And then ran it:
isCustom ifTrue: [Compiler evaluate: self customBlockCode for: receiver logged: false].
rubiks_cube_guy238 wrote:
LS97 wrote:
great it works!
now all the block making/deleting is perfect.
i just have a tiny problem![]()
well, a bit bigger.
so, where's the code that actually runs all of those blocks? because i want it so that when i run a block it executes the code directly and not a method with that name.
i think it's somewhere in CommandBlockMorph evaluation, but how exactly can i do that?Code:
Compiler evaluate: (code) for: receiver logged: falseHere ya go.
![]()
That is not what he meant...
he meant "what actually evaluates the block" not "what is the Compiler message to run a piece of code"
And please don't triple-post. Thanks![]()
Sorry about the tripple posting. im to lazy to reduce it to 1 post
.
And anyways, what LS97 wanted to see is probably CommandBlockMorph evaluateWithArgs:
Or you could try to take a look at the ScratchProcess (located in 'Scratch-Execution Engine')
Offline
ok great htnaks
Offline