terralang / terra

Terra is a low-level system programming language that is embedded in and meta-programmed by the Lua programming language.
terralang.org
Other
2.68k stars 196 forks source link

What's the syntax for declaring methods without defining them? #338

Open capr opened 5 years ago

capr commented 5 years ago

The doc says:

Alternatively, you can declare a function before defining it:

terra isodd :: uint32 -> bool

What's the syntax for methods?

I tried:

terra T.method :: &T -> {}
terra T:method :: {} -> {}

but none seem to work, and the error is:

C:\projects\terra\src\asdl.lua:31: bad argument #1 to 'ipairs' (table expected, got nil)
stack traceback:
    [C]: in function 'ipairs'
    C:\projects\terra\src\asdl.lua:31: in function 'insertall'
    C:\projects\terra\src\terralib.lua:1013: in function 'desugarmethoddefinition'
    C:\projects\terra\src\terralib.lua:1083: in function 'defineobjects'


Thanks!
elliottslaughter commented 5 years ago

Probably just an oversight, the syntax you show is what I'd expect it to be if it were supported.

capr commented 5 years ago

FYI terra T.methods.method :: {&T} -> {} works.