Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize the root of the project in the examples #55

Open
gpetiot opened this issue Nov 28, 2024 · 1 comment
Open

Customize the root of the project in the examples #55

gpetiot opened this issue Nov 28, 2024 · 1 comment

Comments

@gpetiot
Copy link

gpetiot commented Nov 28, 2024

I don't find it convenient to move into the directory of the examples to get them to work, as the paths to the resources are relative to that directory.

So, I propose to add an optional ROOT environment variable to each example, such as:

+let root = Bos.OS.Env.var "ROOT"
+
 let setup () =
   let open Raylib in
   init_window width height "raylib [textures] example - bunnymark";
-  let tex_bunny = load_texture "resources/wabbit_alpha.png" in
+  let tex_bunny =
+    let path =
+      match root with
+      | Some root -> Fmt.str "%s/resources/wabbit_alpha.png" root
+      | None -> "resources/wabbit_alpha.png"
+    in
+    load_texture path
+  in

We can also put this code in some helper library to avoid duplications.

So that we can run them with:

ROOT=examples/textures dune exec -- examples/textures/textures_bunnymark_ocaml_types.exe

What do you think?

@tjammer
Copy link
Owner

tjammer commented Nov 28, 2024

I share your sentiment, but I'm not convinced that typing ROOT=... is much more convenient than cd ....

What about this: When lauching with dune exec, the executables have their Sys.executable_name set to an absolute path. With that, we could get the resoure path like

  let respath res =
    if Filename.is_relative Sys.executable_name then res
    else Filename.(concat (dirname Sys.executable_name) res)
  in

It's not the most robust solution in the world but works for the examples, and saves typing out the directory all-together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants