View previous topic :: View next topic |
Author |
Message |
eldar
Joined: 14 Jun 2008 Posts: 101 Location: Ufa, Russia
|
Posted: Mon Sep 14, 2009 1:53 pm Post subject: Symbols from imported module are non-accessible |
|
|
Code: |
module b
function foo()
return "xyz"
//------------
module a
import b
global x = foo()
//------------
eldar@eldar-laptop:~/projects/dmake$ mdcl a.md
Error: <top-level>.<top-level>(5): Attempting to get nonexistent global 'foo'
|
Same thing happens with classes. It looks like some trivial bug or a trivial mistake that I make. Could you please help? |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Mon Sep 14, 2009 8:49 pm Post subject: |
|
|
Import name visibility doesn't work like in D but rather more like in Python. You must either fully-qualify the names of imported symbols (like "b.foo()") or selectively import them (like "import b: foo", same as in D). |
|
Back to top |
|
|
eldar
Joined: 14 Jun 2008 Posts: 101 Location: Ufa, Russia
|
Posted: Mon Sep 14, 2009 10:51 pm Post subject: |
|
|
Thank you!
Since I opened a topic, I have another issue:
Code: |
module b
class B
{
field = 0
this()
{
field = 5;
}
}
// --------------
module a
import b
global b = B()
|
mdcl a.md
gives
Error: a.<top-level>(5): Attempting to get nonexistent global 'B'
This is in module "a", but the error is in fact in module "b" on the line "field = 5", and should be
Error: <top-level>.constructor(9): Attempting to get nonexistent global 'field'
It is rather annoying that it doesn't output the actual issue. |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Tue Sep 15, 2009 12:09 am Post subject: |
|
|
Uh, again, you have to do "global b = b.B()". Then it'll output the right error. |
|
Back to top |
|
|
eldar
Joined: 14 Jun 2008 Posts: 101 Location: Ufa, Russia
|
Posted: Tue Sep 15, 2009 5:33 am Post subject: |
|
|
Sorry, and thank you!
I faced another issue. Basically I need to create a global reference to a string. Whenever I do ~= on the global, it should do ~= on the string. I can easily do that with class and overloaded its opCatAssign. But I can't overload opAssign and that's the problem. And there is no user defined value types.
For example:
Code: |
local name = "hello"
class RefName
{
function opCatAssign(vararg)
name = vararg[0]
// opAssign ??
}
global refName = RefName()
|
Is there anything I can do about it?
In D for instance it's possible to do:
Code: | import tango.io.Stdout;
int i;
class C
{
static void opAssign(int i)
{
.i = i;
}
}
void main()
{
C = 1;
Stdout(i).newline;
} |
|
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Tue Sep 15, 2009 9:15 am Post subject: |
|
|
Is there a reason why you can't skip the class altogether and just modify the global string variable? |
|
Back to top |
|
|
eldar
Joined: 14 Jun 2008 Posts: 101 Location: Ufa, Russia
|
Posted: Tue Sep 15, 2009 9:34 am Post subject: |
|
|
actually it is an array of objects and the global has to be an alias to the string field of the last element of the array:
Code: |
function appendToString(str: string)
arr[-1].strName ~= str
function setString(str: string)
arr[-1].strName = str
|
|
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Tue Sep 15, 2009 2:08 pm Post subject: |
|
|
Oh I see. Yeah, using functions like that is about the only way. Overloading assignment is an extremely tricky proposition without user-defined value types. |
|
Back to top |
|
|
eldar
Joined: 14 Jun 2008 Posts: 101 Location: Ufa, Russia
|
Posted: Tue Sep 15, 2009 11:11 pm Post subject: |
|
|
Basically what I'm doing is a build system like dsss, but it will use miniD for configuration files. And I am trying to give a nicer syntax in them. Yeah, user-defined value types would be just what's needed. |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Wed Sep 16, 2009 7:39 am Post subject: |
|
|
Depending on how you have things laid out, you could use tables for holding config data, like:
Code: | target$ "main",
{
flags = "-g -debug"
exclude = "std.*"
output = "main.exe"
} |
Or something. |
|
Back to top |
|
|
|