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.
Odin Language Home Page
Whitebox
- Follow instructions to get/compile Odin and install WhiteBox
- Install the WhiteBox plugin in your editor of choice
- I use VS Code
- Compile
add.odin
to .dll by runningbuild.bat
- Open
whitebox_hack.c
in your editor - Start the WhiteBox executable
- NOTE: WhiteBox MUST be running before trying to connect.
- Start the WhiteBox plugin
- In VS Code, press
CTRL + SHIFT + P
and selectWhiteBox: Connect
- In VS Code, press
- In WhiteBox, create a new profile to point to the
odin_add.dll
- Click on a line of source code and Watch The Magic!
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.
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".