On Tue, Feb 12, 2013 at 6:06 PM, Mark Miesfeld <miesfeld@gmail.com> wrote:
On Tue, Feb 12, 2013 at 2:51 PM, Staffan Tylen <staffan.tylen@gmail.com> wrote:
I'm fiddling with the .Package class and have found that if I create a new package from an array of rexx code, the new package is immediately executed by the init method. Is this the way it is supposed to work? Example:

a=.array~new
a~append("say 'hi this is me'")
a~append("say 'bye'")
p=.package~new("package1",a)


I haven't played with the .Package class much, but it says this in the doc:

The files loaded by ::REQUIRES are also contained in Package class instances.

So, I think that p = .Package~new()

is going to behave like:

::requires 'p.txt'

and if p.txt is

say 'hi this is me'
say 'bye'

Then when you require p.txt those 2 lines of code are going to run.  Which is what happens in your test.  Change your test to this

a=.array~new
a~append("::routine speak public")
a~append("say 'hi this is me'")
a~append("say 'bye'")
a~append("return 0")
p=.package~new("package1",a)
r = speak()

and try it.

Although I just did and it didn't work as I expected.  But, it is more like what I think should work.


Mark, speak() did not work because creating the package does not automatically add the package to the current context.  You'd need to add  

  .context~package~addPackage(p) 

to add it to the namespace. 

or you can pull the speak routine object from the package and call it. 

Rick

--
Mark Miesfeld


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Oorexx-users mailing list
Oorexx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-users