Reputation: 16598
Let's say I have a REBOL script in another file (imported.r
) that looks like this:
REBOL [ author: {Greg} title: {Awesome REBOL Code} ] x: 3
How can I import this file into another script and gain access to the contents of the REBOL header? I'm aware of load/header
but I can't seem to do anything with it.
imported: context load/header %imported.r
What do I do now to access the header of imported.r
as an object!
?
Upvotes: 2
Views: 317
Reputation: 136
LOAD/HEADER gives you a block of code, as you can see by PROBEing what it returns. It contains the unevaluated source for building a header object followed by the rest of the script.
To MAKE an OBJECT! from that header code, one way is to
>> set [header script] do/next load/header %imported.r
>> header/title
== "Some script title"
or, if you only need the header object, just
>> header: first do/next load/header %imported.r
>> header/title
== "Some script title"
This gives you object access via HEADER and the scripts code in the SCRIPT block, as DO/NEXT evaluates only the first expression and returns the result of the expression and the position in the code block after that evaluation.
Upvotes: 4