#-> operator (selector call expressions) use in pure Odin

1 messages · Page 1 of 1 (latest)

austere spade
#

Is there a purpose in pure odin for the -> operator? I understand the documentation says its use is intended with vtables which I believe Odin doesn't have use for by design, but is there any use for it in pure Odin or only to make interfacing with like C++ libraries more convenient?

ex.

just a simple possibly naive test:

Foo :: struct{
    msg: string
}

show_foo::proc(foo: Foo){
    fmt.println(foo.msg)
}

main :: proc(){
    foo::Foo{msg="Hello"}
    foo->show_foo()
}

Error: 'foo' of type 'Foo' has no field 'show_foo'

Thanks!

summer dove
#
package foo

import "core:fmt"

Foo :: struct {
    print: proc(foo: ^Foo),
    bar: int,
}

make_foo :: proc(bar: int) -> (res: ^Foo) {
    res = new_clone(Foo{
        print = print_foo,
        bar   = bar,
    })
    return
}

print_foo :: proc(foo: ^Foo) {
    fmt.printf("%#v\n", foo)
}

main :: proc() {
    f := make_foo(42)
    f->print()
}
tidal spade
#

COM APIs are the main reason for their existence

hasty marsh
#

Objc too

summer dove
#

a->b() -> a.b(a)

austere spade
#

@summer dove Thanks! I had tried using a proc as a default on a struct and got an error about that. this makes sense though