This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "core:fmt" | |
import "core:strings" | |
main :: proc() { | |
// Demo: Split `text` on any character in delimiter string. | |
{ | |
text := "\nThis is a long text\nwith line breaks."; | |
lines_itr := split_iterator(text, "\n"); | |
for line in split_any_next(&lines_itr) { | |
fmt.println(string(line)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package range_example | |
import "core:fmt" | |
main :: proc() { | |
fr := forward_range(0, 9); | |
for i in next_range(&fr) do fmt.printf("%v ", i); | |
fmt.printf("\n"); | |
// output: 0 1 2 3 4 5 6 7 8 9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ratelimit | |
import "core:fmt" | |
import "core:time" | |
ratelimit :: proc(limit: time.Duration, loc := #caller_location) -> (ok: bool) { | |
@static state: map[u64]time.Time; | |
start, end := state[loc.hash], time.now(); | |
ok = start._nsec == 0 || time.diff(start, end) > limit; | |
if ok do state[loc.hash] = end; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "core:fmt" | |
import "core:mem" | |
import "core:log" | |
Logging_Allocator_Data :: struct { | |
backing: mem.Allocator, | |
} | |
logging_allocator :: proc(data: ^Logging_Allocator_Data) -> mem.Allocator { | |
// `package log` uses context.temp_allocator and temp_allocator is lazily initialized. Dummy allocate here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "core:fmt" | |
import "core:mem" | |
import "core:log" | |
import "core:runtime" | |
// NOTE(Oskar): An example of how to do a leak checking allocator with Odin's context system. | |
// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"selector":"source.odin", | |
"file_regex": "^(.+)\\(([0-9]+):([0-9]+)\\) (.+)$", | |
"shell_cmd":"odin check \"$file_path\" -no-entry-point", | |
"variants":[ | |
// | |
// current file | |
// | |
// syntax check |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "core:fmt" | |
import "base:intrinsics" | |
main :: proc() { | |
X :: enum { A, B, C } | |
Y :: bit_set[X]; | |
values := Y{.A, .C}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample code showing how to create a modern OpenGL window and rendering | |
// context on Win32, using Odin. | |
// | |
// Ported from https://gist.github.com/nickrolfe/1127313ed1dbf80254b614a721b3ee9c | |
package main | |
import "core:sys/windows" | |
import "core:strings" | |
import "core:fmt" |