[REBOL] Re: Embedded Object and Scope yet again...
From: larry:ecotope at: 11-May-2001 13:31
Hi Joel
You raise a lot of interesting questions. I will respond in several short
posts. We were discussing using a quick object wrapper around script code:
REBOL []
ctx-wrapper [
........ all my code here
] end ctx-wrapper
> > ... There are some extra precautions when using vid which I will skip
> > here.
> >
>
> Do tell?!?! Precautions are A Good Thing!
>
OK, here are the extra precautions and the reason why. Consider the
following code:
ctw-wrap: context [
layo: layout [
rbb: box red
button "Change color" [rbb/color: random 255.255.255 show rbb]
]
view layo
]
After it runs, we find:
>> type? rbb
== object!
Even though LAYOUT creates a face object, all set-words used in the block
arg to LAYOUT are bound in the global context. This is not true for STYLIZE.
So we have to add place-holders for all set-words used in the layout
block(s) to the wrapper object, like so:
ctx-wrap: context [
; place-holders for all set-words in layout block(s)
rb: none
; normal object variables
a: [1 2 3]
double: func [x][x * 2]
layo: layout [
rb: box red
button "Change color" [rb/color: random 255.255.255 show rb]
]
; some code
view layo
]
After this runs, we get:
>> rb
** Script Error: rb has no value
** Near: rb
>>
More soon
-Larry