1. ver 4.0 Name Space Question ?

If I have a bunch of public constants in a Library
and I include that library in a second library.

Is there a way to make the constants visible from the second
library without making the first libraries constants global ?

new topic     » topic index » view message » categorize

2. Re: ver 4.0 Name Space Question ?

bernie said...

If I have a bunch of public constants in a Library
and I include that library in a second library.

Is there a way to make the constants visible from the second
library without making the first libraries constants global ?

If I understand you correctly, you have this ...

-- LIBA.e -- 
public integer foo 

and this ...

-- LIBB.e -- 
include LIBA.e 

and you want things that include LIBB.e to be able to see foo.

If that is the case then write LIBB.e like this ...

-- LIBB.e -- 
public include LIBA.e 

Note that we public include a file that contains public symbols so that those symbols are made 'as if' they were public in the file that has the include.

public symbols are normally exposed for one level of include, but a public include exposes included public symbols up one more extra level.

By doing this, files that include LIBB.e will also be able to see public symbols declared in LIBA.e.

new topic     » goto parent     » topic index » view message » categorize

3. Re: ver 4.0 Name Space Question ?

-- LIBA.e -- 
public constant 
foo1 = 1, 
foo2 = 2 
 
public function foobarr1() 
return 0 
end function 
 
public function foobarr2() 
return 0 
end function 
 

and this ...

-- LIBB.e -- 
-- No I want to pass on just the constants not 
-- the public functions from LIBA.e. 
   
new topic     » goto parent     » topic index » view message » categorize

4. Re: ver 4.0 Name Space Question ?

bernie said...
-- LIBA.e -- 
public constant 
foo1 = 1, 
foo2 = 2 
 
public function foobarr1() 
return 0 
end function 
 
public function foobarr2() 
return 0 
end function 
 

and this ...

-- LIBB.e -- 
-- No I want to pass on just the constants not 
-- the public functions from LIBA.e. 
   

Ok. Code like this then ...

-- LIBA.e -- 
public constant 
foo1 = 1, 
foo2 = 2 
 
export function foobarr1() 
return 0 
end function 
 
export function foobarr2() 
return 0 
end function 
 

and this ...

-- LIBB.e -- 
-- I want to pass on just the constants not 
-- the functions from LIBA.e.   
public include LIBA.e 

The export scope modifier is used for this purpose. It works just like public except that these symbols are only ever passed up one level only. In other words, if a file wants to use an export symbol, that file must include it explicitly.

You still do a public include to expose the public symbols but any exported symbols are not seen by files that include LIBB.e

new topic     » goto parent     » topic index » view message » categorize

5. Re: ver 4.0 Name Space Question ?

DerekParnell said...
bernie said...
-- LIBA.e -- 
public constant 
foo1 = 1, 
foo2 = 2 
 
public function foobarr1() 
return 0 
end function 
 
public function foobarr2() 
return 0 
end function 
 

and this ...

-- LIBB.e -- 
-- No I want to pass on just the constants not 
-- the public functions from LIBA.e. 
   

Ok. Code like this then ...

-- LIBA.e -- 
public constant 
foo1 = 1, 
foo2 = 2 
 
export function foobarr1() 
return 0 
end function 
 
export function foobarr2() 
return 0 
end function 
 

and this ...

-- LIBB.e -- 
-- I want to pass on just the constants not 
-- the functions from LIBA.e.   
public include LIBA.e 

The export scope modifier is used for this purpose. It works just like public except that these symbols are only ever passed up one level only. In other words, if a file wants to use an export symbol, that file must include it explicitly.

You still do a public include to expose the public symbols but any exported symbols are not seen by files that include LIBB.e

Thanks Derek !

Now I understand the difference between export and public.

Who is ever in charge of that Developers group had better
give you a raise for being so good at explaining.

new topic     » goto parent     » topic index » view message » categorize

6. Re: ver 4.0 Name Space Question ?

bernie said...

Thanks Derek !

Now I understand the difference between export and public.

Who is ever in charge of that Developers group had better
give you a raise for being so good at explaining.

I'll speak on behalf of the dev team, as I'm sure they will all agree... As of today, we have doubled Derek's pay.

Jeremy

new topic     » goto parent     » topic index » view message » categorize

7. Re: ver 4.0 Name Space Question ?

bernie said...
DerekParnell said...
bernie said...
-- LIBA.e -- 
public constant 
foo1 = 1, 
foo2 = 2 
 
public function foobarr1() 
return 0 
end function 
 
public function foobarr2() 
return 0 
end function 
 

and this ...

-- LIBB.e -- 
-- No I want to pass on just the constants not 
-- the public functions from LIBA.e. 
   

Ok. Code like this then ...

-- LIBA.e -- 
public constant 
foo1 = 1, 
foo2 = 2 
 
export function foobarr1() 
return 0 
end function 
 
export function foobarr2() 
return 0 
end function 
 

and this ...

-- LIBB.e -- 
-- I want to pass on just the constants not 
-- the functions from LIBA.e.   
public include LIBA.e 

The export scope modifier is used for this purpose. It works just like public except that these symbols are only ever passed up one level only. In other words, if a file wants to use an export symbol, that file must include it explicitly.

You still do a public include to expose the public symbols but any exported symbols are not seen by files that include LIBB.e

Thanks Derek !

Now I understand the difference between export and public.

Who is ever in charge of that Developers group had better
give you a raise for being so good at explaining.

Derek's explanation should be IN the EU4 docs!

And in relation to those docs, about include,

What does "N.B." MEAN?

And since, after "An identifier marked as public or export...", an explanation for public is given, there needs to be an explantion for export also, either just before or just after the explanation for public.

Dan

new topic     » goto parent     » topic index » view message » categorize

8. Re: ver 4.0 Name Space Question ?

http://openeuphoria.org/docs/eu400_0012.html#_102_scope

It could be made easier to understand.

Jeremy

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu