Main procedures in Odin can't return a value ? #3097
-
Hi, I only do some coding here and there and I'm new to the Odin language so forgive my ignorance. Can main procedures Odin programs not return a value? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Are you looking for If you want to emulate something like package main
import "core:os"
import "core:fmt"
main :: proc() {
// your "real" `main`
err := run()
exit_code := 0
exit_message: Maybe(string)
// map error values to status codes & messages
switch err {
case .None:
// OK
case .Oops:
exit_code = 1
exit_message = "Oops..."
}
if message, ok := exit_message.?; ok {
fmt.eprintln("Error:", exit_message)
}
os.exit(exit_code)
}
Error :: enum {
None,
Oops,
// add more
}
run :: proc() -> (err: Error) {
// (app code here)
return .Oops
} |
Beta Was this translation helpful? Give feedback.
Are you looking for
os.exit()
?If you want to emulate something like
int main()
from C, for example, you can define another proc likerun
which does return a value. Then all yourmain
does is call that function, and handle any error it returned accordingly - usingos.exit()
to abort with an exit code, or whatever you would like your specific application to do.