slang-users mailing list

[2005 Date Index] [2005 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: [slang-users] Bug in namespace allocation


Jörg Sommer <joerg@xxxxxxxxxxxx> wrote:
>But this leads to very strange errors:

I would not call this behavior "strange" nor an "error".  It works as
it is documented to work.  What you seem to be looking for is a way to
autoload a public function from a file evaluated in a specified
namespace.  Currently there exists no simple mechanism to perform such
a task.  However, it is rather easy to create a function that achieves
this result.  Let's call it "autoload_public".  Then in test.sl
replace

   autoload("foo", "/tmp/test1.sl");

with

   autoload_public ("foo", "/tmp/test1.sl", "_test");

This statement says to autoload "foo" from "/tmp/test.sl" evaluated in
the "_test" namespace.

Here is an implementation of such a function:

   define autoload_public (fun, file, ns)
   {
      if (is_defined (fun))
	return;

      eval ("public define $fun();"$
	    + "public define $fun(){"$
	    + "variable args=__pop_args(_NARGS);"
	    + "()=evalfile(\"$file\",\"$ns\");"$
	    + "return $fun(__push_args(args));}"$);
   }

--John


[2005 date index] [2005 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]