Skip to content

Commit

Permalink
Updated to use tabs instead of spaces for indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
drmargarido committed Jan 4, 2025
1 parent 8ec5033 commit 2977351
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions json/load_json_unmarshal/load_json_unmarshal.odin
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,36 @@ import "core:os"
import "core:fmt"
import "core:encoding/json"

import "core:mem"

Game_Settings :: struct {
window_width: i32,
window_height: i32,
window_title: string,
rendering_api: string,
renderer_settings: struct{
msaa: bool,
depth_testing: bool,
},
window_width: i32,
window_height: i32,
window_title: string,
rendering_api: string,
renderer_settings: struct{
msaa: bool,
depth_testing: bool,
},
}

main :: proc(){
// Load in your json file!
// Load in your json file!
data, ok := os.read_entire_file_from_filename("game_settings.json")
if !ok {
fmt.eprintln("Failed to load the file!")
return
}
defer delete(data) // Free the memory at the end

// Load data from the json bytes directly to the struct
settings: Game_Settings
unmarshal_err := json.unmarshal(data, &settings)
if unmarshal_err != nil {
fmt.eprintln("Failed to unmarshal the file!")
return
}
fmt.eprintf("Result %v\n", settings)
// Load data from the json bytes directly to the struct
settings: Game_Settings
unmarshal_err := json.unmarshal(data, &settings)
if unmarshal_err != nil {
fmt.eprintln("Failed to unmarshal the file!")
return
}
fmt.eprintf("Result %v\n", settings)

// Clear allocated strings
delete(settings.window_title)
delete(settings.rendering_api)
// Clear allocated strings
delete(settings.window_title)
delete(settings.rendering_api)
}

0 comments on commit 2977351

Please sign in to comment.