I've been looking at the Odin language for a while, and figured it was time to give it a try. It's not talked about very much, though it looks like it aims to be an improvement on C. I saw Ginger Bill's discussion with TJ and Primeagen a while ago, and he talked clearly and directly about his opinions and its aims for simplicity.
I have no idea what I'm getting into here. The syntax looks sort of similar to that of Jonathan Blow's Jai language that I've seen in his videos.
Download
After downloading it from Github, it looks self-contained.
It looks like the vendor/ folder comes with a bunch of prebundled third-party libraries for things I could use to build games: Box2D, Lua, Vulkan, GLFW, and so on. I've never seen this before, that's unexpected, but looks very nice if it works.
Simple Programs
After adding the odin directory to $PATH, copying and running the "Hellope!" program builds and runs as advertised. There's no boiler plate, no .toml file or anything in the directory to build and run the program.
package main
import"core:fmt"
main ::proc() {
fmt.println("Hello, World!")
}
Semicolons appear optional.
The operators seem familiar to C and C++ with a few new ones:
%% remainder (floored) integers
&~ bitwise and-not integers, enums
%%= remainder (floored) and assign a %%= b is a = a %% b
&~= bitwise and-not and assign a &~= b is a = a &~ b
GLFW setup
Do the libraries in that vendor/ folder work, or are they just for show?
I don't know how to import a library, but fmt is import core:fmt so maybe I can import glfw from that folder with vendor/glfw? It seems to work. Looking at the vendor code, it looks like you can use an import by providing the name before the path.
import glfw "bindings"
I'm looking for glfwInit, looks like the wrapper chops off the front:
Can it create a window though? What happens when I try to port the GLFW example directly to Odin?
Looks like main doesn't return a value, just like Ada entry procedures, and requires a separate function to do so, os.exit().
Trying to create and then initialize a window says there's a redeclaration. Perhaps := isn't just assignment, but also declares like in Go?
window :: glfw.WindowHandle;
window := glfw.CreateWindow(640, 480, "Hello World", nil, nil)
PS D:\dev\odin\03_glfw_window> odin run .
D:/dev/odin/03_glfw_window/empty_glfw_window.odin(15:2) Error: Redeclaration of 'window' in this scope
at D:/dev/odin/03_glfw_window/empty_glfw_window.odin(14:2)
window := glfw.CreateWindow(640, 480, "Hello World", nil, nil)
Ok, so there's also no while loop, only for.
It doesn't work as-is. I look through the OpenGL vendor directory in odin and find a mention about loading OpenGL function pointers. Once I add the appropriate call in gl.load_up_to(4, 5, glfw.gl_set_proc_address), it works: