v / examples / sokol / 06_obj_viewer / modules / obj / util.v
24 lines · 21 sloc · 564 bytes · cfa91d81d71c0c60b29a7b6704b2f6d3b1d069c3
Raw
1module obj
2
3import os
4import os.asset
5
6// read a file as single lines
7pub fn read_lines_from_file(file_path string) []string {
8 if os.exists(file_path) {
9 return os.read_lines(file_path) or { [] }
10 }
11 return read_bytes_from_file(file_path).bytestr().split_into_lines()
12}
13
14// read a file as []u8
15pub fn read_bytes_from_file(file_path string) []u8 {
16 if os.exists(file_path) {
17 return os.read_bytes(file_path) or { [] }
18 }
19 mpath := 'models/${file_path}'
20 return asset.read_bytes('assets', mpath) or {
21 eprintln('Model file NOT FOUND: `${mpath}`')
22 exit(0)
23 }
24}
25