Well, it's a bit misleading to say that module variables are generally assumed to be constants at compile time. They are variables, but the '.' operator is evaluated at compile time, so anything indexed through it becomes a constant value.
Well, "int x" in a module is ok to use as a constant value,
-- test.pmod: int x=17; ... import test; constant bar=x;
is totally ok. So they *are* seen as constants.
No, it's enough to index the module with '->' instead.
Ah, interesting. I didn't know that.
/ Mirar
Previous text:
2004-02-02 22:11: Subject: Re: Pike module initialization at compile time
Well, it's a bit misleading to say that module variables are generally assumed to be constants at compile time. They are variables, but the '.' operator is evaluated at compile time, so anything indexed through it becomes a constant value.
As for imports, any identifier it adds are accessed as through a '.' operator, so they become constants too.
/.../ If you really want to do this (and have a global object), you need a query method to get the global object every time.
No, it's enough to index the module with '->' instead. Al's example with a module and a variable inside it with the same name makes it unnecessarily confusing, so I prove another example:
Foo.pmod:
int var = 17;
foo.pike:
import "."; int main () { werror ("%O\n", Foo.var); // writes 17 Foo->var = 42; werror ("%O\n", Foo.var); // still writes 17 werror ("%O\n", Foo->var); // writes 42 }
(I import '.' instead of '.Foo' to more clearly show the relation between '.' and '->'.)
/ Martin Stjernholm, Roxen IS