FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Symbols from imported module are non-accessible

 
Post new topic   Reply to topic     Forum Index -> MiniD
View previous topic :: View next topic  
Author Message
eldar



Joined: 14 Jun 2008
Posts: 101
Location: Ufa, Russia

PostPosted: Mon Sep 14, 2009 1:53 pm    Post subject: Symbols from imported module are non-accessible Reply with quote

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
View user's profile Send private message
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Mon Sep 14, 2009 8:49 pm    Post subject: Reply with quote

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
View user's profile Send private message
eldar



Joined: 14 Jun 2008
Posts: 101
Location: Ufa, Russia

PostPosted: Mon Sep 14, 2009 10:51 pm    Post subject: Reply with quote

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
View user's profile Send private message
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Tue Sep 15, 2009 12:09 am    Post subject: Reply with quote

Uh, again, you have to do "global b = b.B()". Then it'll output the right error.
Back to top
View user's profile Send private message
eldar



Joined: 14 Jun 2008
Posts: 101
Location: Ufa, Russia

PostPosted: Tue Sep 15, 2009 5:33 am    Post subject: Reply with quote

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
View user's profile Send private message
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Tue Sep 15, 2009 9:15 am    Post subject: Reply with quote

Is there a reason why you can't skip the class altogether and just modify the global string variable?
Back to top
View user's profile Send private message
eldar



Joined: 14 Jun 2008
Posts: 101
Location: Ufa, Russia

PostPosted: Tue Sep 15, 2009 9:34 am    Post subject: Reply with quote

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
View user's profile Send private message
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Tue Sep 15, 2009 2:08 pm    Post subject: Reply with quote

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
View user's profile Send private message
eldar



Joined: 14 Jun 2008
Posts: 101
Location: Ufa, Russia

PostPosted: Tue Sep 15, 2009 11:11 pm    Post subject: Reply with quote

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
View user's profile Send private message
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Wed Sep 16, 2009 7:39 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> MiniD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group