Skip to content

jmbjr/odin_whitebox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

odin_whitebox

example on how to make odin work with whitebox.

Please Note: This process is currently very cumbersome to set up and use and does not take advantage of WhiteBox's actual capability (by a long shot). This is presented as one working example in case you want to inspect the inputs/outputs of some of your Odin procs.

Overview:

Odin Language Home Page
Whitebox

Instructions:

  1. Follow instructions to get/compile Odin and install WhiteBox
    • The Odin and WhiteBox Discord servers are very helpful
    • Specifically, thanks @4984 and @azmr, since you guys did most of the work helping me out!
  2. Install the WhiteBox plugin in your editor of choice
    • I use VS Code
  3. Compile add.odin to .dll by running build.bat
  4. Open whitebox_hack.c in your editor
  5. Start the WhiteBox executable
    • NOTE: WhiteBox MUST be running before trying to connect.
  6. Start the WhiteBox plugin
    • In VS Code, press CTRL + SHIFT + P and select WhiteBox: Connect
  7. In WhiteBox, create a new profile to point to the odin_add.dll
    • Preferences
    • clone
    • Set a name
      • I named mine dll
    • Click the DLL files tab
    • Scroll down and click Add group button
    • In the text box, enter the path to your odin_add.dll
    • click OK to save
      image
  8. Click on a line of source code and Watch The Magic!
    image

How does this work?

Currently, WhiteBox is unable to work with Odin source code. However, after a fun screen-sharing session with Andrew (@azmr, creator of WhiteBox) and @4984, we managed to get WhiteBox to communicate with an Odin .dll.

Refer to the Odin Binding to C docs and the discussion on Implicit context system.

Basically, we create a global context and set it in the main to the actual context. Then inside the proc we want to view in WhiteBox, we can get the global context and ensure the correct symbols are created in the .dll.

package main
import "core:fmt"
import "core:runtime"

g_context : runtime.Context 

main :: proc() {
    g_context = context
    x:=add(1.0,1.0)
    fmt.println("Hello Whitebox!")
    fmt.println(x)
}

@(export) 
@(link_name="odin_add")
add :: proc"system"(a,b :f32) -> f32 {
    context=g_context
    sum : f32 = a + b
    fmt.println("Adding:", a, "plus", b, "=", sum)
    return sum
}

Due to this dependency on main, everything in the main proc is run in WhiteBox. image

A final caveat is that when you recompile your Odin .dll, you will need to completely close out WhiteBox since WhiteBox currently locks the .dll, preventing recompilation. This should be addressed in a future update.

Again, this is more of a "Here's Proof That You Can Run Odin With WhiteBox".

About

example on how to make odin work with whitebox

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published