Scoped Imports, FFI-as
More QoL changes:
import
s can now either beprivate
(the default), orpublic
. Private imports are the old behaviour (I think -- I can't remember if we successfully removed re-exporting previously), where whatever the module imports is not transitively exported to other modules that import it. The reverse is true of public imports.
Given the following:
export foo
public fn foo() { }
// ...
export bar
public import "foo"
// ...
export baz
private import "foo" // you'll actually get a warning that it's redundant
fn main()
{
// foo::foo is visible from bar, as bar::foo::foo()
bar::foo::foo()
// foo is not visible from baz!
// baz::foo::foo()
}
- Declare foreign functions (
ffi
)as
something -- these alias names participate in overloading (and the 'real' names are no longer visible). Particularly useful for a certain someone:
export gl
public ffi fn glVertex2i(x: int, y: int) as vertex
public ffi fn glVertex2f(x: float, y: float) as vertex
public ffi fn glVertex2d(x: double, y: double) as vertex
public ffi fn glVertex3i(x: int, y: int, z: int) as vertex
public ffi fn glVertex3f(x: float, y: float, z: float) as vertex
public ffi fn glVertex3d(x: double, y: double, z: double) as vertex
// ...
import "gl"
gl::vertex(1, 1) // calls glVertex2i
gl::vertex(1.0, 1.0, 0.5) // calls glVertex3d