Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

operator overloads in types #583

Closed
nddrylliog opened this issue Feb 14, 2013 · 2 comments

Comments

@nddrylliog
Copy link
Member

commented Feb 14, 2013

ie. be able to write that:

MyArray: cover template <T> {
    length: Int
    data: T*

    init: func@ (=length) {
        data = gc_malloc(T size * length)
    }

    get: func (index: Int) -> T {
        _checkIndex(index)
        data[index]
    }

    set: func@ (index: Int, value: T) {
        _checkIndex(index)
        data[index] = value
    }

    _checkIndex: func (index: Int) {
        if (index < 0 || index >= length) {
            Exception new("Out of bounds array access: %d should be in %d..%d" \
                format(index, 0, length)) throw()
        }
    }

    operator [] (i: Int) -> T {
        get(i)
    }

    operator []= (i: Int, v: T) {
        set(i, v)
    }
}

It'll also fix weird things like: using a lib that returns a List, and then you try to index it with [] but it doesn't work because you don't import ArrayList/List yourself.

@alexnask

This comment has been minimized.

Copy link
Collaborator

commented Feb 14, 2013

Cough cough #33 cough cough

nddrylliog added a commit that referenced this issue Feb 14, 2013
@nddrylliog

This comment has been minimized.

Copy link
Member Author

commented Feb 14, 2013

Closed in 6ec80f5

@nddrylliog nddrylliog closed this Feb 14, 2013

nddrylliog added a commit that referenced this issue Feb 14, 2013
Make all other operators work in-class. cf. #583 (or #33 for that mat…
…ter). Still no inheritance.. will see about that laterz.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.