[slang-users] Bug in namespace allocation
John E. Davis
davis at space.mit.edu
Sat Oct 8 16:44:21 EDT 2005
Jörg Sommer <joerg at alea.gnuu.de> 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
More information about the slang-users-l
mailing list